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
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,624,184,209
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
n,a,b=map(int,input().split()) if b==0: print(1) else: agv=(n-a)+(n-b) if agv%2==0: print(avg//2) else: avg=avg//2 print(agv+1)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python n,a,b=map(int,input().split()) if b==0: print(1) else: agv=(n-a)+(n-b) if agv%2==0: print(avg//2) else: avg=avg//2 print(agv+1) ```
-1
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,568,036,532
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
218
307,200
n=int(input()) x=[] y=[] co1=int(0) co2=int(0) count=[0,0] for i in range(n): k,l=map(int,input().split()) x.append(k) y.append(l) if(sum(x)%2==0 and sum(y)%2==0): print(0) elif((sum(x)%2==0 and sum(y)%2!=0) or (sum(y)%2==0 and sum(x)%2!=0)): print(-1) else: for i in range(n): if(x[i]%2!=0): temp=x[i] x[i]=y[i] y[i]=temp count[0]+=1 if(sum(x)%2==0 and sum(y)%2==0): break for i in range(n): if(y[i]%2!=0): temp=x[i] x[i]=y[i] y[i]=temp count[1]+=1 if(sum(x)%2==0 and sum(y)%2==0): break print(min(count))
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python n=int(input()) x=[] y=[] co1=int(0) co2=int(0) count=[0,0] for i in range(n): k,l=map(int,input().split()) x.append(k) y.append(l) if(sum(x)%2==0 and sum(y)%2==0): print(0) elif((sum(x)%2==0 and sum(y)%2!=0) or (sum(y)%2==0 and sum(x)%2!=0)): print(-1) else: for i in range(n): if(x[i]%2!=0): temp=x[i] x[i]=y[i] y[i]=temp count[0]+=1 if(sum(x)%2==0 and sum(y)%2==0): break for i in range(n): if(y[i]%2!=0): temp=x[i] x[i]=y[i] y[i]=temp count[1]+=1 if(sum(x)%2==0 and sum(y)%2==0): break print(min(count)) ```
0
1,000
B
Light It Up
PROGRAMMING
1,500
[ "greedy" ]
null
null
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp. The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_{|a|} &lt; M$. All $a_i$ must be integers. Of course, preinstalled program is a good program. The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state. Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$. Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off. Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_n &lt; M$) — initially installed program $a$.
Print the only integer — maximum possible total time when the lamp is lit.
[ "3 10\n4 6 7\n", "2 12\n1 10\n", "2 7\n3 4\n" ]
[ "8\n", "9\n", "6\n" ]
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place. In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$. In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
0
[ { "input": "3 10\n4 6 7", "output": "8" }, { "input": "2 12\n1 10", "output": "9" }, { "input": "2 7\n3 4", "output": "6" }, { "input": "1 2\n1", "output": "1" }, { "input": "5 10\n1 3 5 6 8", "output": "6" }, { "input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031", "output": "999999969" }, { "input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031", "output": "999999969" }, { "input": "1 10\n1", "output": "9" }, { "input": "1 10000000\n1", "output": "9999999" }, { "input": "1 8\n1", "output": "7" }, { "input": "7 17\n1 5 9 10 11 14 16", "output": "9" }, { "input": "4 17\n1 5 9 10", "output": "12" }, { "input": "5 12\n1 2 3 4 5", "output": "9" }, { "input": "2 1000000000\n100 111", "output": "999999989" }, { "input": "3 90591\n90579 90580 90581", "output": "90589" }, { "input": "5 16\n1 2 3 4 5", "output": "13" }, { "input": "6 981231233\n1 6 15 30 130 1875", "output": "981229468" }, { "input": "1 3\n1", "output": "2" }, { "input": "3 12\n4 7 11", "output": "8" }, { "input": "1 100000\n1", "output": "99999" }, { "input": "2 5\n1 3", "output": "3" }, { "input": "1 1000000000\n1", "output": "999999999" }, { "input": "1 1000000000\n999999999", "output": "999999999" }, { "input": "3 4\n1 2 3", "output": "2" }, { "input": "3 5\n1 2 3", "output": "3" }, { "input": "1 4\n2", "output": "3" }, { "input": "3 5\n1 3 4", "output": "3" }, { "input": "9 20\n5 9 11 12 14 15 16 17 19", "output": "12" }, { "input": "2 4\n1 2", "output": "3" }, { "input": "1 10\n2", "output": "9" }, { "input": "2 6\n2 4", "output": "4" }, { "input": "2 4\n1 3", "output": "2" }, { "input": "3 6\n1 2 4", "output": "4" }, { "input": "7 9863\n65 96 97 98 101 112 1115", "output": "9819" } ]
1,635,239,630
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
4,505,600
# -*- coding: utf-8 -*- """ Created on Tue Oct 26 16:54:29 2021 @author: Boush """ n,m = map(int,input().split()) i = list(map(int,input().split())) a = [0];a.extend(i);a.append(m) t = [] for i in range(len(a)-1): t.append(a[i+1]-a[i]) sum_ = 0 for i in range(0,len(t),2): sum_ += t[i] max_ = {sum_} t.insert(0,0) i = 2 while i < len(t): sum_ = -1 for j in range(i,len(t)+1,2): sum_ += t[j] max_.add(sum_) i += 2 print(max(max_))
Title: Light It Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp. The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_{|a|} &lt; M$. All $a_i$ must be integers. Of course, preinstalled program is a good program. The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state. Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$. Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. Input Specification: First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off. Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 &lt; a_1 &lt; a_2 &lt; \dots &lt; a_n &lt; M$) — initially installed program $a$. Output Specification: Print the only integer — maximum possible total time when the lamp is lit. Demo Input: ['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n'] Demo Output: ['8\n', '9\n', '6\n'] Note: In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place. In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$. In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
```python # -*- coding: utf-8 -*- """ Created on Tue Oct 26 16:54:29 2021 @author: Boush """ n,m = map(int,input().split()) i = list(map(int,input().split())) a = [0];a.extend(i);a.append(m) t = [] for i in range(len(a)-1): t.append(a[i+1]-a[i]) sum_ = 0 for i in range(0,len(t),2): sum_ += t[i] max_ = {sum_} t.insert(0,0) i = 2 while i < len(t): sum_ = -1 for j in range(i,len(t)+1,2): sum_ += t[j] max_.add(sum_) i += 2 print(max(max_)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them.
[ "(((#)((#)\n", "()((#((#(#()\n", "#\n", "(#)\n" ]
[ "1\n2\n", "2\n2\n1", "-1\n", "-1\n" ]
|*s*| denotes the length of the string *s*.
0
[ { "input": "(((#)((#)", "output": "1\n2" }, { "input": "()((#((#(#()", "output": "1\n1\n3" }, { "input": "#", "output": "-1" }, { "input": "(#)", "output": "-1" }, { "input": "(((((#(#(#(#()", "output": "1\n1\n1\n5" }, { "input": "#))))", "output": "-1" }, { "input": "((#(()#(##", "output": "1\n1\n1\n1" }, { "input": "##((((((()", "output": "-1" }, { "input": "(((((((((((((((((((###################", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "((#)(", "output": "-1" }, { "input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": ")((##((###", "output": "-1" }, { "input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((", "output": "-1" }, { "input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(", "output": "-1" }, { "input": "((#(", "output": "-1" }, { "input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#", "output": "-1" }, { "input": "(())((((#)", "output": "3" }, { "input": "(#(", "output": "-1" }, { "input": "((#)(", "output": "-1" }, { "input": "(((()#(#)(", "output": "-1" }, { "input": "#((#", "output": "-1" }, { "input": "(#((((()", "output": "-1" }, { "input": "(#((", "output": "-1" }, { "input": ")(((())#", "output": "-1" } ]
1,622,903,593
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
155
307,200
s = input() count = 0 store = 0 first = True ans = False for c in s: if c == "(": count += 1 elif c == ")": if store == 0 or count > 0: count -= 1 else: store -= 1 if count < 0: print(-1) ans = True break else: if not first: print(store) store = count count = 0 first = False if not ans: if store == 0: print(-1) else: print(store)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. Input Specification: The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. Output Specification: If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them. Demo Input: ['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n'] Demo Output: ['1\n2\n', '2\n2\n1', '-1\n', '-1\n'] Note: |*s*| denotes the length of the string *s*.
```python s = input() count = 0 store = 0 first = True ans = False for c in s: if c == "(": count += 1 elif c == ")": if store == 0 or count > 0: count -= 1 else: store -= 1 if count < 0: print(-1) ans = True break else: if not first: print(store) store = count count = 0 first = False if not ans: if store == 0: print(-1) else: print(store) ```
0
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 0" } ]
1,689,933,288
2,147,483,647
Python 3
OK
TESTS
34
46
0
pCount , iCount = list(map(int,input().split())) sadPpl = 0 for _ in range(pCount) : info = input() operator = info[:1] num = int(info[2:]) if operator == "+" : iCount += num else : if iCount >= num: iCount -= num else : sadPpl += 1 print(iCount , sadPpl)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python pCount , iCount = list(map(int,input().split())) sadPpl = 0 for _ in range(pCount) : info = input() operator = info[:1] num = int(info[2:]) if operator == "+" : iCount += num else : if iCount >= num: iCount -= num else : sadPpl += 1 print(iCount , sadPpl) ```
3
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100", "output": "10" }, { "input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9", "output": "4" }, { "input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54", "output": "12" }, { "input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68", "output": "10" }, { "input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30", "output": "8" }, { "input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14", "output": "7" }, { "input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28", "output": "22" }, { "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": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2", "output": "0" }, { "input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2", "output": "68" }, { "input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8", "output": "5" }, { "input": "1\n0 0", "output": "0" }, { "input": "1\n100 100", "output": "0" }, { "input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73", "output": "42" }, { "input": "3\n1 3\n2 7\n8 9", "output": "2" }, { "input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53", "output": "0" }, { "input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54", "output": "0" }, { "input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60", "output": "12" }, { "input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3", "output": "8" } ]
1,694,417,940
2,147,483,647
Python 3
OK
TESTS
27
46
0
n = int(input()) count = 0 while n > 0: p, q = list(map(int, input().split(" "))) if q - p >= 2: count+=1 n-=1 print(count)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. Output Specification: Print a single integer — the number of rooms where George and Alex can move in. Demo Input: ['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n'] Demo Output: ['0\n', '2\n'] Note: none
```python n = int(input()) count = 0 while n > 0: p, q = list(map(int, input().split(" "))) if q - p >= 2: count+=1 n-=1 print(count) ```
3
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200", "output": "YES" }, { "input": "2\n100 200", "output": "NO" }, { "input": "2\n200 100", "output": "NO" }, { "input": "3\n100 100 100", "output": "NO" }, { "input": "3\n200 200 200", "output": "NO" }, { "input": "3\n200 100 200", "output": "NO" }, { "input": "4\n100 100 100 100", "output": "YES" }, { "input": "4\n200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100", "output": "YES" }, { "input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100", "output": "NO" }, { "input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200", "output": "YES" }, { "input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200", "output": "YES" }, { "input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200", "output": "NO" }, { "input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100", "output": "YES" }, { "input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100", "output": "NO" }, { "input": "5\n200 200 200 200 200", "output": "NO" }, { "input": "9\n100 100 100 200 100 100 200 100 200", "output": "YES" }, { "input": "1\n200", "output": "NO" }, { "input": "7\n200 200 200 100 200 200 200", "output": "NO" }, { "input": "4\n100 100 200 200", "output": "YES" }, { "input": "6\n100 100 100 200 200 200", "output": "NO" }, { "input": "4\n200 100 100 200", "output": "YES" }, { "input": "5\n100 100 100 100 200", "output": "YES" } ]
1,697,280,551
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
import sys from os import path if (path.exists('input.txt')): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt','w') n = int(input()) arr = [int(x) for x in input().split()] c1 = c2 = 0 for i in arr: if i==100: c1+= 1 else: c2+= 2 print('YES' if abs(c1-c2)%2==0 else 'NO')
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. Output Specification: In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). Demo Input: ['3\n100 200 100\n', '4\n100 100 100 200\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
```python import sys from os import path if (path.exists('input.txt')): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt','w') n = int(input()) arr = [int(x) for x in input().split()] c1 = c2 = 0 for i in arr: if i==100: c1+= 1 else: c2+= 2 print('YES' if abs(c1-c2)%2==0 else 'NO') ```
0
350
C
Bombs
PROGRAMMING
1,600
[ "greedy", "implementation", "sortings" ]
null
null
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point with coordinates (0,<=0). Also, let's mark the robot's current position as (*x*,<=*y*). In order to destroy all the bombs, the robot can perform three types of operations: 1. Operation has format "1 k dir". To perform the operation robot have to move in direction *dir* *k* (*k*<=≥<=1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1), (*x*,<=*y*<=-<=1) (corresponding to directions). It is forbidden to move from point (*x*,<=*y*), if at least one point on the path (besides the destination point) contains a bomb. 1. Operation has format "2". To perform the operation robot have to pick a bomb at point (*x*,<=*y*) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (*x*,<=*y*) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container. 1. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0,<=0). It is forbidden to perform the operation if the container has no bomb. Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of bombs on the coordinate plane. Next *n* lines contain two integers each. The *i*-th line contains numbers (*x**i*,<=*y**i*) (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0,<=0).
In a single line print a single integer *k* — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these *k* operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where *k*<=≤<=106.
[ "2\n1 1\n-1 -1\n", "3\n5 0\n0 5\n1 0\n" ]
[ "12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n", "12\n1 1 R\n2\n1 1 L\n3\n1 5 R\n2\n1 5 L\n3\n1 5 U\n2\n1 5 D\n3\n" ]
none
1,000
[ { "input": "2\n1 1\n-1 -1", "output": "12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3" }, { "input": "3\n5 0\n0 5\n1 0", "output": "12\n1 1 R\n2\n1 1 L\n3\n1 5 R\n2\n1 5 L\n3\n1 5 U\n2\n1 5 D\n3" }, { "input": "1\n-277226476 314722425", "output": "6\n1 277226476 L\n1 314722425 U\n2\n1 277226476 R\n1 314722425 D\n3" }, { "input": "2\n-404192496 -968658337\n556071553 -256244640", "output": "12\n1 556071553 R\n1 256244640 D\n2\n1 556071553 L\n1 256244640 U\n3\n1 404192496 L\n1 968658337 D\n2\n1 404192496 R\n1 968658337 U\n3" }, { "input": "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2", "output": "128\n1 1 U\n2\n1 1 D\n3\n1 1 R\n2\n1 1 L\n3\n1 1 L\n2\n1 1 R\n3\n1 1 D\n2\n1 1 U\n3\n1 1 L\n1 1 U\n2\n1 1 R\n1 1 D\n3\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 2 U\n2\n1 2 D\n3\n1 1 R\n1 1 D\n2\n1 1 L\n1 1 U\n3\n1 2 D\n2\n1 2 U\n3\n1 2 L\n2\n1 2 R\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n1 2 R\n2\n1 2 L\n3\n1 2 L\n1 1 D\n2\n1 2 R\n1 1 U\n3\n1 2 R\n1 1 U\n2\n1 2 L\n1 1 D\n3\n1 1 R\n1 2 U\n2\n1 1 L\n1 2 D\n3\n1 1 L\n1 2 U\n2\n1 1 R\n1 2 D\n3\n1 2 L\n1 1 U\n2\n1 2 R\n1 1 D\n3\n1 1 L\n1 2 D\n2\n1 1 R\n1 2 U\n3\n1 2 R\n..." } ]
1,545,551,050
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
218
0
n = int(input()) s =[] for i in range(n): l = list(map(int, input().split())) s.append(l) s.sort() num = 0 op = [] for i in range(n): x = s[i][0] y = s[i][1] if y == 0: num += 4 l1 = [str(1), str(x), 'R'] l2 = ['2'] l3 = [str(1), str(x), 'L'] l4 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) elif x == 0: num += 4 l1 = [str(1), str(y), 'U'] l2 = ['2'] l3 = [str(1), str(y), 'D'] l4 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) else: num += 6 l1 = [str(1), str(x), 'R'] l2 = [str(1), str(y), 'U'] l3 = ['2'] l4 = [str(1), str(y), 'D'] l5 = [str(1), str(x), 'L'] l6 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) op.append(l5) op.append(l6) print(num) for i in range(len(op)): print(' '.join(op[i]))
Title: Bombs Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point with coordinates (0,<=0). Also, let's mark the robot's current position as (*x*,<=*y*). In order to destroy all the bombs, the robot can perform three types of operations: 1. Operation has format "1 k dir". To perform the operation robot have to move in direction *dir* *k* (*k*<=≥<=1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1), (*x*,<=*y*<=-<=1) (corresponding to directions). It is forbidden to move from point (*x*,<=*y*), if at least one point on the path (besides the destination point) contains a bomb. 1. Operation has format "2". To perform the operation robot have to pick a bomb at point (*x*,<=*y*) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (*x*,<=*y*) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container. 1. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0,<=0). It is forbidden to perform the operation if the container has no bomb. Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of bombs on the coordinate plane. Next *n* lines contain two integers each. The *i*-th line contains numbers (*x**i*,<=*y**i*) (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0,<=0). Output Specification: In a single line print a single integer *k* — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these *k* operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where *k*<=≤<=106. Demo Input: ['2\n1 1\n-1 -1\n', '3\n5 0\n0 5\n1 0\n'] Demo Output: ['12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n', '12\n1 1 R\n2\n1 1 L\n3\n1 5 R\n2\n1 5 L\n3\n1 5 U\n2\n1 5 D\n3\n'] Note: none
```python n = int(input()) s =[] for i in range(n): l = list(map(int, input().split())) s.append(l) s.sort() num = 0 op = [] for i in range(n): x = s[i][0] y = s[i][1] if y == 0: num += 4 l1 = [str(1), str(x), 'R'] l2 = ['2'] l3 = [str(1), str(x), 'L'] l4 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) elif x == 0: num += 4 l1 = [str(1), str(y), 'U'] l2 = ['2'] l3 = [str(1), str(y), 'D'] l4 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) else: num += 6 l1 = [str(1), str(x), 'R'] l2 = [str(1), str(y), 'U'] l3 = ['2'] l4 = [str(1), str(y), 'D'] l5 = [str(1), str(x), 'L'] l6 = ['3'] op.append(l1) op.append(l2) op.append(l3) op.append(l4) op.append(l5) op.append(l6) print(num) for i in range(len(op)): print(' '.join(op[i])) ```
0
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,595,503,828
2,147,483,647
Python 3
OK
TESTS
32
109
6,656,000
s,v1,v2,t1,t2=list(map(int,input().split())) first=v1*s+2*t1 second=v2*s+2*t2 if first<second: print('First') elif first>second: print('Second') else: print('Friendship')
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s,v1,v2,t1,t2=list(map(int,input().split())) first=v1*s+2*t1 second=v2*s+2*t2 if first<second: print('First') elif first>second: print('Second') else: print('Friendship') ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,698,279,235
2,147,483,647
Python 3
OK
TESTS
15
46
0
k,n,w = map(int, input().split()) cost = 0 for i in range(1, w+1): cost += i*k if cost <= n: print(0) else: print(cost - n)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k,n,w = map(int, input().split()) cost = 0 for i in range(1, w+1): cost += i*k if cost <= n: print(0) else: print(cost - n) ```
3
762
B
USB vs. PS/2
PROGRAMMING
1,400
[ "greedy", "implementation", "sortings", "two pointers" ]
null
null
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.
The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105)  — the number of mouses in the price list. The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109)  — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
[ "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n" ]
[ "3 14\n" ]
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
0
[ { "input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2", "output": "3 14" }, { "input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB", "output": "8 2345344274" }, { "input": "3 0 3\n0", "output": "0 0" }, { "input": "1 2 4\n12\n257866589 PS/2\n246883568 USB\n104396128 USB\n993389754 PS/2\n896419206 USB\n405836977 USB\n50415634 PS/2\n152940828 PS/2\n847270779 PS/2\n850467106 USB\n922287488 USB\n622484596 PS/2", "output": "7 1840824320" }, { "input": "0 4 2\n12\n170189291 USB\n670118538 USB\n690872205 PS/2\n582606841 PS/2\n397508479 USB\n578814041 USB\n96734643 USB\n168371453 USB\n528445088 PS/2\n506017602 PS/2\n512143072 USB\n188740735 USB", "output": "6 2573047832" }, { "input": "5 100 100\n29\n741703337 USB\n285817204 PS/2\n837154300 USB\n250820430 USB\n809146898 PS/2\n10478072 USB\n2833804 PS/2\n669657009 USB\n427708130 PS/2\n204319444 PS/2\n209882040 USB\n56937335 USB\n107442187 USB\n46188465 USB\n902978472 USB\n792812238 PS/2\n513787720 PS/2\n486353330 PS/2\n168930159 PS/2\n183624803 USB\n67302934 USB\n264291554 USB\n467936329 USB\n82111533 USB\n849018301 USB\n645374374 PS/2\n967926381 PS/2\n286289663 PS/2\n36760263 USB", "output": "29 11375586709" }, { "input": "71 15 60\n24\n892757877 USB\n613048358 USB\n108150254 USB\n425313488 USB\n949441992 USB\n859461207 PS/2\n81440099 PS/2\n348819522 USB\n606267503 USB\n443620287 PS/2\n610038583 USB\n374259313 PS/2\n947207567 PS/2\n424889764 PS/2\n58345333 USB\n735796912 PS/2\n523115052 USB\n983709864 USB\n426463338 USB\n305759345 PS/2\n689127461 PS/2\n878781173 PS/2\n445036480 USB\n643765304 USB", "output": "24 13374616076" }, { "input": "37 80 100\n31\n901706521 USB\n555265160 PS/2\n547038505 PS/2\n644436873 PS/2\n105558073 USB\n915082057 PS/2\n913113815 USB\n953413471 PS/2\n252912707 PS/2\n830344497 USB\n781593007 USB\n610659875 PS/2\n177755858 PS/2\n496444729 PS/2\n617569418 USB\n304908147 PS/2\n188649950 PS/2\n705737216 USB\n473915286 USB\n622994426 PS/2\n783873493 USB\n789927108 USB\n258311181 PS/2\n720083354 PS/2\n676406125 PS/2\n634885851 PS/2\n126814339 USB\n704693540 USB\n789707618 PS/2\n938873907 USB\n576166502 USB", "output": "31 18598842609" }, { "input": "6 100 10\n11\n931138340 USB\n421397130 USB\n899599243 PS/2\n891033726 PS/2\n375251114 PS/2\n991976657 USB\n743116261 PS/2\n163085281 PS/2\n111524953 PS/2\n148832199 PS/2\n480084927 PS/2", "output": "11 6157039831" }, { "input": "1 1 124\n1\n2 USB", "output": "1 2" }, { "input": "1 1 1\n3\n3 USB\n3 PS/2\n3 PS/2", "output": "3 9" }, { "input": "3 3 3\n6\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB", "output": "6 18" }, { "input": "1 1 1\n0", "output": "0 0" }, { "input": "1 1 1\n4\n9 USB\n1 PS/2\n5 USB\n6 PS/2", "output": "3 12" }, { "input": "1 1 1\n1\n6 PS/2", "output": "1 6" }, { "input": "1 3 1\n5\n1 PS/2\n8 USB\n8 PS/2\n8 PS/2\n1 PS/2", "output": "5 26" }, { "input": "3 2 1\n6\n1 USB\n4 PS/2\n4 PS/2\n7 USB\n8 PS/2\n1 USB", "output": "6 25" }, { "input": "1 1 1\n3\n10 USB\n6 USB\n6 USB", "output": "2 12" }, { "input": "1 1 1\n3\n4 USB\n3 PS/2\n3 USB", "output": "3 10" }, { "input": "1 1 1\n2\n6 PS/2\n5 USB", "output": "2 11" }, { "input": "1 1 2\n5\n4 USB\n7 PS/2\n10 PS/2\n7 PS/2\n3 USB", "output": "4 21" }, { "input": "1 4 4\n8\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n474310330 USB", "output": "7 1621841331" }, { "input": "1 4 4\n9\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB", "output": "8 2538599717" }, { "input": "1 4 4\n10\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB", "output": "8 2414801876" }, { "input": "48810 78876 100000\n0", "output": "0 0" }, { "input": "1 0 0\n1\n862644246 PS/2", "output": "0 0" }, { "input": "2 6 0\n3\n380521935 USB\n261865233 USB\n744434239 USB", "output": "2 642387168" }, { "input": "0 0 0\n1\n1 USB", "output": "0 0" }, { "input": "0 0 0\n1\n2 USB", "output": "0 0" }, { "input": "1 1 1\n1\n5 USB", "output": "1 5" }, { "input": "1 1 1\n2\n2 USB\n5 USB", "output": "2 7" }, { "input": "1 1 1\n2\n3 PS/2\n6 PS/2", "output": "2 9" }, { "input": "2 1 1\n4\n5 USB\n5 PS/2\n3 PS/2\n7 PS/2", "output": "3 13" } ]
1,666,539,436
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,867,200
t=1 while t>0: t-=1 a,b,c=(int(_) for _ in input().strip().split(' ')) n=int(input()) u=[] p=[] cnt1=0 cnt2=0 for i in range(n): x=int(input().split(' ')) s=input() if s=="USB": u.append(x) cnt1+=1 if s=="PS/2": p.append(x) cnt2+=1 u.sort() p.sort() ans=min(a,cnt1)+min(b,cnt2)+min(c,max(cnt1-a,0)+max(cnt2-b,0)) val=0 for i in range(min(a,cnt1)): val+=u[i] for i in range(min(b,cnt2)): val+=p[i] pos1=min(a,cnt1) pos2=min(b,cnt2) while c!=0: if cnt1-a>0 and cnt2-b>0: if u[pos1]<=p[pos2]: val+=u[pos1] pos1+=1 else: val+=p[pos2] pos2+=1 else: if cnt1-a>0: val+=u[pos1] pos1+=1 if cnt2-b>0: val+=p[pos2] pos2+=1 if cnt1-a<=0 and cnt2-b<=0: break print(ans,end=' ') print(val)
Title: USB vs. PS/2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input Specification: The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105)  — the number of mouses in the price list. The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109)  — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Specification: Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy. Demo Input: ['2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n'] Demo Output: ['3 14\n'] Note: In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
```python t=1 while t>0: t-=1 a,b,c=(int(_) for _ in input().strip().split(' ')) n=int(input()) u=[] p=[] cnt1=0 cnt2=0 for i in range(n): x=int(input().split(' ')) s=input() if s=="USB": u.append(x) cnt1+=1 if s=="PS/2": p.append(x) cnt2+=1 u.sort() p.sort() ans=min(a,cnt1)+min(b,cnt2)+min(c,max(cnt1-a,0)+max(cnt2-b,0)) val=0 for i in range(min(a,cnt1)): val+=u[i] for i in range(min(b,cnt2)): val+=p[i] pos1=min(a,cnt1) pos2=min(b,cnt2) while c!=0: if cnt1-a>0 and cnt2-b>0: if u[pos1]<=p[pos2]: val+=u[pos1] pos1+=1 else: val+=p[pos2] pos2+=1 else: if cnt1-a>0: val+=u[pos1] pos1+=1 if cnt2-b>0: val+=p[pos2] pos2+=1 if cnt1-a<=0 and cnt2-b<=0: break print(ans,end=' ') print(val) ```
-1
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,637,603,525
2,147,483,647
PyPy 3
OK
TESTS
30
156
0
s = input() uc = lc = 0 for c in s: if c.islower(): lc+=1 else: uc+=1 if lc>=uc: print(s.lower()) else: print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s = input() uc = lc = 0 for c in s: if c.islower(): lc+=1 else: uc+=1 if lc>=uc: print(s.lower()) else: print(s.upper()) ```
3.961
394
A
Counting Sticks
PROGRAMMING
0
[ "brute force", "implementation" ]
null
null
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type: Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*. We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =. We really aren't fabulous at arithmetics. Can you help us?
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
[ "||+|=|||||\n", "|||||+||=||\n", "|+|=||||||\n", "||||+||=||||||\n" ]
[ "|||+|=||||\n", "Impossible\n", "Impossible\n", "||||+||=||||||\n" ]
In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
500
[ { "input": "||+|=|||||", "output": "|||+|=||||" }, { "input": "|||||+||=||", "output": "Impossible" }, { "input": "|+|=||||||", "output": "Impossible" }, { "input": "||||+||=||||||", "output": "||||+||=||||||" }, { "input": "||||||||||||+|||||||||||=||||||||||||||||||||||", "output": "Impossible" }, { "input": "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "|+|=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+|=|", "output": "|+|=||" }, { "input": "|+||=|", "output": "|+|=||" }, { "input": "|+|=||", "output": "|+|=||" }, { "input": "|||+|=|", "output": "Impossible" }, { "input": "|||+|=|", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|+|=|||", "output": "Impossible" }, { "input": "|+|=||||", "output": "||+|=|||" }, { "input": "|+||=|", "output": "|+|=||" }, { "input": "|+||||||=|||||", "output": "|+|||||=||||||" }, { "input": "|+|||=||", "output": "|+||=|||" }, { "input": "|+||||=|||", "output": "|+|||=||||" }, { "input": "|+|||||=||||", "output": "|+||||=|||||" }, { "input": "||+||=||", "output": "|+||=|||" }, { "input": "||+|||=|||", "output": "|+|||=||||" }, { "input": "|||||+||=||||||||||", "output": "Impossible" }, { "input": "|||+|||=||||", "output": "||+|||=|||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "|||||+|||||=||||||||||||", "output": "||||||+|||||=|||||||||||" }, { "input": "||+|||||||=|||||||", "output": "|+|||||||=||||||||" }, { "input": "||||+||||=||||||", "output": "|||+||||=|||||||" }, { "input": "||||+|||=|||||", "output": "|||+|||=||||||" }, { "input": "||+|||=|||||||", "output": "|||+|||=||||||" }, { "input": "||+|=|", "output": "|+|=||" }, { "input": "|||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+|=||||||", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" } ]
1,577,904,272
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
109
307,200
n = input() a, b, c, d = 0, 0, 0, 1 for i in n: if i == '+': d = 2 elif i == '=': d = 3 elif d == 1: a += 1 elif d == 2: b += 1 else: c += 1 if a + b == c: print(n) elif abs(c - ((a + b + c) // 2)) == 1: print('|' * a + '+' + '|' * (b + (c - ((a + b + c) // 2))) + '=' + '|' * (c - (c - ((a + b + c) // 2)))) else: print('Impossible')
Title: Counting Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type: Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*. We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =. We really aren't fabulous at arithmetics. Can you help us? Input Specification: The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. Output Specification: If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples. Demo Input: ['||+|=|||||\n', '|||||+||=||\n', '|+|=||||||\n', '||||+||=||||||\n'] Demo Output: ['|||+|=||||\n', 'Impossible\n', 'Impossible\n', '||||+||=||||||\n'] Note: In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
```python n = input() a, b, c, d = 0, 0, 0, 1 for i in n: if i == '+': d = 2 elif i == '=': d = 3 elif d == 1: a += 1 elif d == 2: b += 1 else: c += 1 if a + b == c: print(n) elif abs(c - ((a + b + c) // 2)) == 1: print('|' * a + '+' + '|' * (b + (c - ((a + b + c) // 2))) + '=' + '|' * (c - (c - ((a + b + c) // 2)))) else: print('Impossible') ```
0
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong.
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 4", "output": "YES" }, { "input": "43 5", "output": "YES" }, { "input": "47 7", "output": "NO" }, { "input": "50 5", "output": "YES" }, { "input": "57 6", "output": "YES" }, { "input": "60 8", "output": "NO" }, { "input": "62 7", "output": "YES" }, { "input": "76 9", "output": "NO" }, { "input": "69 7", "output": "YES" }, { "input": "113 10", "output": "YES" }, { "input": "141 11", "output": "YES" }, { "input": "207 16", "output": "NO" }, { "input": "231 18", "output": "NO" }, { "input": "296 19", "output": "YES" }, { "input": "332 20", "output": "YES" }, { "input": "378 24", "output": "NO" }, { "input": "428 23", "output": "YES" }, { "input": "497 27", "output": "NO" }, { "input": "640 32", "output": "YES" }, { "input": "798 35", "output": "YES" }, { "input": "802 35", "output": "YES" }, { "input": "864 40", "output": "NO" }, { "input": "953 44", "output": "NO" }, { "input": "995 44", "output": "YES" }, { "input": "1000 44", "output": "YES" }, { "input": "1000 0", "output": "YES" }, { "input": "1000 1000", "output": "NO" }, { "input": "2 1000", "output": "NO" }, { "input": "2 0", "output": "YES" } ]
1,695,814,201
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
5,632,000
# Hydro submission #6514123610f69f159c4e63ec@1695814198877 print('YES')
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong. Input Specification: The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). Output Specification: Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. Demo Input: ['27 2\n', '45 7\n'] Demo Output: ['YES', 'NO'] Note: In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
```python # Hydro submission #6514123610f69f159c4e63ec@1695814198877 print('YES') ```
0
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "output": "16" }, { "input": "10\n2 3 0 1 3 1 2 2 1 0", "output": "3" }, { "input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 3", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n3 3", "output": "0" }, { "input": "3\n3 3 3", "output": "0" }, { "input": "2\n3 2", "output": "0" }, { "input": "2\n0 2", "output": "1" }, { "input": "10\n2 2 3 3 3 3 2 1 3 2", "output": "2" }, { "input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0", "output": "11" }, { "input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1", "output": "4" }, { "input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2", "output": "3" }, { "input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0", "output": "12" }, { "input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3", "output": "5" }, { "input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2", "output": "4" }, { "input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1", "output": "16" }, { "input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3", "output": "5" }, { "input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3", "output": "3" }, { "input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0", "output": "22" }, { "input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2", "output": "9" }, { "input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3", "output": "2" }, { "input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0", "output": "21" }, { "input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2", "output": "11" }, { "input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2", "output": "7" }, { "input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0", "output": "28" }, { "input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1", "output": "10" }, { "input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3", "output": "8" }, { "input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2", "output": "29" }, { "input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3", "output": "8" }, { "input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0", "output": "32" }, { "input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2", "output": "16" }, { "input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3", "output": "7" }, { "input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0", "output": "40" }, { "input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2", "output": "13" }, { "input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3", "output": "7" }, { "input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0", "output": "44" }, { "input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2", "output": "15" }, { "input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3", "output": "8" }, { "input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1", "output": "35" }, { "input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3", "output": "13" }, { "input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3", "output": "6" }, { "input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1", "output": "43" }, { "input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1", "output": "16" }, { "input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1", "output": "10" }, { "input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0", "output": "51" }, { "input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1", "output": "16" }, { "input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1", "output": "11" }, { "input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1", "output": "56" }, { "input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0", "output": "17" }, { "input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3", "output": "9" }, { "input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0", "output": "54" }, { "input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3", "output": "19" }, { "input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3", "output": "9" }, { "input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1", "output": "57" }, { "input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1", "output": "17" }, { "input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2", "output": "9" }, { "input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1", "output": "61" }, { "input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2", "output": "15" }, { "input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2", "output": "14" }, { "input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2", "output": "63" }, { "input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3", "output": "15" }, { "input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2", "output": "0" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "50" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "49" }, { "input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "2\n0 3", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 0", "output": "1" }, { "input": "2\n2 1", "output": "0" }, { "input": "2\n2 3", "output": "0" }, { "input": "2\n3 0", "output": "1" }, { "input": "2\n3 1", "output": "0" }, { "input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0", "output": "50" } ]
1,545,846,881
2,147,483,647
Python 3
OK
TESTS
88
124
0
n = int(input()) act = [int(i) for i in input().split()] rest = 0 curr = 0 for e in act: if e == 0: rest += 1 curr = 0 elif e == 1: if curr == 0 or curr == 1: curr = -1 else: rest += 1 curr = 0 elif e == 2: if curr == 0 or curr == -1: curr = 1 else: rest += 1 curr = 0 else: if curr == 0: continue else: curr *= -1 print(rest)
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python n = int(input()) act = [int(i) for i in input().split()] rest = 0 curr = 0 for e in act: if e == 0: rest += 1 curr = 0 elif e == 1: if curr == 0 or curr == 1: curr = -1 else: rest += 1 curr = 0 elif e == 2: if curr == 0 or curr == -1: curr = 1 else: rest += 1 curr = 0 else: if curr == 0: continue else: curr *= -1 print(rest) ```
3
18
D
Seller Bob
PROGRAMMING
2,000
[ "brute force", "dp", "greedy" ]
D. Seller Bob
2
128
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally.
The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000).
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
[ "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n", "3\nwin 5\nsell 6\nsell 4\n" ]
[ "1056\n", "0\n" ]
none
0
[ { "input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056" }, { "input": "3\nwin 5\nsell 6\nsell 4", "output": "0" }, { "input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1", "output": "2147483646" }, { "input": "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819", "output": "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054..." }, { "input": "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304", "output": "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648" }, { "input": "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257", "output": "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273..." }, { "input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165", "output": "0" }, { "input": "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312", "output": "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933..." }, { "input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838", "output": "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779..." }, { "input": "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157", "output": "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144" }, { "input": "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549", "output": "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096" }, { "input": "1\nsell 2000", "output": "0" }, { "input": "1\nwin 2000", "output": "0" }, { "input": "2\nwin 2000\nsell 2000", "output": "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..." } ]
1,672,741,179
2,147,483,647
PyPy 3-64
OK
TESTS
45
342
8,806,400
# Saw Answer n = int(input()) sell = dict() win = dict() c = [] for i in range(n): s, v = input().split() v = int(v) + 1 c.append(v) if s[0] == "s": c[i] *= -1 sell[v] = i else: if v not in win: win[v] = list() win[v].append(i) ans = 0 for i in sorted(sell.keys(), reverse=True): if i not in win: continue while len(win[i]) and win[i][-1] > sell[i]: win[i].pop() if len(win[i]): if all(c[j] for j in range(win[i][-1], sell[i] + 1)): for j in range(win[i][-1], sell[i] + 1): c[j] = 0 ans += 2 ** (i - 1) print(ans)
Title: Seller Bob Time Limit: 2 seconds Memory Limit: 128 megabytes Problem Description: Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input Specification: The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). Output Specification: Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Demo Input: ['7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n', '3\nwin 5\nsell 6\nsell 4\n'] Demo Output: ['1056\n', '0\n'] Note: none
```python # Saw Answer n = int(input()) sell = dict() win = dict() c = [] for i in range(n): s, v = input().split() v = int(v) + 1 c.append(v) if s[0] == "s": c[i] *= -1 sell[v] = i else: if v not in win: win[v] = list() win[v].append(i) ans = 0 for i in sorted(sell.keys(), reverse=True): if i not in win: continue while len(win[i]) and win[i][-1] > sell[i]: win[i].pop() if len(win[i]): if all(c[j] for j in range(win[i][-1], sell[i] + 1)): for j in range(win[i][-1], sell[i] + 1): c[j] = 0 ans += 2 ** (i - 1) print(ans) ```
3.881694
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input": "17 100 100 1", "output": "1" }, { "input": "17 2 3 100", "output": "5" }, { "input": "18 1 3 3", "output": "2" }, { "input": "19 1 1 1", "output": "1" }, { "input": "999999997 999999990 1000000000 1000000000", "output": "1000000000" }, { "input": "999999998 1000000000 999999990 1000000000", "output": "999999990" }, { "input": "634074578 336470888 481199252 167959139", "output": "335918278" }, { "input": "999999999 1000000000 1000000000 999999990", "output": "1000000000" }, { "input": "804928248 75475634 54748096 641009859", "output": "0" }, { "input": "535590429 374288891 923264237 524125987", "output": "524125987" }, { "input": "561219907 673102149 496813081 702209411", "output": "673102149" }, { "input": "291882089 412106895 365329221 585325539", "output": "585325539" }, { "input": "757703054 5887448 643910770 58376259", "output": "11774896" }, { "input": "783332532 449924898 72235422 941492387", "output": "0" }, { "input": "513994713 43705451 940751563 824608515", "output": "131116353" }, { "input": "539624191 782710197 514300407 2691939", "output": "8075817" }, { "input": "983359971 640274071 598196518 802030518", "output": "640274071" }, { "input": "8989449 379278816 26521171 685146646", "output": "405799987" }, { "input": "34618927 678092074 895037311 863230070", "output": "678092074" }, { "input": "205472596 417096820 468586155 41313494", "output": "0" }, { "input": "19 5 1 2", "output": "3" }, { "input": "17 1 2 2", "output": "2" }, { "input": "18 3 3 1", "output": "2" }, { "input": "19 4 3 1", "output": "3" }, { "input": "936134778 715910077 747167704 219396918", "output": "438793836" }, { "input": "961764255 454914823 615683844 102513046", "output": "307539138" }, { "input": "692426437 48695377 189232688 985629174", "output": "146086131" }, { "input": "863280107 347508634 912524637 458679894", "output": "347508634" }, { "input": "593942288 86513380 486073481 341796022", "output": "0" }, { "input": "914539062 680293934 764655030 519879446", "output": "764655030" }, { "input": "552472140 509061481 586588704 452405440", "output": "0" }, { "input": "723325809 807874739 160137548 335521569", "output": "335521569" }, { "input": "748955287 546879484 733686393 808572289", "output": "546879484" }, { "input": "774584765 845692742 162011045 691688417", "output": "691688417" }, { "input": "505246946 439473295 30527185 869771841", "output": "30527185" }, { "input": "676100616 178478041 604076030 752887969", "output": "0" }, { "input": "701730093 477291299 177624874 930971393", "output": "654916173" }, { "input": "432392275 216296044 751173719 109054817", "output": "216296044" }, { "input": "458021753 810076598 324722563 992170945", "output": "992170945" }, { "input": "188683934 254114048 48014511 170254369", "output": "48014511" }, { "input": "561775796 937657403 280013594 248004555", "output": "0" }, { "input": "1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 10000 10000 3", "output": "9" }, { "input": "3 12 3 4", "output": "7" }, { "input": "3 10000 10000 1", "output": "3" }, { "input": "3 1000 1000 1", "output": "3" }, { "input": "3 10 10 1", "output": "3" }, { "input": "3 100 100 1", "output": "3" }, { "input": "3 100000 10000 1", "output": "3" }, { "input": "7 10 2 3", "output": "5" }, { "input": "3 1000 1000 2", "output": "6" }, { "input": "1 100000 1 100000", "output": "100000" }, { "input": "7 4 3 1", "output": "3" }, { "input": "3 1000 1000 3", "output": "9" }, { "input": "3 1000 1 1", "output": "2" }, { "input": "3 10 1 1", "output": "2" }, { "input": "3 100000 1 1", "output": "2" }, { "input": "3 100 1 1", "output": "2" }, { "input": "3 100000 100000 1", "output": "3" }, { "input": "3 1000 1 100", "output": "101" }, { "input": "3 1000000000 1 1000000000", "output": "1000000000" }, { "input": "3 1000 1 10", "output": "11" }, { "input": "3 200 1 100", "output": "101" }, { "input": "7 4 1 1", "output": "2" }, { "input": "7 4 12 1", "output": "3" }, { "input": "3 9 1 1", "output": "2" }, { "input": "3 10000000 1000000 1", "output": "3" }, { "input": "7 1000 1000 1", "output": "3" }, { "input": "3 10000 1 30", "output": "31" }, { "input": "3 1000 1 2", "output": "3" }, { "input": "7 12 6 1", "output": "3" }, { "input": "3 100000 1 1000", "output": "1001" }, { "input": "7 1000 1000 3", "output": "9" }, { "input": "3 4 3 1", "output": "3" }, { "input": "3 3000000 1 100000", "output": "100001" }, { "input": "3 3 1 1", "output": "2" }, { "input": "3 10 1 5", "output": "6" }, { "input": "3 2000 2000 1", "output": "3" }, { "input": "3 10000000 10000000 1", "output": "3" }, { "input": "3 5 1 1", "output": "2" }, { "input": "3 100 1 33", "output": "34" }, { "input": "7 9 2 7", "output": "9" }, { "input": "4448 2 3 6", "output": "0" }, { "input": "2228 1 6 3", "output": "0" } ]
1,584,542,535
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
124
307,200
#I: n, a, b, c = map(int, input().split()) mod = n % 4 if n < 4: mod = n elif n == 4: mod = 0 ans = [] if mod == 3: ans.append(a) ans.append(3*c) ans.append(3*b + c) print(min(ans)) elif mod == 2: ans.append(b) ans.append(2*a) ans.append(2*c) ans.append(c + 3*a) print(min(ans)) elif mod == 1: ans.append(c) ans.append(3*a) ans.append(b + a) print(min(ans)) else: print(0)
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input Specification: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Output Specification: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Demo Input: ['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n'] Demo Output: ['3\n', '1\n', '0\n', '1000000000\n'] Note: In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
```python #I: n, a, b, c = map(int, input().split()) mod = n % 4 if n < 4: mod = n elif n == 4: mod = 0 ans = [] if mod == 3: ans.append(a) ans.append(3*c) ans.append(3*b + c) print(min(ans)) elif mod == 2: ans.append(b) ans.append(2*a) ans.append(2*c) ans.append(c + 3*a) print(min(ans)) elif mod == 1: ans.append(c) ans.append(3*a) ans.append(b + a) print(min(ans)) else: print(0) ```
0
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,700,218,288
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
s INF = 10**20 MOD = 10**9 + 7 from math import gcd from math import ceil, log2, factorial from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() I = lambda:list(map(int,input().split())) TESTS = 0 """ Facts and Data representation Constructive? Top bottom up down """ def solve(): n, = I() a = I() a = [[a[i], i] for i in range(n)] a.sort(reverse=True) ans = [0] * n ans[a[0][1]] = 1 cnt = 0 for i in range(1, n): if (a[i][0] == a[i - 1][0]): ans[a[i][1]] = ans[a[i - 1][1]] cnt += 1 else: ans[a[i][1]] = ans[a[i - 1][1]] + cnt + 1 cnt = 0 print(*ans) def main(): if not TESTS: solve() return t, = I() while t: solve() t -= 1 if __name__ == "__main__": main()
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python s INF = 10**20 MOD = 10**9 + 7 from math import gcd from math import ceil, log2, factorial from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() I = lambda:list(map(int,input().split())) TESTS = 0 """ Facts and Data representation Constructive? Top bottom up down """ def solve(): n, = I() a = I() a = [[a[i], i] for i in range(n)] a.sort(reverse=True) ans = [0] * n ans[a[0][1]] = 1 cnt = 0 for i in range(1, n): if (a[i][0] == a[i - 1][0]): ans[a[i][1]] = ans[a[i - 1][1]] cnt += 1 else: ans[a[i][1]] = ans[a[i - 1][1]] + cnt + 1 cnt = 0 print(*ans) def main(): if not TESTS: solve() return t, = I() while t: solve() t -= 1 if __name__ == "__main__": main() ```
-1
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
1,695,980,195
2,147,483,647
PyPy 3-64
OK
TESTS
37
124
0
n = int(input()) numbers = list(map(int, input().split())) best = worst = numbers[0] amazing = 0 for current in numbers[1:]: if current < worst: worst = current amazing += 1 if current > best: best = current amazing += 1 print(amazing)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python n = int(input()) numbers = list(map(int, input().split())) best = worst = numbers[0] amazing = 0 for current in numbers[1:]: if current < worst: worst = current amazing += 1 if current > best: best = current amazing += 1 print(amazing) ```
3
142
A
Help Farmer
PROGRAMMING
1,600
[ "brute force", "math" ]
null
null
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks. At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*. Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks.
The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109).
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
[ "4\n", "7\n", "12\n" ]
[ "28 41\n", "47 65\n", "48 105\n" ]
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks.
500
[ { "input": "4", "output": "28 41" }, { "input": "7", "output": "47 65" }, { "input": "12", "output": "48 105" }, { "input": "1", "output": "17 17" }, { "input": "6", "output": "34 57" }, { "input": "8", "output": "40 73" }, { "input": "9", "output": "41 81" }, { "input": "14", "output": "58 121" }, { "input": "15", "output": "55 129" }, { "input": "16", "output": "56 137" }, { "input": "18", "output": "57 153" }, { "input": "20", "output": "64 169" }, { "input": "299999771", "output": "1499998867 2399998177" }, { "input": "54", "output": "106 441" }, { "input": "96", "output": "144 777" }, { "input": "348", "output": "396 2793" }, { "input": "748", "output": "487 5993" }, { "input": "908", "output": "1840 7273" }, { "input": "1026", "output": "591 8217" }, { "input": "1985", "output": "3601 15889" }, { "input": "4472", "output": "1603 35785" }, { "input": "20845", "output": "8873 166769" }, { "input": "50480", "output": "17884 403849" }, { "input": "62497", "output": "312497 499985" }, { "input": "646055", "output": "140995 5168449" }, { "input": "790620", "output": "316416 6324969" }, { "input": "989903", "output": "1082167 7919233" }, { "input": "7033800", "output": "210976 56270409" }, { "input": "7661860", "output": "546725 61294889" }, { "input": "7834243", "output": "8302235 62673953" }, { "input": "45134118", "output": "19223945 361072953" }, { "input": "89054701", "output": "445273517 712437617" }, { "input": "99264891", "output": "15587889 794119137" }, { "input": "127039320", "output": "1209066 1016314569" }, { "input": "206898748", "output": "1683461 1655189993" }, { "input": "231136953", "output": "539319577 1849095633" }, { "input": "257259713", "output": "2122207 2058077713" }, { "input": "286736327", "output": "290355727 2293890625" }, { "input": "311933803", "output": "1559669027 2495470433" }, { "input": "332393619", "output": "10714371 2659148961" }, { "input": "422114561", "output": "78417139 3376916497" }, { "input": "453012754", "output": "2844347 3624102041" }, { "input": "470860680", "output": "129486993 3766885449" }, { "input": "509607936", "output": "3045276 4076863497" }, { "input": "534879507", "output": "253364145 4279036065" }, { "input": "535074941", "output": "647722381 4280599537" }, { "input": "536870912", "output": "3151876 4294967305" }, { "input": "573308928", "output": "3301020 4586471433" }, { "input": "603979776", "output": "3414276 4831838217" }, { "input": "605404800", "output": "3414952 4843238409" }, { "input": "615716902", "output": "10508698 4925735225" }, { "input": "628464178", "output": "3574502 5027713433" }, { "input": "631243141", "output": "634644469 5049945137" }, { "input": "644972544", "output": "3573148 5159780361" }, { "input": "659274082", "output": "1977822262 5274192665" }, { "input": "679477248", "output": "3693060 5435817993" }, { "input": "735134400", "output": "3886608 5881075209" }, { "input": "764411904", "output": "3988228 6115295241" }, { "input": "778377600", "output": "4036708 6227020809" }, { "input": "791683200", "output": "4082888 6333465609" }, { "input": "805306368", "output": "4201476 6442450953" }, { "input": "821620800", "output": "4185636 6572966409" }, { "input": "856079286", "output": "196667409 6848634297" }, { "input": "857656800", "output": "4307008 6861254409" }, { "input": "859963392", "output": "4320292 6879707145" }, { "input": "864864000", "output": "4331048 6918912009" }, { "input": "882161280", "output": "4388720 7057290249" }, { "input": "884822400", "output": "4396766 7078579209" }, { "input": "905969664", "output": "4529412 7247757321" }, { "input": "908107200", "output": "4474050 7264857609" }, { "input": "918918000", "output": "4511288 7351344009" }, { "input": "931170240", "output": "4548514 7449361929" }, { "input": "935625600", "output": "4563150 7485004809" }, { "input": "936354996", "output": "40069269 7490839977" }, { "input": "951350400", "output": "4614600 7610803209" }, { "input": "958557600", "output": "4637398 7668460809" }, { "input": "972972000", "output": "4685478 7783776009" }, { "input": "980179200", "output": "4707050 7841433609" }, { "input": "985944960", "output": "4725040 7887559689" }, { "input": "994593600", "output": "4752650 7956748809" }, { "input": "999893227", "output": "1000183267 7999145825" }, { "input": "999893387", "output": "1000724227 7999147105" }, { "input": "999905161", "output": "1000161721 7999241297" }, { "input": "999942949", "output": "1000368197 7999543601" }, { "input": "999996583", "output": "1022096687 7999972673" }, { "input": "999999797", "output": "4999998997 7999998385" }, { "input": "999999883", "output": "4999999427 7999999073" }, { "input": "999999893", "output": "4999999477 7999999153" }, { "input": "999999929", "output": "4999999657 7999999441" }, { "input": "999999937", "output": "4999999697 7999999505" }, { "input": "999999991", "output": "1059701759 7999999937" }, { "input": "999999992", "output": "129518035 7999999945" }, { "input": "999999993", "output": "490196227 7999999953" }, { "input": "999999994", "output": "928571477 7999999961" }, { "input": "999999995", "output": "4924975 7999999969" }, { "input": "999999996", "output": "1000000044 7999999977" }, { "input": "999999997", "output": "15309947 7999999985" }, { "input": "999999998", "output": "504345691 7999999993" }, { "input": "999999999", "output": "52392027 8000000001" }, { "input": "1000000000", "output": "4770064 8000000009" } ]
1,619,577,675
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
1,228,800
#!/usr/bin/env python3 # this solution convert variable to the following way # n = x*y*z then find the minimum and maximum integer value # of the following expression (x+1)*(y+2)*(z+2) def int_sqrt(n): return int(n**(1/2)) def min_sum(prod): ms = prod + 1 # initial minimum possible sum for i in range(1, int_sqrt(prod) + 1): if prod % i == 0: s = i + prod/i if ms > s: ms = s return ms def main(): n = int(input()) minp = 9*n+9 # initial minimum product maxp = 1 for x in range(1, n+1): if n % x != 0: continue else: # print("x: " + str(x), end = ', ') yz_prod = n/x # print("yz_prod: " + str(yz_prod), end = ', ') # expression for minium product (x+1)*(y+2)*(z+2) ms = min_sum(yz_prod) mi_p = (yz_prod + 2*ms + 4)*(x + 1) # print("min_sum: " + str(ms), end = ', ') # print("mi_p: " + str(mi_p), end = ', ') ma_p = (yz_prod + 2*(yz_prod + 1) + 4)*(x + 1) # print("ma_p: " + str(ma_p)) if (mi_p < minp): minp = mi_p if (ma_p > maxp): maxp = ma_p print(str(int(minp - n)) + ' ' + str(int(maxp - n))) if __name__ == '__main__': main()
Title: Help Farmer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks. At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*. Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks. Input Specification: The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). Output Specification: Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Demo Input: ['4\n', '7\n', '12\n'] Demo Output: ['28 41\n', '47 65\n', '48 105\n'] Note: Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks.
```python #!/usr/bin/env python3 # this solution convert variable to the following way # n = x*y*z then find the minimum and maximum integer value # of the following expression (x+1)*(y+2)*(z+2) def int_sqrt(n): return int(n**(1/2)) def min_sum(prod): ms = prod + 1 # initial minimum possible sum for i in range(1, int_sqrt(prod) + 1): if prod % i == 0: s = i + prod/i if ms > s: ms = s return ms def main(): n = int(input()) minp = 9*n+9 # initial minimum product maxp = 1 for x in range(1, n+1): if n % x != 0: continue else: # print("x: " + str(x), end = ', ') yz_prod = n/x # print("yz_prod: " + str(yz_prod), end = ', ') # expression for minium product (x+1)*(y+2)*(z+2) ms = min_sum(yz_prod) mi_p = (yz_prod + 2*ms + 4)*(x + 1) # print("min_sum: " + str(ms), end = ', ') # print("mi_p: " + str(mi_p), end = ', ') ma_p = (yz_prod + 2*(yz_prod + 1) + 4)*(x + 1) # print("ma_p: " + str(ma_p)) if (mi_p < minp): minp = mi_p if (ma_p > maxp): maxp = ma_p print(str(int(minp - n)) + ' ' + str(int(maxp - n))) if __name__ == '__main__': main() ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,673,335,491
2,147,483,647
PyPy 3-64
OK
TESTS
81
124
0
n=int(input()) a=0 b=0 c=0 for i in range(n): lst=list(map(int,input().split())) a+=lst[0] b+=lst[1] c+=lst[2] if(a==0 and b==0 and c==0): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) a=0 b=0 c=0 for i in range(n): lst=list(map(int,input().split())) a+=lst[0] b+=lst[1] c+=lst[2] if(a==0 and b==0 and c==0): print("YES") else: print("NO") ```
3.969
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair.
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32", "output": "25" }, { "input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50", "output": "1" }, { "input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1", "output": "1" }, { "input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50", "output": "50" }, { "input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "50" }, { "input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9", "output": "9" } ]
1,621,439,262
2,147,483,647
Python 3
OK
TESTS
56
202
13,721,600
input() k=set() ans=0 for i in tuple(map(int,input().split())): if i not in k: k.add(i) ans=max(len(k),ans) else: k.remove(i) print(ans)
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair. Output Specification: Print single integer — the maximum number of socks that were on the table at the same time. Demo Input: ['1\n1 1\n', '3\n2 1 1 3 2 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
```python input() k=set() ans=0 for i in tuple(map(int,input().split())): if i not in k: k.add(i) ans=max(len(k),ans) else: k.remove(i) print(ans) ```
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,575,819,553
2,147,483,647
Python 3
OK
TESTS
26
124
0
n = int(input()) i = 1 j = n - 1 mxi = -1 mxj = 1001 while i < j: for d in range(2, i+1): if (j % d == 0) and (i % d == 0): break else: if (i > mxi) and (j < mxj): mxi = i mxj = j i += 1 j -= 1 print(mxi, mxj)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python n = int(input()) i = 1 j = n - 1 mxi = -1 mxj = 1001 while i < j: for d in range(2, i+1): if (j % d == 0) and (i % d == 0): break else: if (i > mxi) and (j < mxj): mxi = i mxj = j i += 1 j -= 1 print(mxi, mxj) ```
3
295
A
Greg and Array
PROGRAMMING
1,400
[ "data structures", "implementation" ]
null
null
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*. Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array. Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg.
The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array. Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105). Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). The numbers in the lines are separated by single spaces.
On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces. 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 of the %I64d specifier.
[ "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n", "1 1 1\n1\n1 1 1\n1 1\n", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n" ]
[ "9 18 17\n", "2\n", "5 18 31 20\n" ]
none
500
[ { "input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "output": "9 18 17" }, { "input": "1 1 1\n1\n1 1 1\n1 1", "output": "2" }, { "input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3", "output": "5 18 31 20" }, { "input": "1 1 1\n0\n1 1 0\n1 1", "output": "0" } ]
1,662,523,020
2,147,483,647
PyPy 3-64
OK
TESTS
31
1,231
25,600,000
n, m, k = map(int, input().split()) array = list(map(int, input().split())) L = [] R = [] D = [] for i in range(m): l, r, d = map(int, input().split()) L.append(l) R.append(r) D.append(d) L[i] -= 1 U = [0 for _ in range(m+1)] for i in range(k): x, y = map(int, input().split()) x -= 1 U[x] += 1 U[y] -= 1 c = 0 C = [0 for _ in range(n+1)] for i in range(m): c += U[i] C[L[i]] += D[i] * c C[R[i]] -= D[i] * c; c = 0 for i in range(n): c += C[i] array[i] += c str_array = list(map(str, array)) print(" ".join(str_array))
Title: Greg and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*. Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array. Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. Input Specification: The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array. Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105). Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). The numbers in the lines are separated by single spaces. Output Specification: On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces. 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 of the %I64d specifier. Demo Input: ['3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n', '1 1 1\n1\n1 1 1\n1 1\n', '4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n'] Demo Output: ['9 18 17\n', '2\n', '5 18 31 20\n'] Note: none
```python n, m, k = map(int, input().split()) array = list(map(int, input().split())) L = [] R = [] D = [] for i in range(m): l, r, d = map(int, input().split()) L.append(l) R.append(r) D.append(d) L[i] -= 1 U = [0 for _ in range(m+1)] for i in range(k): x, y = map(int, input().split()) x -= 1 U[x] += 1 U[y] -= 1 c = 0 C = [0 for _ in range(n+1)] for i in range(m): c += U[i] C[L[i]] += D[i] * c C[R[i]] -= D[i] * c; c = 0 for i in range(n): c += C[i] array[i] += c str_array = list(map(str, array)) print(" ".join(str_array)) ```
3
551
C
GukiZ hates Boxes
PROGRAMMING
2,200
[ "binary search", "greedy" ]
null
null
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are *n* piles of boxes, arranged in a line, from left to right, *i*-th pile (1<=≤<=*i*<=≤<=*n*) containing *a**i* boxes. Luckily, *m* students are willing to help GukiZ by removing all the boxes from his way. Students are working simultaneously. At time 0, all students are located left of the first pile. It takes one second for every student to move from this position to the first pile, and after that, every student must start performing sequence of two possible operations, each taking one second to complete. Possible operations are: 1. If *i*<=≠<=*n*, move from pile *i* to pile *i*<=+<=1;1. If pile located at the position of student is not empty, remove one box from it. GukiZ's students aren't smart at all, so they need you to tell them how to remove boxes before professor comes (he is very impatient man, and doesn't want to wait). They ask you to calculate minumum time *t* in seconds for which they can remove all the boxes from GukiZ's way. Note that students can be positioned in any manner after *t* seconds, but all the boxes must be removed.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105), the number of piles of boxes and the number of GukiZ's students. The second line contains *n* integers *a*1,<=*a*2,<=... *a**n* (0<=≤<=*a**i*<=≤<=109) where *a**i* represents the number of boxes on *i*-th pile. It's guaranteed that at least one pile of is non-empty.
In a single line, print one number, minimum time needed to remove all the boxes in seconds.
[ "2 1\n1 1\n", "3 2\n1 0 2\n", "4 100\n3 4 5 4\n" ]
[ "4\n", "5\n", "5\n" ]
First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second). Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5 seconds. Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile. Process will be over in 5 seconds, when removing the boxes from the last pile is finished.
1,750
[ { "input": "2 1\n1 1", "output": "4" }, { "input": "3 2\n1 0 2", "output": "5" }, { "input": "4 100\n3 4 5 4", "output": "5" }, { "input": "5 8\n121351 0 13513 0 165454", "output": "37544" }, { "input": "6 6\n0 10 0 0 10 0", "output": "8" }, { "input": "1 1\n1", "output": "2" }, { "input": "1 100000\n1", "output": "2" }, { "input": "1 100000\n1000000000", "output": "10001" }, { "input": "1 1\n1000000000", "output": "1000000001" }, { "input": "20 20\n0 0 0 0 0 0 154 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "15" }, { "input": "10 10\n0 0 0 100 0 0 0 0 0 0", "output": "14" }, { "input": "15 20\n0 0 0 500 0 0 0 0 400 0 0 0 0 0 0", "output": "52" }, { "input": "5 3\n0 0 14 0 0", "output": "8" }, { "input": "6 2\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "3000000005" }, { "input": "3 2\n10 0 0", "output": "6" }, { "input": "3 100000\n0 1 0", "output": "3" }, { "input": "9 5\n0 0 0 0 0 0 0 0 6", "output": "11" }, { "input": "4 1\n0 1000000000 0 1", "output": "1000000005" }, { "input": "19 100000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "20" }, { "input": "7 1\n13 14 15 1 1 0 1", "output": "52" }, { "input": "5 3\n999999999 999999999 999999999 999999999 19992232", "output": "1339997413" }, { "input": "1 1\n15141354", "output": "15141355" }, { "input": "1 100000\n543431351", "output": "5436" } ]
1,679,498,937
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
53
140
13,516,800
n,m = map(int, input().split()) A = list(map(int, input().split())) lo, hi = 1, 10**15 def check(maxt): st, b = 0, A[0] for i in range(m): t = maxt-1-st while t > 0: rem = min(b, t) b, t = b-rem, t-rem if b == 0: st += 1 if st == n: return True b, t = A[st], t-1 return False while lo+1 < hi: mid = (lo+hi) // 2 if check(mid): hi = mid else: lo = mid print(hi)
Title: GukiZ hates Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are *n* piles of boxes, arranged in a line, from left to right, *i*-th pile (1<=≤<=*i*<=≤<=*n*) containing *a**i* boxes. Luckily, *m* students are willing to help GukiZ by removing all the boxes from his way. Students are working simultaneously. At time 0, all students are located left of the first pile. It takes one second for every student to move from this position to the first pile, and after that, every student must start performing sequence of two possible operations, each taking one second to complete. Possible operations are: 1. If *i*<=≠<=*n*, move from pile *i* to pile *i*<=+<=1;1. If pile located at the position of student is not empty, remove one box from it. GukiZ's students aren't smart at all, so they need you to tell them how to remove boxes before professor comes (he is very impatient man, and doesn't want to wait). They ask you to calculate minumum time *t* in seconds for which they can remove all the boxes from GukiZ's way. Note that students can be positioned in any manner after *t* seconds, but all the boxes must be removed. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105), the number of piles of boxes and the number of GukiZ's students. The second line contains *n* integers *a*1,<=*a*2,<=... *a**n* (0<=≤<=*a**i*<=≤<=109) where *a**i* represents the number of boxes on *i*-th pile. It's guaranteed that at least one pile of is non-empty. Output Specification: In a single line, print one number, minimum time needed to remove all the boxes in seconds. Demo Input: ['2 1\n1 1\n', '3 2\n1 0 2\n', '4 100\n3 4 5 4\n'] Demo Output: ['4\n', '5\n', '5\n'] Note: First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second). Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5 seconds. Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile. Process will be over in 5 seconds, when removing the boxes from the last pile is finished.
```python n,m = map(int, input().split()) A = list(map(int, input().split())) lo, hi = 1, 10**15 def check(maxt): st, b = 0, A[0] for i in range(m): t = maxt-1-st while t > 0: rem = min(b, t) b, t = b-rem, t-rem if b == 0: st += 1 if st == n: return True b, t = A[st], t-1 return False while lo+1 < hi: mid = (lo+hi) // 2 if check(mid): hi = mid else: lo = mid print(hi) ```
0
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,683,917,586
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
num1, num2 = map(int, input().split()) def dfs(num1, num2): if not num2: return num1 return dfs(num2, num1 % num2) print(dfs(num1, num2))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python num1, num2 = map(int, input().split()) def dfs(num1, num2): if not num2: return num1 return dfs(num2, num1 % num2) print(dfs(num1, num2)) ```
0
1,000
C
Covered Points Count
PROGRAMMING
1,700
[ "data structures", "implementation", "sortings" ]
null
null
You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$.
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments. The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment.
Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$.
[ "3\n0 3\n1 3\n3 8\n", "3\n1 3\n2 4\n5 7\n" ]
[ "6 2 1 \n", "5 2 0 \n" ]
The picture describing the first example: <img class="tex-graphics" src="https://espresso.codeforces.com/f76b3fe547bff6be5b14de76c8b78ba3efecc744.png" style="max-width: 100.0%;max-height: 100.0%;"/> Points with coordinates $[0, 4, 5, 6, 7, 8]$ are covered by one segment, points $[1, 2]$ are covered by two segments and point $[3]$ is covered by three segments. The picture describing the second example: <img class="tex-graphics" src="https://espresso.codeforces.com/6e9332c303e1bc5d6cf34c2d6c5e2a19c9417289.png" style="max-width: 100.0%;max-height: 100.0%;"/> Points $[1, 4, 5, 6, 7]$ are covered by one segment, points $[2, 3]$ are covered by two segments and there are no points covered by three segments.
0
[ { "input": "3\n0 3\n1 3\n3 8", "output": "6 2 1 " }, { "input": "3\n1 3\n2 4\n5 7", "output": "5 2 0 " }, { "input": "1\n0 1000000000000000000", "output": "1000000000000000001 " } ]
1,673,010,267
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
3,000
156,672,000
def fff(): k = [] inp = int(input()) for x in range(inp): k.append(list(map(int,input().split()))) j = [-1 for x in range(max(k[-1])+1)] for x in k: for y in range(x[0],x[1]+1): j[y] += 1 t = [0 for x in range(inp)] for x in j: if x != -1: t[x] += 1 print(' '.join(list(map(str,t)))) fff()
Title: Covered Points Count Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments. The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment. Output Specification: Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$. Demo Input: ['3\n0 3\n1 3\n3 8\n', '3\n1 3\n2 4\n5 7\n'] Demo Output: ['6 2 1 \n', '5 2 0 \n'] Note: The picture describing the first example: <img class="tex-graphics" src="https://espresso.codeforces.com/f76b3fe547bff6be5b14de76c8b78ba3efecc744.png" style="max-width: 100.0%;max-height: 100.0%;"/> Points with coordinates $[0, 4, 5, 6, 7, 8]$ are covered by one segment, points $[1, 2]$ are covered by two segments and point $[3]$ is covered by three segments. The picture describing the second example: <img class="tex-graphics" src="https://espresso.codeforces.com/6e9332c303e1bc5d6cf34c2d6c5e2a19c9417289.png" style="max-width: 100.0%;max-height: 100.0%;"/> Points $[1, 4, 5, 6, 7]$ are covered by one segment, points $[2, 3]$ are covered by two segments and there are no points covered by three segments.
```python def fff(): k = [] inp = int(input()) for x in range(inp): k.append(list(map(int,input().split()))) j = [-1 for x in range(max(k[-1])+1)] for x in k: for y in range(x[0],x[1]+1): j[y] += 1 t = [0 for x in range(inp)] for x in j: if x != -1: t[x] += 1 print(' '.join(list(map(str,t)))) fff() ```
0
6
E
Exposition
PROGRAMMING
1,900
[ "binary search", "data structures", "dsu", "trees", "two pointers" ]
E. Exposition
1
64
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters. The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.
The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters.
In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters. In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.
[ "3 3\n14 12 10\n", "2 0\n10 10\n", "4 5\n8 19 10 13\n" ]
[ "2 2\n1 2\n2 3\n", "2 1\n1 2\n", "2 1\n3 4\n" ]
none
0
[ { "input": "3 3\n14 12 10", "output": "2 2\n1 2\n2 3" }, { "input": "2 0\n10 10", "output": "2 1\n1 2" }, { "input": "4 5\n8 19 10 13", "output": "2 1\n3 4" }, { "input": "1 1\n1", "output": "1 1\n1 1" }, { "input": "2 10\n35 45", "output": "2 1\n1 2" }, { "input": "4 8\n89 33 54 75", "output": "1 4\n1 1\n2 2\n3 3\n4 4" }, { "input": "5 1\n9 6 8 7 5", "output": "2 1\n3 4" }, { "input": "3 3\n3 8 6", "output": "2 1\n2 3" }, { "input": "4 1000000\n100001 1 200001 300001", "output": "4 1\n1 4" }, { "input": "4 1000\n11497 9999 10730 12280", "output": "2 1\n2 3" }, { "input": "3 0\n1000000 1000000 1000000", "output": "3 1\n1 3" }, { "input": "4 50\n165 182 157 132", "output": "4 1\n1 4" }, { "input": "5 173\n350 250 200 300 400", "output": "4 1\n1 4" }, { "input": "4 0\n1 1 1 1", "output": "4 1\n1 4" }, { "input": "2 1000000\n1 1000000", "output": "2 1\n1 2" }, { "input": "7 14\n28 28 29 35 25 29 28", "output": "7 1\n1 7" }, { "input": "10 163\n7541 2535 5883 5775 2821 5962 4489 5548 2852 4595", "output": "2 1\n3 4" }, { "input": "15 793\n98580 27440 3719 73977 34819 64092 89939 75329 72884 66502 17464 73662 6666 47984 45348", "output": "1 15\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15" }, { "input": "28 543\n1921 1700 1363 2580 2693 3144 2269 908 3863 3750 2151 3039 1581 3395 1133 1804 1464 2040 2372 2475 1240 800 3521 3270 2815 1026 3625 2930", "output": "3 1\n18 20" }, { "input": "55 1000\n2612 1306 4300 1790 3173 9493 7209 7763 8563 4534 7466 1281 4483 6863 3787 7292 3957 8775 7221 4016 5743 6556 2070 2119 4795 9094 1913 2077 8786 4520 1865 2357 7871 3288 8231 5808 9383 9820 9974 3056 5343 2169 5177 6299 5805 8132 9315 6747 5226 3531 1206 4073 8290 1423 6720", "output": "3 1\n37 39" } ]
1,689,638,025
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689638025.2973702")# 1689638025.29739
Title: Exposition Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters. The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input Specification: The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters. Output Specification: In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters. In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Demo Input: ['3 3\n14 12 10\n', '2 0\n10 10\n', '4 5\n8 19 10 13\n'] Demo Output: ['2 2\n1 2\n2 3\n', '2 1\n1 2\n', '2 1\n3 4\n'] Note: none
```python print("_RANDOM_GUESS_1689638025.2973702")# 1689638025.29739 ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,678,604,266
2,147,483,647
Python 3
OK
TESTS
30
92
0
o = input() result = "" p = 0 while p < len(o): if o[p] == ".": result += '0' else: p += 1 if o[p] == ".": result += '1' else: result += '2' p += 1 print(result)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python o = input() result = "" p = 0 while p < len(o): if o[p] == ".": result += '0' else: p += 1 if o[p] == ".": result += '1' else: result += '2' p += 1 print(result) ```
3.977
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2", "output": "5\n7\n5\n5\n2\n7\n7\n13\n4" }, { "input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7", "output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326" }, { "input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29", "output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772" }, { "input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12", "output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195" }, { "input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1", "output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2" }, { "input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2", "output": "6\n1\n6\n1\n5\n6\n1\n5" }, { "input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4", "output": "22\n10\n10\n6\n12\n36\n6\n14\n16" }, { "input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4", "output": "11\n11\n2\n10\n1\n3\n10\n12\n12" }, { "input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5", "output": "8\n27\n1\n8\n26" }, { "input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8", "output": "10\n2\n13\n10" }, { "input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5", "output": "9\n24\n28" }, { "input": "1\n1\n2\n1 1 1\n2 1 1", "output": "1\n1" } ]
1,668,375,498
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
15
0
n = int(input()) a = list(map(int, input().split())) k = int(input()) b = [0] sum = 0 for i in range(n): sum += a[i] b.append(sum) a.sort() c = [0] for i in range(n): sum += a[i] c.append(sum) for i in range(k): temp = list(map(int, input().split())) if temp[0] == 1: l = temp[1] r = temp[2] print(b[r] - b[l -1]) else: l = temp[1] r = temp[2] print(c[r] - c[l - 1])
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. Output Specification: Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. Demo Input: ['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n'] Demo Output: ['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n'] Note: Please note that the answers to the questions may overflow 32-bit integer type.
```python n = int(input()) a = list(map(int, input().split())) k = int(input()) b = [0] sum = 0 for i in range(n): sum += a[i] b.append(sum) a.sort() c = [0] for i in range(n): sum += a[i] c.append(sum) for i in range(k): temp = list(map(int, input().split())) if temp[0] == 1: l = temp[1] r = temp[2] print(b[r] - b[l -1]) else: l = temp[1] r = temp[2] print(c[r] - c[l - 1]) ```
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
1,664,775,685
2,147,483,647
Python 3
OK
TESTS
54
46
0
n = int(input()) li = input().strip('W').split('W') r = [] for i in li: if i: r.append(len(i)) print(len(r)) print(*r)
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). Output Specification: The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. Demo Input: ['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n'] Demo Output: ['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 '] Note: The last sample case correspond to the picture in the statement.
```python n = int(input()) li = input().strip('W').split('W') r = [] for i in li: if i: r.append(len(i)) print(len(r)) print(*r) ```
3
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered. Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages. Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen. Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*.
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24 23 22 21 20 19 18 17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "Karen" }, { "input": "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 1238375 743262 106355 1167830 180315 1233029 816465 752968 782570 1499881 1328457 1867240 13948 1302782\n322597 1868510 1958236 1348157 765908 1023636 874300 537124 631783 414906 886318 1931572 1381013 992451 1305644 1525745 716087 83173 303248 1572710 43084 333341 992413 267806 70390 644521 1014900 497068 178940 1920268", "output": "Karen" }, { "input": "30\n1143673 436496 1214486 1315862 148404 724601 1430740 1433008 1654610 1635673 614673 1713408 1270999 1697 1463796 50027 525482 1659078 688200 842647 518551 877506 1017082 1807856 3280 759698 1208220 470180 829800 1960886\n1312613 1965095 967255 1289012 1950383 582960 856825 49684 808824 319418 1968270 190821 344545 211332 1219388 1773751 1876402 132626 541448 1584672 24276 1053225 1823073 1858232 1209173 1035991 1956373 1237148 1973608 848873", "output": "Karen" }, { "input": "1\n2\n3", "output": "Karen" }, { "input": "1\n1048576\n1020000", "output": "Karen" }, { "input": "3\n9 33 69\n71 74 100", "output": "Karen" }, { "input": "3\n1 2 3\n9 5 6", "output": "Karen" }, { "input": "3\n1 7 8\n9 10 20", "output": "Karen" }, { "input": "3\n1 3 2\n4 5 8", "output": "Karen" }, { "input": "3\n2 1 100\n3 4 9", "output": "Karen" }, { "input": "3\n3 1 100\n2 1000 100000", "output": "Karen" }, { "input": "3\n1 2 5\n3 4 6", "output": "Karen" }, { "input": "3\n3 1 8\n2 4 17", "output": "Karen" }, { "input": "3\n1 5 6\n7 8 3", "output": "Karen" }, { "input": "1\n1\n3", "output": "Karen" }, { "input": "3\n1 3 10\n2 4 20", "output": "Karen" }, { "input": "3\n7 8 10\n15 9 11", "output": "Karen" }, { "input": "3\n5 6 8\n3 100 9", "output": "Karen" }, { "input": "3\n1 2 3\n4 5 8", "output": "Karen" }, { "input": "3\n1 2 19\n3 7 30", "output": "Karen" }, { "input": "3\n1 2 3\n6 7 8", "output": "Karen" }, { "input": "3\n1 4 55\n2 3 9", "output": "Karen" }, { "input": "3\n1 100 200\n5 4 500", "output": "Karen" }, { "input": "1\n6\n7", "output": "Karen" }, { "input": "3\n1 3 5\n2 4 13", "output": "Karen" }, { "input": "3\n3 1 100\n2 1000 10000", "output": "Karen" }, { "input": "3\n1 3 9\n2 4 40", "output": "Karen" }, { "input": "2\n1 199999\n1935807 2000000", "output": "Karen" }, { "input": "3\n1 3 8\n2 4 24", "output": "Karen" }, { "input": "2\n4 1\n7 3", "output": "Karen" }, { "input": "3\n1 2 4\n3 7 8", "output": "Karen" }, { "input": "3\n1 6 10000\n2 3 100000", "output": "Karen" } ]
1,548,798,297
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
614,400
l1=[] n=int(input("")) l1 = list(map(int, input('').split())) l2=[] l2 = list(map(int, input('').split())) l=l1+l2 c=0 for i in range (n): for j in range (n): if (l1[i]^l2[j] in l ): c=c+1 if (c % 2 == 0 ) : print("Karen") else: print("Koyomi")
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered. Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages. Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game. Input Specification: The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen. Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*. Output Specification: Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization. Demo Input: ['3\n1 2 3\n4 5 6\n', '5\n2 4 6 8 10\n9 7 5 3 1\n'] Demo Output: ['Karen\n', 'Karen\n'] Note: In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
```python l1=[] n=int(input("")) l1 = list(map(int, input('').split())) l2=[] l2 = list(map(int, input('').split())) l=l1+l2 c=0 for i in range (n): for j in range (n): if (l1[i]^l2[j] in l ): c=c+1 if (c % 2 == 0 ) : print("Karen") else: print("Koyomi") ```
0
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "output": "100" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "199" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb", "output": "99" }, { "input": "abcde\nfghij", "output": "5" }, { "input": "abcde\nabcdf", "output": "5" }, { "input": "abcde\nbbcde", "output": "5" }, { "input": "abcde\neabcd", "output": "5" }, { "input": "abcdefgh\nabdcefgh", "output": "8" }, { "input": "mmmmm\nmnmmm", "output": "5" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa", "output": "34" }, { "input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy", "output": "26" }, { "input": "a\nab", "output": "2" }, { "input": "b\nab", "output": "2" }, { "input": "ab\nb", "output": "2" }, { "input": "ab\nc", "output": "2" }, { "input": "aaaaaa\naaaaaa", "output": "-1" }, { "input": "abacaba\nabacaba", "output": "-1" }, { "input": "aabb\nbbaa", "output": "4" }, { "input": "ab\nba", "output": "2" }, { "input": "abcd\nabc", "output": "4" }, { "input": "abaa\nabaa", "output": "-1" }, { "input": "ab\nab", "output": "-1" }, { "input": "ab\nabcd", "output": "4" }, { "input": "abc\nabcd", "output": "4" }, { "input": "mo\nmomo", "output": "4" }, { "input": "koooooooooooooooo\nloooooooooooooooo", "output": "17" }, { "input": "aaa\naa", "output": "3" }, { "input": "abc\nabc", "output": "-1" }, { "input": "abcd\nabcd", "output": "-1" }, { "input": "abc\ncba", "output": "3" }, { "input": "ahc\nahc", "output": "-1" }, { "input": "abc\nbac", "output": "3" }, { "input": "aa\naaa", "output": "3" }, { "input": "aaa\naaa", "output": "-1" }, { "input": "abc\nacb", "output": "3" }, { "input": "abc\nab", "output": "3" }, { "input": "abb\nabb", "output": "-1" }, { "input": "abc\ncab", "output": "3" }, { "input": "aaaaaa\naaaaa", "output": "6" }, { "input": "aa\naab", "output": "3" }, { "input": "len\nlena", "output": "4" }, { "input": "aaaaa\naa", "output": "5" }, { "input": "aaa\naaaa", "output": "4" }, { "input": "bcd\nabcd", "output": "4" }, { "input": "aaabbc\naaaccc", "output": "6" }, { "input": "abcd\nzycd", "output": "4" }, { "input": "baa\nzaa", "output": "3" }, { "input": "asdf\nadfs", "output": "4" }, { "input": "abcdefgh\nabcdefgh", "output": "-1" }, { "input": "aba\naab", "output": "3" }, { "input": "aba\naba", "output": "-1" }, { "input": "abcccc\naccccc", "output": "6" }, { "input": "acb\nabc", "output": "3" }, { "input": "a\naa", "output": "2" }, { "input": "abababab\nab", "output": "8" }, { "input": "ababab\nab", "output": "6" } ]
1,664,166,458
2,147,483,647
PyPy 3-64
OK
TESTS
73
62
307,200
def solve(): a = input() b = input() print(-1 if a == b else max(len(a), len(b))) t = 1 #int(input()) for i in range(t): #print(f"Case #{i+1}:", end=" ") solve()
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input Specification: The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output Specification: If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. Demo Input: ['abcd\ndefgh\n', 'a\na\n'] Demo Output: ['5\n', '-1\n'] Note: In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
```python def solve(): a = input() b = input() print(-1 if a == b else max(len(a), len(b))) t = 1 #int(input()) for i in range(t): #print(f"Case #{i+1}:", end=" ") solve() ```
3
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" }, { "input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761", "output": "YES" }, { "input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974", "output": "YES" }, { "input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291", "output": "NO" }, { "input": "3\n1 1000000000 1000000000", "output": "YES" }, { "input": "4\n1 1000000000 1000000000 1000000000", "output": "YES" }, { "input": "3\n1 1000000000 1", "output": "NO" }, { "input": "5\n1 2 3 5 2", "output": "YES" }, { "input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431", "output": "NO" }, { "input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159", "output": "YES" }, { "input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023", "output": "YES" }, { "input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015", "output": "YES" }, { "input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14", "output": "YES" }, { "input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368", "output": "NO" }, { "input": "3\n1 1000000000 999999999", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000", "output": "NO" }, { "input": "5\n2 3 4 10 20", "output": "YES" }, { "input": "6\n18 23 40 80 160 161", "output": "YES" }, { "input": "4\n5 6 7 888", "output": "YES" }, { "input": "9\n1 1 2 2 4 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 900 4 500 1500 5", "output": "YES" }, { "input": "3\n2 2 3", "output": "YES" }, { "input": "7\n1 2 100 200 250 1000000 2000000", "output": "YES" }, { "input": "8\n2 3 5 5 5 6 6 13", "output": "YES" }, { "input": "3\n2 3 4", "output": "YES" }, { "input": "6\n1 1 1 4 5 100", "output": "YES" }, { "input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377", "output": "YES" }, { "input": "4\n2 3 4 8", "output": "YES" }, { "input": "3\n5 6 7", "output": "YES" }, { "input": "5\n1 4 5 6 1000000", "output": "YES" }, { "input": "4\n5 6 7 20", "output": "YES" }, { "input": "6\n1 1 1 1 1 65", "output": "YES" }, { "input": "4\n3 4 5 100", "output": "YES" }, { "input": "3\n2 4 5", "output": "YES" }, { "input": "7\n1 1 1 1 1 10 1000", "output": "YES" }, { "input": "4\n1 1 2 3", "output": "NO" }, { "input": "11\n1 2 5 6 7 8 9 17 18 19 100", "output": "YES" }, { "input": "4\n5 16 20 200", "output": "YES" }, { "input": "5\n17 6 3 3 1", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "6\n1 1 1 2 3 5", "output": "YES" }, { "input": "4\n2 4 6 6", "output": "YES" }, { "input": "9\n1 2 4 4 4 4 7 8 20", "output": "YES" }, { "input": "9\n1 1 2 5 5 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 600 4 1700 6000 5", "output": "YES" }, { "input": "5\n5761 20966 27841 28800 29399", "output": "YES" }, { "input": "9\n1 2 3 6 7 10 11 12 24", "output": "YES" }, { "input": "4\n1 2 1 1", "output": "YES" }, { "input": "5\n1 1 2 3 4", "output": "YES" } ]
1,642,795,279
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
93
7,884,800
n = int(input()) a = list(map(int,input().split(' '))) a.sort() if a[len(a)-2] +a[len(a)-3]> max(a): print('YES') else: print('NO')
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. Output Specification: In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. Demo Input: ['5\n1 5 3 2 4\n', '3\n4 1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
```python n = int(input()) a = list(map(int,input().split(' '))) a.sort() if a[len(a)-2] +a[len(a)-3]> max(a): print('YES') else: print('NO') ```
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,641,389,652
2,147,483,647
Python 3
OK
TESTS
40
46
0
s=input() f=False for i in range(len(s)): if s[i]=='h': for l in range(i+1,len(s)): if s[l]=='e': for k in range(l+1,len(s)): if s[k]=='l': for j in range(k+1,len(s)): if s[j]=='l': for p in range(j+1,len(s)): if s[p]=='o': f=True break if f: 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 s=input() f=False for i in range(len(s)): if s[i]=='h': for l in range(i+1,len(s)): if s[l]=='e': for k in range(l+1,len(s)): if s[k]=='l': for j in range(k+1,len(s)): if s[j]=='l': for p in range(j+1,len(s)): if s[p]=='o': f=True break if f: print('YES') else: print('NO') ```
3.977
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,639,563,844
2,147,483,647
Python 3
OK
TESTS
34
122
0
n = int(input()) t1 = 0 t2 = 0 temp = '' flag = '' for i in range(n): goal = input() if i == 0: temp = goal t1 += 1 else: if temp == goal: t1 += 1 else: flag = goal t2 += 1 if t1 > t2: print(temp) else: print(flag)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) t1 = 0 t2 = 0 temp = '' flag = '' for i in range(n): goal = input() if i == 0: temp = goal t1 += 1 else: if temp == goal: t1 += 1 else: flag = goal t2 += 1 if t1 > t2: print(temp) else: print(flag) ```
3.9695
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,694,451,717
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
61
2,764,800
n = int(input()) a = list(map((input().split()))) k, o = 0, float('-inf') for i in range(1,n): if a[i]>=a[i-1]: k+=1 else: o = max(o,k) print(o)
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()) a = list(map((input().split()))) k, o = 0, float('-inf') for i in range(1,n): if a[i]>=a[i-1]: k+=1 else: o = max(o,k) print(o) ```
-1
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,699,464,912
2,147,483,647
Python 3
OK
TESTS
47
92
0
n=str(input()) m = n if n[0] == '-': if int(n[-2]) <= int(n[-1]): m=n[:-1] else: m=n[:-2]+n[-1] m=int(m) print(m)
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python n=str(input()) m = n if n[0] == '-': if int(n[-2]) <= int(n[-1]): m=n[:-1] else: m=n[:-2]+n[-1] m=int(m) print(m) ```
3
907
B
Tic-Tac-Toe
PROGRAMMING
1,400
[ "implementation" ]
null
null
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (*x**l*,<=*y**l*) in some small field, the next move should be done in one of the cells of the small field with coordinates (*x**l*,<=*y**l*). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
[ "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n", "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n", "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5\n" ]
[ "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... \n\n", "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\n", "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n" ]
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
1,000
[ { "input": "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "output": "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... " }, { "input": "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "output": "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! " }, { "input": "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5", "output": "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! " }, { "input": ".o. .o. ..x\n..x .xx ..o\n... ... ...\n\n... ... xxo\n..x o.o oxo\n.x. .o. xoo\n\n... o.. ...\n..o .xx ..x\n... ... ...\n5 9", "output": "!o! !o! !!x \n!!x !xx !!o \n!!! !!! !!! \n\n!!! !!! xxo \n!!x o!o oxo \n!x! !o! xoo \n\n!!! o!! !!! \n!!o !xx !!x \n!!! !!! !!! " }, { "input": "... .o. ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... .x. ..x\n\n.x. ... ...\n..o ... .o.\n... o.o xx.\n1 5", "output": "... !o! ... \n... !!! ... \n... !!! ... \n\n... ... ... \n... ... ... \n... .x. ..x \n\n.x. ... ... \n..o ... .o. \n... o.o xx. " }, { "input": "ooo oxx xxo\nx.x oox xox\noox xo. xxx\n\nxxo xxx o.o\nxoo xo. oxo\nooo xox ox.\n\nxoo xoo .oo\nxox xox ox.\noxx xox oxo\n1 3", "output": "ooo oxx xxo \nx!x oox xox \noox xo! xxx \n\nxxo xxx o!o \nxoo xo! oxo \nooo xox ox! \n\nxoo xoo !oo \nxox xox ox! \noxx xox oxo " }, { "input": "... ... ...\n..o ... ..o\n... .x. ..x\n\nx.. ... ...\n.x. .ox oo.\n... .xo ..x\n\n... ... .ox\n... ox. ..x\n... ..o .o.\n2 3", "output": "... ... ... \n..o ... ..o \n... .x. ..x \n\nx.. ... !!! \n.x. .ox oo! \n... .xo !!x \n\n... ... .ox \n... ox. ..x \n... ..o .o. " }, { "input": "xox o.x xxo\nxox xox oxo\nxxx .xx xoo\n\nooo oox o.x\n.xx xx. oo.\nooo xox ooo\n\nooo oxo xox\nx.x xox xox\noxo x.o xxo\n1 7", "output": "xox o!x xxo \nxox xox oxo \nxxx !xx xoo \n\nooo oox o!x \n!xx xx! oo! \nooo xox ooo \n\nooo oxo xox \nx!x xox xox \noxo x!o xxo " }, { "input": "ox. x.o ..x\n... ..o .o.\n.o. ... x.o\n\nx.x .oo ...\n..o ox. .xx\n..x o.x .o.\n\n... ... .x.\nox. xx. .o.\n... ... ..o\n9 9", "output": "ox. x.o ..x \n... ..o .o. \n.o. ... x.o \n\nx.x .oo ... \n..o ox. .xx \n..x o.x .o. \n\n... ... !x! \nox. xx. !o! \n... ... !!o " }, { "input": "xx. oxx .xo\nxxx o.o xox\nxoo xoo xoo\n\nooo o.x xox\no.. xoo .xo\noxx .x. xoo\n\nooo oxo oxx\nxxx xox ..o\noo. oxx xx.\n3 8", "output": "xx! oxx !xo \nxxx o!o xox \nxoo xoo xoo \n\nooo o!x xox \no!! xoo !xo \noxx !x! xoo \n\nooo oxo oxx \nxxx xox !!o \noo! oxx xx! " }, { "input": "... xo. o..\noo. ..o xx.\n..x x.. ..o\n\n.ox .xx ...\no.x xox xo.\nxox .xo ..o\n\n..o ... xxo\no.. .o. oxo\n..o x.. ..x\n8 9", "output": "... xo. o.. \noo. ..o xx. \n..x x.. ..o \n\n.ox .xx !!! \no.x xox xo! \nxox .xo !!o \n\n..o ... xxo \no.. .o. oxo \n..o x.. ..x " }, { "input": "oox xoo xxx\nooo xxo oxo\nxxx xoo xxo\n\noxo oxx xoo\nxoo oox xox\nxox oox oox\n\nxxo xoo oxo\noxx xxx xxx\noxo oxo oo.\n1 5", "output": "oox xoo xxx \nooo xxo oxo \nxxx xoo xxo \n\noxo oxx xoo \nxoo oox xox \nxox oox oox \n\nxxo xoo oxo \noxx xxx xxx \noxo oxo oo! " }, { "input": ".oo x.o xoo\n.o. xxx .x.\n..o x.o xxx\n\n..o .oo .xx\n.x. xox o.o\n.xo o.o .x.\n\n.o. xo. xxx\n.xo o.. .xo\n..o ..o xox\n1 8", "output": ".oo x!o xoo \n.o. xxx .x. \n..o x!o xxx \n\n..o .oo .xx \n.x. xox o.o \n.xo o.o .x. \n\n.o. xo. xxx \n.xo o.. .xo \n..o ..o xox " }, { "input": "xxo xoo xxo\nooo ooo xxx\noox oxo oxx\n\noxo oxo xxx\nxoo oxx oxo\nxxx oxx ooo\n\noxx xoo xxo\nxxx oox xox\nxxo o.o oxo\n9 6", "output": "xxo xoo xxo \nooo ooo xxx \noox oxo oxx \n\noxo oxo xxx \nxoo oxx oxo \nxxx oxx ooo \n\noxx xoo xxo \nxxx oox xox \nxxo o!o oxo " }, { "input": "ox. o.x .o.\nxxo xoo .oo\n.xx oox o..\n\nxx. oox oxx\noox oxx xxo\nxo. oxo x.x\n\no.x .x. xx.\n.xo ox. ooo\n.ox xo. ..o\n6 2", "output": "ox. o.x .o. \nxxo xoo .oo \n.xx oox o.. \n\nxx. oox oxx \noox oxx xxo \nxo. oxo x.x \n\no.x !x! xx. \n.xo ox! ooo \n.ox xo! ..o " }, { "input": "oxo xoo ox.\nxxx xoo xxo\nxoo xxx xox\n\nxxx xxx xoo\nooo o.o oxx\nxxo ooo xxx\n\nooo oox ooo\nooo oxo xxx\nxxo xox xxo\n6 1", "output": "oxo xoo ox! \nxxx xoo xxo \nxoo xxx xox \n\nxxx xxx xoo \nooo o!o oxx \nxxo ooo xxx \n\nooo oox ooo \nooo oxo xxx \nxxo xox xxo " }, { "input": ".xo oxx xoo\nooo .xo xxx\noxo oox xoo\n\nx.o xoo xxx\nxo. oxo oxx\nx.x xoo o.o\n\nxoo xox oxx\nooo .x. .xx\nxox x.. xoo\n6 5", "output": ".xo oxx xoo \nooo .xo xxx \noxo oox xoo \n\nx.o xoo xxx \nxo. oxo oxx \nx.x xoo o.o \n\nxoo xox oxx \nooo !x! .xx \nxox x!! xoo " }, { "input": "oxo xox ooo\n.xo xxo oxx\nxxx oxo xxx\n\nxxo oxx .xx\nxo. xoo oxx\noxo oxx xox\n\nxoo ooo oox\nooo ooo xxo\nxxx x.o oxo\n2 2", "output": "oxo xox ooo \n!xo xxo oxx \nxxx oxo xxx \n\nxxo oxx !xx \nxo! xoo oxx \noxo oxx xox \n\nxoo ooo oox \nooo ooo xxo \nxxx x!o oxo " }, { "input": "xox xxx xoo\nxoo xxx oxo\nxoo oox xoo\n\noxo oox xox\noxo xox xox\noox xoo oox\n\no.o xox oox\noox xxo xxo\nxox xxx oxo\n3 4", "output": "xox xxx xoo \nxoo xxx oxo \nxoo oox xoo \n\noxo oox xox \noxo xox xox \noox xoo oox \n\no!o xox oox \noox xxo xxo \nxox xxx oxo " }, { "input": "ooo xxx .x.\nxxo oox ooo\n.o. oox xxx\n\nxox oxx xxo\nxxx oxx oxx\noxx ooo ooo\n\n.oo xoo xo.\nxxo oox ooo\nxox xxx xxo\n5 1", "output": "ooo xxx !x! \nxxo oox ooo \n!o! oox xxx \n\nxox oxx xxo \nxxx oxx oxx \noxx ooo ooo \n\n!oo xoo xo! \nxxo oox ooo \nxox xxx xxo " } ]
1,514,041,282
3,382
Python 3
OK
TESTS
20
62
5,632,000
field = [[""]*9 for i in range(9)] z = 0 for i in range(3): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(3,6): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(6,9): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 x, y = map(int,input().split()) x2 = ((y-1) % 3) * 3 y2 = ((x-1) % 3) * 3 temp = 0 for i in range(3): for j in range(3): if field[y2+i][x2+j] == ".": field[y2+i][x2+j] = "!" temp += 1 if temp == 0: for i in range(9): for j in range(9): if field[i][j] == ".": field[i][j] = "!" for i in range(9): for j in range(9): if j % 3 == 0 and j != 0: print("",end=" ") print(field[i][j],end="") if i % 3 == 2 and i != 8: print() print()
Title: Tic-Tac-Toe Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (*x**l*,<=*y**l*) in some small field, the next move should be done in one of the cells of the small field with coordinates (*x**l*,<=*y**l*). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input Specification: First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Specification: Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Demo Input: ['... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n', 'xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n', 'o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5\n'] Demo Output: ['... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... \n\n', 'xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\n', 'o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n'] Note: In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
```python field = [[""]*9 for i in range(9)] z = 0 for i in range(3): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(3,6): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(6,9): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 x, y = map(int,input().split()) x2 = ((y-1) % 3) * 3 y2 = ((x-1) % 3) * 3 temp = 0 for i in range(3): for j in range(3): if field[y2+i][x2+j] == ".": field[y2+i][x2+j] = "!" temp += 1 if temp == 0: for i in range(9): for j in range(9): if field[i][j] == ".": field[i][j] = "!" for i in range(9): for j in range(9): if j % 3 == 0 and j != 0: print("",end=" ") print(field[i][j],end="") if i % 3 == 2 and i != 8: print() print() ```
3
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "0\n0\n0\n0" }, { "input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "output": "0\n0\n0\n0\n0" }, { "input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "output": "0\n1\n0\n0\n0\n1" }, { "input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "output": "0\n0\n0\n0\n0\n0\n1" }, { "input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3", "output": "0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5", "output": "0\n1\n0\n0\n0\n0\n0\n1\n0" }, { "input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1", "output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0" }, { "input": "1 1\n-1\n1 1", "output": "0" }, { "input": "1 1\n1\n1 1", "output": "0" } ]
1,595,170,236
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
31,948,800
n,m = map(int,input().split()) l=sum(list(map(int,input().split()))) if(l>0): a=(n-l)//2 b=n-a else: b=(n+l)//2 a=n-b for i in range(m): x,y=map(int,input().split()) if((y-x)%2==0): print(0) else: if((y-x+1)//2<=min(a,b)): print(1) else: print(0)
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the responses to Eugene's queries in the order they occur in the input. Demo Input: ['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n'] Demo Output: ['0\n1\n0\n', '0\n1\n0\n1\n0\n'] Note: none
```python n,m = map(int,input().split()) l=sum(list(map(int,input().split()))) if(l>0): a=(n-l)//2 b=n-a else: b=(n+l)//2 a=n-b for i in range(m): x,y=map(int,input().split()) if((y-x)%2==0): print(0) else: if((y-x+1)//2<=min(a,b)): print(1) else: print(0) ```
0
137
B
Permutation
PROGRAMMING
1,000
[ "greedy" ]
null
null
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Print the only number — the minimum number of changes needed to get the permutation.
[ "3\n3 1 2\n", "2\n2 2\n", "5\n5 3 3 3 1\n" ]
[ "0\n", "1\n", "2\n" ]
The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
1,000
[ { "input": "3\n3 1 2", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "2" }, { "input": "5\n6 6 6 6 6", "output": "5" }, { "input": "10\n1 1 2 2 8 8 7 7 9 9", "output": "5" }, { "input": "8\n9 8 7 6 5 4 3 2", "output": "1" }, { "input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n5000", "output": "1" }, { "input": "4\n5000 5000 5000 5000", "output": "4" }, { "input": "5\n3366 3461 4 5 4370", "output": "3" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "0" }, { "input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "output": "7" }, { "input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974", "output": "10" }, { "input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5", "output": "0" }, { "input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142", "output": "15" }, { "input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27", "output": "14" }, { "input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64", "output": "18" }, { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604", "output": "70" }, { "input": "1\n2", "output": "1" }, { "input": "2\n5000 5000", "output": "2" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3 4", "output": "2" }, { "input": "10\n1 2 3 4 5 6 7 1000 10 10", "output": "2" } ]
1,435,950,845
245
Python 3
OK
TESTS
48
124
512,000
n = int(input()) a = input().split() d = {} for i in a: t = int(i) if t in d: d[t] += 1 else: d[t] = 1 res = 0 for i in range(1, n+1): if i not in d: res += 1 print(res)
Title: Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). Input Specification: The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). Output Specification: Print the only number — the minimum number of changes needed to get the permutation. Demo Input: ['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n'] Demo Output: ['0\n', '1\n', '2\n'] Note: The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
```python n = int(input()) a = input().split() d = {} for i in a: t = int(i) if t in d: d[t] += 1 else: d[t] = 1 res = 0 for i in range(1, n+1): if i not in d: res += 1 print(res) ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,695,064,379
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
92
0
n,m=map(int,input().split()) l=[2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,49,51,53] z="NO" for i in range(len(l)): if l[i] == n and l[i+1] ==m: z="YES" print(z)
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python n,m=map(int,input().split()) l=[2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,49,51,53] z="NO" for i in range(len(l)): if l[i] == n and l[i+1] ==m: z="YES" print(z) ```
0
618
A
Slime Combining
PROGRAMMING
800
[ "implementation" ]
null
null
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value *v*, you combine them together to create a slime with value *v*<=+<=1. You would like to see what the final state of the row is after you've added all *n* slimes. Please print the values of the slimes in the row from left to right.
The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000).
Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left.
[ "1\n", "2\n", "3\n", "8\n" ]
[ "1\n", "2\n", "2 1\n", "4\n" ]
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 1. 2 1. 2 1 1. 3 1. 3 1 1. 3 2 1. 3 2 1 1. 4
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "2 1" }, { "input": "8", "output": "4" }, { "input": "100000", "output": "17 16 11 10 8 6" }, { "input": "12345", "output": "14 13 6 5 4 1" }, { "input": "32", "output": "6" }, { "input": "70958", "output": "17 13 11 9 6 4 3 2" }, { "input": "97593", "output": "17 15 14 13 12 11 9 6 5 4 1" }, { "input": "91706", "output": "17 15 14 11 10 6 5 4 2" }, { "input": "85371", "output": "17 15 12 11 9 7 6 5 4 2 1" }, { "input": "97205", "output": "17 15 14 13 12 10 9 8 6 5 3 1" }, { "input": "34768", "output": "16 11 10 9 8 7 5" }, { "input": "12705", "output": "14 13 9 8 6 1" }, { "input": "30151", "output": "15 14 13 11 9 8 7 3 2 1" }, { "input": "4974", "output": "13 10 9 7 6 4 3 2" }, { "input": "32728", "output": "15 14 13 12 11 10 9 8 7 5 4" }, { "input": "8192", "output": "14" }, { "input": "65536", "output": "17" }, { "input": "32", "output": "6" }, { "input": "256", "output": "9" }, { "input": "4096", "output": "13" }, { "input": "33301", "output": "16 10 5 3 1" }, { "input": "16725", "output": "15 9 7 5 3 1" }, { "input": "149", "output": "8 5 3 1" }, { "input": "16277", "output": "14 13 12 11 10 9 8 5 3 1" }, { "input": "99701", "output": "17 16 11 9 7 6 5 3 1" } ]
1,620,998,019
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
6,963,200
import math def Log2(x): return (math.log10(x) / math.log10(2)) def isPowerOfTwo(n): return (math.ceil(Log2(n)) == math.floor(Log2(n))) l = [] temp = [] n = int(input()) if isPowerOfTwo(n) : x = Log2(n) print(x+1) else : for i in range(n) : '''if len(l) > 1 and l[-1] == l[-2] : l[-2] += 1 l.pop() print("Begin : ",l) print("Mid : ",l) if i==0 : l.append(1) cntr += 1 else : if l[-1] == cntr : l[-1] += cntr else : l.append(1) cntr = 1 if len(l) > 1 and l[-1] == l[-2] : l[-2] += 1 l.pop() print("End : " ,l)''' l.append(1) if 2**math.ceil(Log2(n)) - 1 == n : temp = [i for i in range(1,math.ceil(Log2(n))+1)] else : if len(l)%2 != 0 : temp.append(1) temp.append(math.ceil(Log2(n))) print(temp)
Title: Slime Combining Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value *v*, you combine them together to create a slime with value *v*<=+<=1. You would like to see what the final state of the row is after you've added all *n* slimes. Please print the values of the slimes in the row from left to right. Input Specification: The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000). Output Specification: Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left. Demo Input: ['1\n', '2\n', '3\n', '8\n'] Demo Output: ['1\n', '2\n', '2 1\n', '4\n'] Note: In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 1. 2 1. 2 1 1. 3 1. 3 1 1. 3 2 1. 3 2 1 1. 4
```python import math def Log2(x): return (math.log10(x) / math.log10(2)) def isPowerOfTwo(n): return (math.ceil(Log2(n)) == math.floor(Log2(n))) l = [] temp = [] n = int(input()) if isPowerOfTwo(n) : x = Log2(n) print(x+1) else : for i in range(n) : '''if len(l) > 1 and l[-1] == l[-2] : l[-2] += 1 l.pop() print("Begin : ",l) print("Mid : ",l) if i==0 : l.append(1) cntr += 1 else : if l[-1] == cntr : l[-1] += cntr else : l.append(1) cntr = 1 if len(l) > 1 and l[-1] == l[-2] : l[-2] += 1 l.pop() print("End : " ,l)''' l.append(1) if 2**math.ceil(Log2(n)) - 1 == n : temp = [i for i in range(1,math.ceil(Log2(n))+1)] else : if len(l)%2 != 0 : temp.append(1) temp.append(math.ceil(Log2(n))) print(temp) ```
0
760
A
Petr and a calendar
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
[ "1 7\n", "1 1\n", "11 6\n" ]
[ "6\n", "5\n", "5\n" ]
The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
500
[ { "input": "1 7", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "2 1", "output": "4" }, { "input": "8 6", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "1 2", "output": "5" }, { "input": "1 3", "output": "5" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "6" }, { "input": "2 1", "output": "4" }, { "input": "2 2", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "2 4", "output": "5" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "3 1", "output": "5" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "5" }, { "input": "3 4", "output": "5" }, { "input": "3 5", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "3 7", "output": "6" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "5" }, { "input": "4 3", "output": "5" }, { "input": "4 4", "output": "5" }, { "input": "4 5", "output": "5" }, { "input": "4 6", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "5" }, { "input": "5 3", "output": "5" }, { "input": "5 4", "output": "5" }, { "input": "5 5", "output": "5" }, { "input": "5 6", "output": "6" }, { "input": "5 7", "output": "6" }, { "input": "6 1", "output": "5" }, { "input": "6 2", "output": "5" }, { "input": "6 3", "output": "5" }, { "input": "6 4", "output": "5" }, { "input": "6 5", "output": "5" }, { "input": "6 6", "output": "5" }, { "input": "6 7", "output": "6" }, { "input": "7 1", "output": "5" }, { "input": "7 2", "output": "5" }, { "input": "7 3", "output": "5" }, { "input": "7 4", "output": "5" }, { "input": "7 5", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "7 7", "output": "6" }, { "input": "8 1", "output": "5" }, { "input": "8 2", "output": "5" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "5" }, { "input": "8 5", "output": "5" }, { "input": "8 6", "output": "6" }, { "input": "8 7", "output": "6" }, { "input": "9 1", "output": "5" }, { "input": "9 2", "output": "5" }, { "input": "9 3", "output": "5" }, { "input": "9 4", "output": "5" }, { "input": "9 5", "output": "5" }, { "input": "9 6", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "10 1", "output": "5" }, { "input": "10 2", "output": "5" }, { "input": "10 3", "output": "5" }, { "input": "10 4", "output": "5" }, { "input": "10 5", "output": "5" }, { "input": "10 6", "output": "6" }, { "input": "10 7", "output": "6" }, { "input": "11 1", "output": "5" }, { "input": "11 2", "output": "5" }, { "input": "11 3", "output": "5" }, { "input": "11 4", "output": "5" }, { "input": "11 5", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "11 7", "output": "6" }, { "input": "12 1", "output": "5" }, { "input": "12 2", "output": "5" }, { "input": "12 3", "output": "5" }, { "input": "12 4", "output": "5" }, { "input": "12 5", "output": "5" }, { "input": "12 6", "output": "6" }, { "input": "12 7", "output": "6" }, { "input": "1 4", "output": "5" }, { "input": "1 5", "output": "5" }, { "input": "9 7", "output": "6" }, { "input": "2 6", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "2 2", "output": "5" }, { "input": "4 7", "output": "6" }, { "input": "12 6", "output": "6" }, { "input": "12 3", "output": "5" }, { "input": "3 6", "output": "6" }, { "input": "9 6", "output": "5" }, { "input": "7 6", "output": "6" }, { "input": "11 7", "output": "6" }, { "input": "6 6", "output": "5" } ]
1,564,854,886
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
a,b=map(int,input().split()) if a in range(1,8,2) or a in range(8,13,2): if b==6 or b==7: print(6) else: print(5) elif a==2: print(4) else: if b==7: print(6) else: print(5)
Title: Petr and a calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap. Input Specification: The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). Output Specification: Print single integer: the number of columns the table should have. Demo Input: ['1 7\n', '1 1\n', '11 6\n'] Demo Output: ['6\n', '5\n', '5\n'] Note: The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
```python a,b=map(int,input().split()) if a in range(1,8,2) or a in range(8,13,2): if b==6 or b==7: print(6) else: print(5) elif a==2: print(4) else: if b==7: print(6) else: print(5) ```
0
978
G
Petya's Exams
PROGRAMMING
1,700
[ "greedy", "implementation", "sortings" ]
null
null
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: - $s_i$ — the day, when questions for the $i$-th exam will be published, - $d_i$ — the day of the $i$-th exam ($s_i &lt; d_i$), - $c_i$ — number of days Petya needs to prepare for the $i$-th exam. For the $i$-th exam Petya should prepare in days between $s_i$ and $d_i-1$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $i$-th exam in day $j$, then $s_i \le j &lt; d_i$. It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days. Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible.
The first line contains two integers $n$ and $m$ $(2 \le n \le 100, 1 \le m \le n)$ — the number of days and the number of exams. Each of the following $m$ lines contains three integers $s_i$, $d_i$, $c_i$ $(1 \le s_i &lt; d_i \le n, 1 \le c_i \le n)$ — the day, when questions for the $i$-th exam will be given, the day of the $i$-th exam, number of days Petya needs to prepare for the $i$-th exam. Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given.
If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $n$ integers, where the $j$-th number is: - $(m + 1)$, if the $j$-th day is a day of some exam (recall that in each day no more than one exam is conducted), - zero, if in the $j$-th day Petya will have a rest, - $i$ ($1 \le i \le m$), if Petya will prepare for the $i$-th exam in the day $j$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $1$.If there are multiple schedules, print any of them.
[ "5 2\n1 3 1\n1 5 1\n", "3 2\n1 3 1\n1 2 1\n", "10 3\n4 7 2\n1 10 3\n8 9 1\n" ]
[ "1 2 3 0 3 \n", "-1\n", "2 2 2 1 1 0 4 3 4 4 \n" ]
In the first example Petya can, for example, prepare for exam $1$ in the first day, prepare for exam $2$ in the second day, pass exam $1$ in the third day, relax in the fourth day, and pass exam $2$ in the fifth day. So, he can prepare and pass all exams. In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.
0
[ { "input": "5 2\n1 3 1\n1 5 1", "output": "1 2 3 0 3 " }, { "input": "3 2\n1 3 1\n1 2 1", "output": "-1" }, { "input": "10 3\n4 7 2\n1 10 3\n8 9 1", "output": "2 2 2 1 1 0 4 3 4 4 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 2", "output": "-1" }, { "input": "3 1\n1 3 2", "output": "1 1 2 " }, { "input": "100 1\n1 100 99", "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 2 " }, { "input": "100 1\n1 100 100", "output": "-1" }, { "input": "100 1\n1 100 98", "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 0 2 " }, { "input": "100 2\n1 100 49\n1 99 49", "output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 " }, { "input": "10 2\n3 7 4\n6 10 1", "output": "0 0 1 1 1 1 3 2 0 3 " }, { "input": "10 4\n2 5 1\n1 4 2\n4 7 1\n7 10 2", "output": "2 2 1 5 5 3 5 4 4 5 " }, { "input": "20 5\n6 16 3\n4 14 4\n3 13 1\n1 11 1\n10 20 4", "output": "4 0 3 2 2 2 2 1 1 1 6 5 6 6 5 6 5 5 0 6 " }, { "input": "30 7\n1 4 1\n22 25 1\n25 28 2\n9 12 1\n13 16 1\n11 14 1\n14 17 1", "output": "1 0 0 8 0 0 0 0 4 0 6 8 5 8 7 8 8 0 0 0 0 2 0 0 8 3 3 8 0 0 " }, { "input": "50 14\n42 44 2\n38 40 1\n6 8 2\n37 39 1\n33 35 1\n17 19 2\n12 14 2\n2 4 1\n9 11 2\n1 3 1\n32 34 1\n24 26 1\n44 46 1\n48 50 1", "output": "10 8 15 15 0 3 3 15 9 9 15 7 7 15 0 0 6 6 15 0 0 0 0 12 0 15 0 0 0 0 0 11 5 15 15 0 4 2 15 15 0 1 1 15 13 15 0 14 0 15 " }, { "input": "50 7\n45 50 4\n26 31 5\n35 40 3\n38 43 1\n39 44 3\n3 8 2\n1 6 1", "output": "7 0 6 6 0 8 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 8 0 0 0 3 3 3 4 5 8 5 5 8 8 1 1 1 1 0 8 " }, { "input": "50 15\n41 46 5\n35 40 5\n27 32 3\n10 15 2\n1 6 3\n20 25 1\n11 16 1\n9 14 1\n13 18 2\n18 23 3\n2 7 2\n25 30 1\n29 34 1\n43 48 1\n45 50 1", "output": "5 5 5 11 11 16 16 0 8 4 4 7 9 16 16 16 9 16 10 10 10 6 16 0 16 12 3 3 3 16 13 16 0 16 2 2 2 2 2 16 1 1 1 1 1 16 14 16 15 16 " }, { "input": "90 30\n1 5 1\n57 61 3\n13 17 1\n60 64 1\n73 77 2\n5 9 2\n16 20 3\n29 33 4\n83 87 3\n63 67 2\n35 39 4\n18 22 1\n42 46 4\n46 50 2\n48 52 2\n23 27 1\n82 86 1\n77 81 3\n67 71 2\n22 26 2\n37 41 1\n6 10 1\n50 54 1\n8 12 1\n86 90 1\n68 72 1\n11 15 1\n72 76 1\n62 66 1\n52 56 1", "output": "1 0 0 0 31 6 6 22 31 31 24 31 27 3 31 7 31 7 7 31 12 31 20 20 16 31 31 0 8 8 8 8 31 0 11 11 11 11 31 21 31 13 13 13 13 31 14 14 15 31 15 31 23 31 30 31 2 2 2 4 31 29 10 31 10 31 31 19 19 26 31 31 28 5 5 31 31 18 18 18 31 17 9 9 9 31 31 25 0 31 " }, { "input": "100 38\n41 43 1\n53 55 2\n91 93 2\n47 49 2\n77 79 2\n5 7 2\n2 4 2\n28 30 1\n79 81 1\n42 44 1\n27 29 1\n95 97 2\n58 60 1\n57 59 1\n61 63 2\n33 35 2\n22 24 1\n44 46 1\n10 12 2\n13 15 1\n97 99 1\n37 39 2\n18 20 1\n50 52 2\n21 23 1\n68 70 2\n83 85 1\n71 73 2\n65 67 1\n64 66 1\n15 17 1\n7 9 1\n88 90 2\n30 32 1\n74 76 1\n24 26 1\n85 87 1\n82 84 1", "output": "0 7 7 39 6 6 39 32 39 19 19 39 20 0 39 31 39 23 0 39 25 17 39 39 36 39 11 8 39 39 34 39 16 16 39 0 22 22 39 0 1 10 39 39 18 39 4 4 39 24 24 39 2 2 39 0 14 13 39 39 15 15 39 30 29 39 39 26 26 39 28 28 39 35 0 39 5 5 39 9 39 38 27 39 39 37 39 33 33 39 3 3 39 0 12 12 39 21 39 0 " }, { "input": "100 43\n76 77 1\n24 25 1\n2 3 1\n85 86 1\n49 50 1\n15 16 1\n30 31 1\n78 79 1\n54 55 1\n58 59 1\n17 18 1\n67 68 1\n21 22 1\n80 81 1\n35 36 1\n8 9 1\n83 84 1\n44 45 1\n62 63 1\n64 65 1\n72 73 1\n27 28 1\n56 57 1\n12 13 1\n40 41 1\n32 33 1\n52 53 1\n70 71 1\n97 98 1\n37 38 1\n87 88 1\n46 47 1\n89 90 1\n4 5 1\n94 95 1\n60 61 1\n99 100 1\n10 11 1\n74 75 1\n6 7 1\n91 92 1\n19 20 1\n42 43 1", "output": "0 3 44 34 44 40 44 16 44 38 44 24 44 0 6 44 11 44 42 44 13 44 0 2 44 0 22 44 0 7 44 26 44 0 15 44 30 44 0 25 44 43 44 18 44 32 44 0 5 44 0 27 44 9 44 23 44 10 44 36 44 19 44 20 44 0 12 44 0 28 44 21 44 39 44 1 44 8 44 14 44 0 17 44 4 44 31 44 33 44 41 44 0 35 44 0 29 44 37 44 " }, { "input": "100 35\n52 55 1\n55 58 1\n69 72 1\n32 35 1\n9 12 3\n68 71 1\n78 81 3\n51 54 1\n56 59 1\n63 66 3\n4 7 2\n12 15 2\n74 77 1\n87 90 3\n72 75 1\n93 96 2\n39 42 2\n15 18 1\n92 95 1\n23 26 3\n83 86 2\n28 31 2\n58 61 1\n47 50 1\n46 49 2\n31 34 1\n82 85 1\n96 99 2\n38 41 1\n41 44 1\n5 8 1\n34 37 1\n19 22 3\n27 30 1\n67 70 1", "output": "0 0 0 11 11 31 36 36 5 5 5 36 12 12 36 18 0 36 33 33 33 36 20 20 20 36 34 22 22 36 36 26 4 36 36 32 36 29 17 17 36 36 30 36 0 25 25 24 36 36 8 1 0 36 36 2 9 36 36 23 36 0 10 10 10 36 35 6 3 36 36 36 15 13 36 0 36 7 7 7 36 27 21 21 36 36 14 14 14 36 0 19 16 16 36 36 28 28 36 0 " }, { "input": "100 4\n73 83 4\n79 89 8\n12 22 6\n23 33 9", "output": "0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 5 4 4 4 4 4 4 4 4 4 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 2 2 2 2 5 2 2 2 2 0 5 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "100 2\n39 43 1\n82 86 3", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "100 36\n2 5 2\n35 38 1\n55 58 2\n40 43 3\n73 76 2\n30 33 3\n87 90 3\n93 96 1\n97 100 1\n42 45 1\n44 47 1\n66 69 3\n95 98 1\n12 15 3\n47 50 1\n72 75 1\n57 60 2\n1 4 1\n8 11 3\n15 18 1\n22 25 2\n76 79 2\n82 85 1\n91 94 2\n83 86 2\n33 36 1\n62 65 3\n26 29 3\n18 21 1\n36 39 1\n68 71 1\n50 53 1\n51 54 1\n4 7 1\n17 20 1\n78 81 1", "output": "18 1 1 37 37 34 37 19 19 19 37 14 14 14 37 20 35 37 29 37 37 21 21 0 37 28 28 28 37 6 6 6 37 26 2 37 30 37 37 4 4 4 37 10 37 11 37 15 0 37 32 33 37 37 3 3 17 37 17 37 0 27 27 27 37 12 12 12 37 31 37 16 5 5 37 37 22 22 37 36 37 23 25 25 37 37 7 7 7 37 24 24 8 37 13 37 9 37 0 37 " }, { "input": "100 37\n49 51 2\n79 81 2\n46 48 2\n71 73 2\n31 33 2\n42 44 1\n17 19 2\n64 66 2\n24 26 1\n8 10 2\n38 40 1\n1 3 2\n75 77 2\n52 54 2\n11 13 2\n87 89 1\n98 100 2\n60 62 1\n56 58 2\n39 41 1\n92 94 1\n13 15 1\n67 69 2\n4 6 2\n19 21 1\n91 93 1\n86 88 1\n43 45 1\n25 27 1\n94 96 1\n81 83 1\n35 37 1\n34 36 1\n61 63 1\n21 23 1\n83 85 1\n27 29 1", "output": "12 12 38 24 24 38 0 10 10 38 15 15 38 22 38 0 7 7 38 25 38 35 38 9 29 38 38 37 38 0 5 5 38 33 32 38 38 11 20 38 38 6 28 38 38 3 3 38 1 1 38 14 14 38 0 19 19 38 0 18 34 38 38 8 8 38 23 23 38 0 4 4 38 0 13 13 38 0 2 2 38 31 38 36 38 27 16 38 38 0 26 21 38 38 30 38 0 17 17 38 " }, { "input": "50 16\n42 44 2\n18 20 2\n10 12 1\n9 11 2\n25 27 1\n45 47 1\n12 14 1\n29 31 2\n4 6 1\n46 48 1\n32 34 2\n34 36 1\n48 50 1\n21 23 1\n15 17 2\n24 26 1", "output": "-1" }, { "input": "90 29\n1 5 1\n56 60 2\n31 35 4\n86 90 2\n25 29 4\n58 62 2\n73 77 2\n12 16 2\n65 69 1\n16 20 3\n42 46 4\n62 66 2\n2 6 2\n77 81 1\n80 84 1\n48 52 4\n81 85 2\n68 72 1\n57 61 1\n75 79 1\n35 39 2\n37 41 1\n18 22 1\n4 8 2\n67 71 1\n85 89 1\n20 24 1\n10 14 2\n51 55 2", "output": "-1" }, { "input": "100 6\n3 43 40\n46 86 24\n38 78 5\n51 91 8\n59 99 12\n60 100 2", "output": "0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 7 4 4 4 5 5 5 5 7 5 5 5 5 7 5 5 5 5 6 6 0 7 7 " }, { "input": "100 36\n2 5 2\n35 38 1\n55 58 2\n40 43 3\n73 76 2\n30 33 3\n87 90 3\n93 96 1\n97 100 1\n42 45 1\n44 47 1\n66 69 3\n95 98 1\n12 15 3\n47 50 1\n72 75 1\n57 60 2\n1 4 1\n8 11 3\n15 18 1\n22 25 2\n76 79 2\n82 85 1\n91 94 2\n83 86 2\n33 36 1\n62 65 3\n26 29 3\n18 21 1\n36 39 1\n68 71 1\n50 53 2\n51 54 1\n4 7 1\n17 20 1\n78 81 1", "output": "-1" }, { "input": "100 37\n49 51 2\n79 81 2\n46 48 2\n71 73 2\n31 33 3\n42 44 1\n17 19 2\n64 66 2\n24 26 1\n8 10 2\n38 40 1\n1 3 2\n75 77 2\n52 54 2\n11 13 2\n87 89 1\n98 100 2\n60 62 1\n56 58 2\n39 41 1\n92 94 1\n13 15 1\n67 69 2\n4 6 2\n19 21 1\n91 93 1\n86 88 1\n43 45 1\n25 27 1\n94 96 1\n81 83 1\n35 37 1\n34 36 1\n61 63 1\n21 23 1\n83 85 1\n27 29 1", "output": "-1" }, { "input": "90 30\n1 5 1\n57 61 3\n13 17 1\n60 64 1\n73 77 2\n5 9 2\n16 20 3\n29 33 5\n83 87 3\n63 67 2\n35 39 4\n18 22 1\n42 46 4\n46 50 2\n48 52 2\n23 27 1\n82 86 1\n77 81 3\n67 71 2\n22 26 2\n37 41 1\n6 10 1\n50 54 1\n8 12 1\n86 90 1\n68 72 1\n11 15 1\n72 76 1\n62 66 1\n52 56 1", "output": "-1" }, { "input": "100 38\n41 43 1\n53 55 2\n91 93 2\n47 49 2\n77 79 2\n5 7 2\n2 4 2\n28 30 1\n79 81 1\n42 44 1\n27 29 1\n95 97 2\n58 60 1\n57 59 1\n61 63 2\n33 35 2\n22 24 1\n44 46 1\n10 12 2\n13 15 1\n97 99 1\n37 39 3\n18 20 1\n50 52 2\n21 23 1\n68 70 2\n83 85 1\n71 73 2\n65 67 1\n64 66 1\n15 17 1\n7 9 1\n88 90 2\n30 32 1\n74 76 1\n24 26 1\n85 87 1\n82 84 1", "output": "-1" }, { "input": "100 43\n76 77 1\n24 25 1\n2 3 1\n85 86 1\n49 50 1\n15 16 1\n30 31 1\n78 79 2\n54 55 1\n58 59 1\n17 18 1\n67 68 1\n21 22 1\n80 81 1\n35 36 1\n8 9 1\n83 84 1\n44 45 1\n62 63 1\n64 65 1\n72 73 1\n27 28 1\n56 57 1\n12 13 1\n40 41 1\n32 33 1\n52 53 1\n70 71 1\n97 98 1\n37 38 1\n87 88 1\n46 47 1\n89 90 1\n4 5 1\n94 95 1\n60 61 1\n99 100 1\n10 11 1\n74 75 1\n6 7 1\n91 92 1\n19 20 1\n42 43 1", "output": "-1" }, { "input": "100 35\n52 55 1\n55 58 1\n69 72 1\n32 35 1\n9 12 3\n68 71 1\n78 81 3\n51 54 1\n56 59 1\n63 66 3\n4 7 2\n12 15 2\n74 77 1\n87 90 3\n72 75 1\n93 96 2\n39 42 2\n15 18 1\n92 95 1\n23 26 4\n83 86 2\n28 31 2\n58 61 1\n47 50 1\n46 49 2\n31 34 1\n82 85 1\n96 99 2\n38 41 1\n41 44 1\n5 8 1\n34 37 1\n19 22 3\n27 30 1\n67 70 1", "output": "-1" }, { "input": "97 22\n10 17 6\n24 31 6\n79 86 7\n60 67 6\n42 49 5\n67 74 5\n34 41 4\n70 77 3\n51 58 5\n82 89 2\n89 96 5\n14 21 2\n40 47 1\n1 8 2\n23 30 1\n59 66 1\n50 57 2\n26 33 1\n15 22 2\n90 97 1\n32 39 1\n2 9 4", "output": "14 14 22 22 22 22 0 23 23 1 1 1 1 1 1 12 23 12 19 19 23 23 15 2 2 2 2 2 2 23 23 18 23 21 7 7 7 7 23 13 23 5 5 5 5 5 23 0 23 17 17 9 9 9 9 9 23 23 16 4 4 4 4 4 4 23 23 6 6 6 6 6 8 23 8 8 23 0 3 3 3 3 3 3 3 23 10 10 23 11 11 11 11 11 20 23 23 " }, { "input": "12 11\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n5 6 5\n6 7 6\n7 8 7\n8 9 8\n9 10 9\n10 11 10\n11 12 1", "output": "-1" }, { "input": "6 2\n1 6 3\n1 2 1", "output": "2 3 1 1 1 3 " }, { "input": "88 1\n1 2 1", "output": "1 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 " }, { "input": "4 2\n1 4 1\n1 2 1", "output": "2 3 1 3 " }, { "input": "100 2\n1 100 30\n1 20 1", "output": "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 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 3 " }, { "input": "88 1\n1 3 1", "output": "1 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 0 0 0 0 0 0 0 0 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": "6 2\n1 5 2\n2 3 1", "output": "1 2 3 1 3 0 " }, { "input": "7 2\n1 7 3\n2 3 1", "output": "1 2 3 1 1 0 3 " }, { "input": "8 2\n3 8 2\n4 5 1", "output": "0 0 1 2 3 1 0 3 " }, { "input": "10 2\n1 10 7\n2 3 1", "output": "1 2 3 1 1 1 1 1 1 3 " }, { "input": "5 2\n1 5 2\n2 3 1", "output": "1 2 3 1 3 " }, { "input": "10 2\n1 10 5\n2 3 1", "output": "1 2 3 1 1 1 1 0 0 3 " }, { "input": "10 2\n1 10 4\n2 4 2", "output": "1 2 2 3 1 1 1 0 0 3 " }, { "input": "10 2\n1 10 6\n3 7 1", "output": "1 1 2 1 1 1 3 1 0 3 " }, { "input": "10 3\n4 8 2\n1 10 3\n5 6 1", "output": "2 2 2 1 3 4 1 4 0 4 " }, { "input": "20 5\n4 14 4\n3 13 1\n1 11 1\n10 20 4\n6 16 3", "output": "3 0 2 1 1 1 1 5 5 5 6 4 6 6 4 6 4 4 0 6 " }, { "input": "73 2\n33 35 2\n12 63 44", "output": "0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 " }, { "input": "86 5\n66 74 1\n29 33 3\n13 78 38\n20 34 2\n72 85 1", "output": "0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 4 4 3 3 3 3 3 3 3 2 2 2 3 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0 1 0 0 0 0 0 5 0 6 0 0 0 6 0 0 0 0 0 0 6 0 " }, { "input": "9 4\n3 7 1\n6 9 1\n2 3 1\n1 8 2", "output": "4 3 5 1 4 2 5 5 5 " }, { "input": "10 2\n1 10 5\n2 4 1", "output": "1 2 1 3 1 1 1 0 0 3 " }, { "input": "10 4\n1 10 2\n1 4 2\n2 5 1\n7 8 1", "output": "2 2 3 5 5 1 4 5 1 5 " }, { "input": "10 2\n1 10 7\n3 7 1", "output": "1 1 2 1 1 1 3 1 1 3 " }, { "input": "96 37\n9 43 23\n60 66 4\n7 15 1\n3 86 4\n30 65 14\n36 38 1\n28 36 8\n68 80 4\n7 22 5\n17 68 1\n7 18 1\n12 47 2\n4 6 2\n5 11 3\n41 55 10\n7 45 22\n6 67 16\n12 50 18\n64 70 2\n21 48 26\n2 17 6\n14 44 10\n63 84 18\n14 19 5\n34 92 56\n51 56 2\n13 20 5\n62 74 2\n1 3 1\n6 46 17\n58 62 4\n10 27 16\n13 37 16\n21 23 1\n48 69 13\n67 82 13\n17 51 18", "output": "-1" }, { "input": "31 3\n2 3 1\n1 12 4\n13 15 1", "output": "2 1 4 2 2 2 0 0 0 0 0 4 3 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "7 2\n2 6 4\n3 4 1", "output": "-1" }, { "input": "20 2\n3 4 1\n2 7 3", "output": "0 2 1 3 2 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "100 5\n15 53 23\n16 85 32\n59 93 3\n54 57 1\n13 40 11", "output": "0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 2 2 2 2 2 6 4 2 2 6 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 6 3 0 0 0 0 0 0 6 0 0 0 0 0 0 0 " }, { "input": "100 5\n24 57 8\n28 72 15\n20 75 49\n27 67 7\n68 100 21", "output": "-1" }, { "input": "11 2\n1 11 5\n4 8 4", "output": "1 1 1 2 2 2 2 3 1 1 3 " }, { "input": "29 5\n5 10 3\n15 22 2\n18 27 4\n16 20 4\n7 11 1", "output": "0 0 0 0 1 1 1 5 0 6 6 0 0 0 2 4 4 4 4 6 2 6 3 3 3 3 6 0 0 " }, { "input": "28 4\n4 23 11\n11 12 1\n2 4 1\n16 24 1", "output": "0 3 0 5 1 1 1 1 1 1 2 5 1 1 1 1 1 4 0 0 0 0 5 5 0 0 0 0 " }, { "input": "90 8\n7 10 2\n27 28 1\n18 20 2\n12 48 2\n37 84 27\n29 32 2\n37 73 16\n3 40 14", "output": "0 0 8 8 8 8 1 1 8 9 8 8 8 8 8 8 8 3 3 9 8 8 4 4 0 0 2 9 6 6 0 9 0 0 0 0 7 7 7 9 7 7 7 7 7 7 7 9 7 7 7 7 7 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 9 5 5 5 5 5 5 5 5 5 0 9 0 0 0 0 0 0 " }, { "input": "61 2\n12 41 24\n20 29 2", "output": "0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "27 8\n7 22 2\n3 5 1\n24 26 1\n1 14 1\n4 23 8\n10 12 1\n16 18 1\n5 6 1", "output": "-1" }, { "input": "88 8\n1 5 2\n29 50 7\n36 42 6\n72 81 2\n12 19 4\n65 73 2\n15 80 29\n4 43 16", "output": "1 1 0 8 9 8 8 8 8 8 8 5 5 5 5 8 8 8 9 8 8 8 8 8 8 7 7 7 2 2 2 2 2 2 2 3 3 3 3 3 3 9 9 7 7 7 7 7 7 9 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 7 7 7 7 7 7 9 4 4 0 0 0 0 9 9 0 0 0 0 0 0 0 " }, { "input": "34 17\n1 2 1\n6 12 4\n22 23 1\n5 6 1\n8 30 9\n2 7 2\n22 26 3\n3 34 31\n1 19 9\n4 11 7\n2 5 1\n4 9 3\n8 14 4\n2 22 14\n3 8 5\n32 33 1\n18 31 10", "output": "-1" }, { "input": "9 2\n3 7 2\n1 9 5", "output": "2 2 1 1 2 2 3 2 3 " }, { "input": "85 6\n4 63 17\n1 47 2\n25 26 1\n1 8 1\n24 78 44\n39 79 4", "output": "4 2 2 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 5 3 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 5 5 5 5 5 5 5 5 6 6 6 6 0 0 7 7 0 0 0 0 0 0 " }, { "input": "85 5\n3 44 9\n77 85 7\n3 27 8\n5 42 4\n4 7 1", "output": "0 0 3 5 3 3 6 3 3 3 3 3 4 4 4 4 1 1 1 1 1 1 1 1 1 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 0 6 " }, { "input": "50 5\n7 23 7\n4 12 4\n7 46 14\n15 32 8\n16 24 2", "output": "0 0 0 2 2 2 2 1 1 1 1 6 1 1 1 5 5 4 4 4 4 4 6 6 4 4 4 3 3 3 3 6 3 3 3 3 3 3 3 3 3 3 0 0 0 6 0 0 0 0 " }, { "input": "6 3\n1 5 1\n1 6 1\n1 2 1", "output": "3 4 1 2 4 4 " }, { "input": "100 3\n17 21 3\n1 66 38\n8 22 2", "output": "2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 1 1 1 2 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " } ]
1,677,645,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n, m = map(int, input().split()) # создаем список экзаменов exams = [] for i in range(m): s, d, c = map(int, input().split()) exams.append((s, d, c, i + 1)) # добавляем номер экзамена # сортируем экзамены по дню начала подготовки exams.sort(key=lambda x: x[0]) # создаем список расписания и список занятых дней schedule = [0] * n used = set() for s, d, c, i in exams: day = s while day < d: if day not in used: schedule[day - 1] = i used.update(range(day, min(day + c, d))) break day += 1 else: print(-1) exit() # заполняем оставшиеся дни отдыхом for i in range(n): if schedule[i] == 0: schedule[i] = m + 1 print(*schedule)
Title: Petya's Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: - $s_i$ — the day, when questions for the $i$-th exam will be published, - $d_i$ — the day of the $i$-th exam ($s_i &lt; d_i$), - $c_i$ — number of days Petya needs to prepare for the $i$-th exam. For the $i$-th exam Petya should prepare in days between $s_i$ and $d_i-1$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $i$-th exam in day $j$, then $s_i \le j &lt; d_i$. It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days. Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible. Input Specification: The first line contains two integers $n$ and $m$ $(2 \le n \le 100, 1 \le m \le n)$ — the number of days and the number of exams. Each of the following $m$ lines contains three integers $s_i$, $d_i$, $c_i$ $(1 \le s_i &lt; d_i \le n, 1 \le c_i \le n)$ — the day, when questions for the $i$-th exam will be given, the day of the $i$-th exam, number of days Petya needs to prepare for the $i$-th exam. Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given. Output Specification: If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $n$ integers, where the $j$-th number is: - $(m + 1)$, if the $j$-th day is a day of some exam (recall that in each day no more than one exam is conducted), - zero, if in the $j$-th day Petya will have a rest, - $i$ ($1 \le i \le m$), if Petya will prepare for the $i$-th exam in the day $j$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $1$.If there are multiple schedules, print any of them. Demo Input: ['5 2\n1 3 1\n1 5 1\n', '3 2\n1 3 1\n1 2 1\n', '10 3\n4 7 2\n1 10 3\n8 9 1\n'] Demo Output: ['1 2 3 0 3 \n', '-1\n', '2 2 2 1 1 0 4 3 4 4 \n'] Note: In the first example Petya can, for example, prepare for exam $1$ in the first day, prepare for exam $2$ in the second day, pass exam $1$ in the third day, relax in the fourth day, and pass exam $2$ in the fifth day. So, he can prepare and pass all exams. In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.
```python n, m = map(int, input().split()) # создаем список экзаменов exams = [] for i in range(m): s, d, c = map(int, input().split()) exams.append((s, d, c, i + 1)) # добавляем номер экзамена # сортируем экзамены по дню начала подготовки exams.sort(key=lambda x: x[0]) # создаем список расписания и список занятых дней schedule = [0] * n used = set() for s, d, c, i in exams: day = s while day < d: if day not in used: schedule[day - 1] = i used.update(range(day, min(day + c, d))) break day += 1 else: print(-1) exit() # заполняем оставшиеся дни отдыхом for i in range(n): if schedule[i] == 0: schedule[i] = m + 1 print(*schedule) ```
0
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,685,079,310
2,147,483,647
Python 3
OK
TESTS
31
92
0
n=int(input()) print(sum(list(map(int,input().split())))/n)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n=int(input()) print(sum(list(map(int,input().split())))/n) ```
3
713
C
Sonya and Problem Wihtout a Legend
PROGRAMMING
2,300
[ "dp", "sortings" ]
null
null
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=3000) — the length of the array. Next line contains *n* integer *a**i* (1<=≤<=*a**i*<=≤<=109).
Print the minimum number of operation required to make the array strictly increasing.
[ "7\n2 1 5 11 5 9 11\n", "5\n5 4 3 2 1\n" ]
[ "9\n", "12\n" ]
In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
2,000
[ { "input": "7\n2 1 5 11 5 9 11", "output": "9" }, { "input": "5\n5 4 3 2 1", "output": "12" }, { "input": "2\n1 1000", "output": "0" }, { "input": "2\n1000 1", "output": "1000" }, { "input": "5\n100 80 60 70 90", "output": "54" }, { "input": "10\n10 16 17 11 1213 1216 1216 1209 3061 3062", "output": "16" }, { "input": "20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158", "output": "43" }, { "input": "1\n1", "output": "0" }, { "input": "5\n1 1 1 2 3", "output": "3" }, { "input": "1\n1000", "output": "0" }, { "input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319", "output": "12423" }, { "input": "75\n392 593 98 533 515 448 220 310 386 79 539 294 208 828 75 534 875 493 94 205 656 105 546 493 60 188 222 108 788 504 809 621 934 455 307 212 630 298 938 62 850 421 839 134 950 256 934 817 209 559 866 67 990 835 534 672 468 768 757 516 959 893 275 315 692 927 321 554 801 805 885 12 67 245 495", "output": "17691" }, { "input": "10\n26 723 970 13 422 968 875 329 234 983", "output": "2546" }, { "input": "20\n245 891 363 6 193 704 420 447 237 947 664 894 512 194 513 616 671 623 686 378", "output": "3208" }, { "input": "5\n850 840 521 42 169", "output": "1485" } ]
1,583,323,835
2,147,483,647
PyPy 3
OK
TESTS
57
249
11,366,400
from bisect import bisect_left as BL n = int(input()) graph = [(-99**9, 0)] # x, slope ans = 0 for i,a in enumerate(map(int,input().split())): a-= i new = [] turnj = BL(graph, (a,99**9)) - 1 if turnj != len(graph)-1: ans+= graph[-1][0] - a # add |x-a| for j in range(turnj): x, sl = graph[j] new.append((x, sl-1)) for j in range(turnj, len(graph)): x, sl = graph[j] if j == turnj: new.append((x, sl-1)) new.append((a, sl+1)) else: new.append((x, sl+1)) # remove positive slopes graph = new while graph[-1][1] > 0: x, sl = graph.pop() if graph[-1][1] != 0: graph.append((x, 0)) print(ans)
Title: Sonya and Problem Wihtout a Legend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=3000) — the length of the array. Next line contains *n* integer *a**i* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print the minimum number of operation required to make the array strictly increasing. Demo Input: ['7\n2 1 5 11 5 9 11\n', '5\n5 4 3 2 1\n'] Demo Output: ['9\n', '12\n'] Note: In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
```python from bisect import bisect_left as BL n = int(input()) graph = [(-99**9, 0)] # x, slope ans = 0 for i,a in enumerate(map(int,input().split())): a-= i new = [] turnj = BL(graph, (a,99**9)) - 1 if turnj != len(graph)-1: ans+= graph[-1][0] - a # add |x-a| for j in range(turnj): x, sl = graph[j] new.append((x, sl-1)) for j in range(turnj, len(graph)): x, sl = graph[j] if j == turnj: new.append((x, sl-1)) new.append((a, sl+1)) else: new.append((x, sl+1)) # remove positive slopes graph = new while graph[-1][1] > 0: x, sl = graph.pop() if graph[-1][1] != 0: graph.append((x, 0)) print(ans) ```
3
276
B
Little Girl and Game
PROGRAMMING
1,300
[ "games", "greedy" ]
null
null
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
[ "aba\n", "abca\n" ]
[ "First\n", "Second\n" ]
none
1,000
[ { "input": "aba", "output": "First" }, { "input": "abca", "output": "Second" }, { "input": "aabb", "output": "First" }, { "input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo", "output": "Second" }, { "input": "gevqgtaorjixsxnbcoybr", "output": "First" }, { "input": "xvhtcbtouuddhylxhplgjxwlo", "output": "First" }, { "input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz", "output": "Second" }, { "input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt", "output": "First" }, { "input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz", "output": "First" }, { "input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq", "output": "Second" }, { "input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg", "output": "First" }, { "input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj", "output": "Second" }, { "input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm", "output": "First" }, { "input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd", "output": "First" }, { "input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh", "output": "First" }, { "input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm", "output": "Second" }, { "input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq", "output": "First" }, { "input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk", "output": "First" }, { "input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq", "output": "Second" }, { "input": "a", "output": "First" }, { "input": "ab", "output": "Second" }, { "input": "abacaba", "output": "First" }, { "input": "abazaba", "output": "First" }, { "input": "zz", "output": "First" }, { "input": "aassddxyz", "output": "First" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "Second" }, { "input": "aabc", "output": "Second" }, { "input": "abcabc", "output": "First" }, { "input": "aaabbbccdd", "output": "Second" }, { "input": "aabbcccc", "output": "First" } ]
1,653,758,426
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
import random def isPalin(string): return True if string==string[::-1] else False stri = list(input().strip()) flag=0 count=0 while True: s = "" for ele in stri: s+=ele if(isPalin(s)): break elif(len(stri)==1): break else: stri.pop(random.randint(0,len(stri)-1)) flag = count+1%2 if(flag==0): print("First") elif(flag==1): print("Second")
Title: Little Girl and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. Input Specification: The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. Output Specification: In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. Demo Input: ['aba\n', 'abca\n'] Demo Output: ['First\n', 'Second\n'] Note: none
```python import random def isPalin(string): return True if string==string[::-1] else False stri = list(input().strip()) flag=0 count=0 while True: s = "" for ele in stri: s+=ele if(isPalin(s)): break elif(len(stri)==1): break else: stri.pop(random.randint(0,len(stri)-1)) flag = count+1%2 if(flag==0): print("First") elif(flag==1): print("Second") ```
0
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", "output": "Yes" }, { "input": "+", "output": "No" }, { "input": "-+", "output": "No" }, { "input": "--", "output": "Yes" }, { "input": "+++", "output": "No" }, { "input": "--+", "output": "No" }, { "input": "++--++", "output": "Yes" }, { "input": "+-++-+", "output": "Yes" }, { "input": "+-+--+", "output": "No" }, { "input": "--++-+", "output": "No" }, { "input": "-+-+--", "output": "No" }, { "input": "+-+++-", "output": "No" }, { "input": "-+-+-+", "output": "No" }, { "input": "-++-+--++--+-++-", "output": "Yes" }, { "input": "+-----+-++---+------+++-++++", "output": "No" }, { "input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "output": "No" }, { "input": "-+-----++++--++-+-++", "output": "Yes" }, { "input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "output": "Yes" }, { "input": "-+-+-++-+-+-", "output": "Yes" }, { "input": "-+-++-+-", "output": "Yes" }, { "input": "-+-++-+-+-", "output": "No" }, { "input": "++-+-+-+-+--+", "output": "No" }, { "input": "+++---", "output": "No" }, { "input": "+-+-+-+-+--+-+-+-+-++--++--+", "output": "Yes" }, { "input": "+-+-++", "output": "No" }, { "input": "-++--+--+++-+-+-+-+-", "output": "No" }, { "input": "+---+-+-", "output": "No" }, { "input": "+-+--+-+", "output": "Yes" }, { "input": "+++---+++---", "output": "No" }, { "input": "-+++++", "output": "No" }, { "input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "output": "Yes" }, { "input": "-+++--", "output": "No" }, { "input": "+---+", "output": "No" }, { "input": "-++", "output": "No" }, { "input": "-+--+-", "output": "Yes" }, { "input": "+---++--++", "output": "No" }, { "input": "+++-", "output": "No" }, { "input": "--+++", "output": "No" }, { "input": "++-+", "output": "No" } ]
1,598,372,179
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
278
716,800
x = list(input()) pos = 0 nag = 0 for i in range(1,len(x)): if(x[i-1]==x[i]): pos += 1 if(pos>0): print("Yes") else : print("No")
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python x = list(input()) pos = 0 nag = 0 for i in range(1,len(x)): if(x[i-1]==x[i]): pos += 1 if(pos>0): print("Yes") else : print("No") ```
0
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" }, { "input": "Danil_and_part_time_job", "output": "YES" }, { "input": "Ann_and_books", "output": "YES" }, { "input": "Olya", "output": "YES" }, { "input": "Nikita", "output": "YES" }, { "input": "Slava", "output": "YES" }, { "input": "Vanya", "output": "NO" }, { "input": "I_dont_know_what_to_write_here", "output": "NO" }, { "input": "danil_and_work", "output": "NO" }, { "input": "Ann", "output": "YES" }, { "input": "Batman_Nananananananan_Batman", "output": "NO" }, { "input": "Olya_Nikita_Ann_Slava_Danil", "output": "NO" }, { "input": "its_me_Mario", "output": "NO" }, { "input": "A", "output": "NO" }, { "input": "Wake_up_Neo", "output": "NO" }, { "input": "Hardest_problem_ever", "output": "NO" }, { "input": "Nikita_Nikita", "output": "NO" }, { "input": "____________________________________________________________________________________________________", "output": "NO" }, { "input": "Nikitb", "output": "NO" }, { "input": "Unn", "output": "NO" }, { "input": "oLya_adn_smth", "output": "NO" }, { "input": "FloorISLava", "output": "NO" }, { "input": "ann", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "AAnnnnn", "output": "YES" }, { "input": "AnnAnn", "output": "NO" }, { "input": "Annn", "output": "YES" }, { "input": "Dilzhan", "output": "NO" }, { "input": "Danilaaa", "output": "YES" }, { "input": "AndAnn", "output": "YES" }, { "input": "OlyaAnnAnn", "output": "NO" }, { "input": "DanilDanilOlya", "output": "NO" }, { "input": "DDanil", "output": "YES" }, { "input": "AnnAnnDanil", "output": "NO" }, { "input": "And_Danil", "output": "YES" }, { "input": "abcddddDanil", "output": "YES" }, { "input": "DanilOlyaOlya", "output": "NO" }, { "input": "Nikitaaa", "output": "YES" }, { "input": "aaabbba", "output": "NO" }, { "input": "Ann_Ann_Danil", "output": "NO" }, { "input": "Danil_Danil_Nikita", "output": "NO" }, { "input": "AlexaaaaaaBBBBBOlyaDDDDD", "output": "YES" }, { "input": "IloveDaniland", "output": "YES" }, { "input": "AnAnn", "output": "YES" }, { "input": "Danil_Danil_Olya", "output": "NO" }, { "input": "DanilDanilSlava", "output": "NO" }, { "input": "DanilDanil", "output": "NO" }, { "input": "OlyOlya", "output": "YES" }, { "input": "NikitaNikitb", "output": "YES" }, { "input": "ababaca", "output": "NO" }, { "input": "AnnNikitaNikitaNikitaNikita__good_luck", "output": "NO" } ]
1,684,211,447
2,147,483,647
Python 3
OK
TESTS
55
62
921,600
import re str = 'Danil|Olya|Slava|Ann|Nikita' if (len(re.findall(str, input())) == 1): print('YES') else: print('NO')
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input Specification: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Output Specification: Print "YES", if problem is from this contest, and "NO" otherwise. Demo Input: ['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n'] Demo Output: ['NO', 'YES', 'NO'] Note: none
```python import re str = 'Danil|Olya|Slava|Ann|Nikita' if (len(re.findall(str, input())) == 1): print('YES') else: print('NO') ```
3
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", "output": "9" }, { "input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2", "output": "5" }, { "input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352", "output": "0" }, { "input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5", "output": "0" }, { "input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "0" }, { "input": "1 1 1\n1 1", "output": "0" }, { "input": "10 10 4\n5 9\n6 9\n6 10\n5 10", "output": "4" }, { "input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000", "output": "4" }, { "input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2", "output": "5" }, { "input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000", "output": "4" } ]
1,671,072,823
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
# -*- coding: utf-8 -*- """ Created on Thu Dec 15 10:26:22 2022 @author: thinkpad """ n,m,k = map(int,input().split()) res = [[0 for _ in range(m+2)] for _ in range(n+2)] dir1 = [[-1,-1],[-1,0],[0,-1]] dir2 = [[-1,0],[-1,1],[0,1]] dir3 = [[0,-1],[1,-1],[1,0]] dir4 = [[0,1],[1,1],[1,0]] def check(i,j): al1 = 0 for d in dir1: x,y = d[0],d[1] if res[i+x][j+y]==1: al1+=1 if al1 == 3: return False al2 = 0 for d in dir2: x,y = d[0],d[1] if res[i+x][j+y]==1: al2+=1 if al2 == 3: return False al3 = 0 for d in dir3: x,y = d[0],d[1] if res[i+x][j+y]==1: al3+=1 if al3 == 3: return False al4 = 0 for d in dir4: x,y = d[0],d[1] if res[i+x][j+y]==1: al4+=1 if al4 == 3: return False return True paint = [] for _ in range(k): paint.append(map(int,input().split())) flag = True for t in range(k): i,j =paint[t][0],paint[t][1] res[i][j]=1 if check(i,j)==False: print(t+1) flag = False else: continue if flag == True: print(0)
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. Input Specification: The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. Output Specification: If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. Demo Input: ['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n'] Demo Output: ['4\n', '5\n', '0\n'] Note: none
```python # -*- coding: utf-8 -*- """ Created on Thu Dec 15 10:26:22 2022 @author: thinkpad """ n,m,k = map(int,input().split()) res = [[0 for _ in range(m+2)] for _ in range(n+2)] dir1 = [[-1,-1],[-1,0],[0,-1]] dir2 = [[-1,0],[-1,1],[0,1]] dir3 = [[0,-1],[1,-1],[1,0]] dir4 = [[0,1],[1,1],[1,0]] def check(i,j): al1 = 0 for d in dir1: x,y = d[0],d[1] if res[i+x][j+y]==1: al1+=1 if al1 == 3: return False al2 = 0 for d in dir2: x,y = d[0],d[1] if res[i+x][j+y]==1: al2+=1 if al2 == 3: return False al3 = 0 for d in dir3: x,y = d[0],d[1] if res[i+x][j+y]==1: al3+=1 if al3 == 3: return False al4 = 0 for d in dir4: x,y = d[0],d[1] if res[i+x][j+y]==1: al4+=1 if al4 == 3: return False return True paint = [] for _ in range(k): paint.append(map(int,input().split())) flag = True for t in range(k): i,j =paint[t][0],paint[t][1] res[i][j]=1 if check(i,j)==False: print(t+1) flag = False else: continue if flag == True: print(0) ```
-1
0
none
none
none
0
[ "none" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
0
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,482,657,384
684
Python 3
OK
TESTS
46
77
4,608,000
ins = list(map(int, input().split())) n = ins[0] m = ins[1] k = ins[2] koln = 1 kolm = 1 while k > 2*m: k -= 2*m koln+=1 while k > 2: k-=2 kolm += 1 if k == 1: print(koln,kolm,"L") else: print(koln, kolm, "R")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python ins = list(map(int, input().split())) n = ins[0] m = ins[1] k = ins[2] koln = 1 kolm = 1 while k > 2*m: k -= 2*m koln+=1 while k > 2: k-=2 kolm += 1 if k == 1: print(koln,kolm,"L") else: print(koln, kolm, "R") ```
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100000", "output": "50000\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7", "output": "3\n2 2 3" }, { "input": "4", "output": "2\n2 2" }, { "input": "8", "output": "4\n2 2 2 2" }, { "input": "9", "output": "4\n2 2 2 3" }, { "input": "99995", "output": "49997\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99996", "output": "49998\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "10", "output": "5\n2 2 2 2 2" }, { "input": "11", "output": "5\n2 2 2 2 3" }, { "input": "99997", "output": "49998\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99998", "output": "49999\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "12", "output": "6\n2 2 2 2 2 2" }, { "input": "13", "output": "6\n2 2 2 2 2 3" }, { "input": "99993", "output": "49996\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99994", "output": "49997\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14", "output": "7\n2 2 2 2 2 2 2" }, { "input": "15", "output": "7\n2 2 2 2 2 2 3" }, { "input": "53", "output": "26\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 3" }, { "input": "57", "output": "28\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 3" }, { "input": "61", "output": "30\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 3" }, { "input": "774", "output": "387\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "202", "output": "101\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 2" }, { "input": "530", "output": "265\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7166", "output": "3583\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "9294", "output": "4647\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "2422", "output": "1211\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "15326", "output": "7663\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "11454", "output": "5727\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14878", "output": "7439\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90672", "output": "45336\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99544", "output": "49772\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90472", "output": "45236\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "23", "output": "11\n2 2 2 2 2 2 2 2 2 2 3" }, { "input": "93", "output": "46\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 3" }, { "input": "19", "output": "9\n2 2 2 2 2 2 2 2 3" }, { "input": "11110", "output": "5555\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." } ]
1,696,413,180
2,147,483,647
Python 3
OK
TESTS
41
77
1,024,000
a = int(input()) print(a // 2) b = [2] * (a // 2) if a % 2 == 0: print(*b) else: b[-1] = 3 print(*b)
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. Input Specification: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). Output Specification: The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. Demo Input: ['5\n', '6\n'] Demo Output: ['2\n2 3\n', '3\n2 2 2\n'] Note: none
```python a = int(input()) print(a // 2) b = [2] * (a // 2) if a % 2 == 0: print(*b) else: b[-1] = 3 print(*b) ```
3
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" }, { "input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430 262 71 415 586 532 562 419 615 732 658 108 315 268 574 86 12 23 429 640 995 342 305", "output": "1000" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "30\n94 93 90 94 90 91 93 91 93 94 93 90 100 94 97 94 94 95 94 96 94 98 97 95 97 91 91 95 98 96", "output": "100" }, { "input": "5\n1000000000 5 5 4 4", "output": "1000000000" }, { "input": "3\n1 2 1", "output": "2" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "4\n1 2 3 4", "output": "4" }, { "input": "3\n1000000000 1000000000 10000000", "output": "1005000000" }, { "input": "3\n677876423 834056477 553175531", "output": "1032554216" }, { "input": "5\n1000000000 1 1 1 1", "output": "1000000000" }, { "input": "4\n1000000000 1000000000 1000000000 1000000000", "output": "1333333334" }, { "input": "3\n4 10 11", "output": "13" }, { "input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1250000000" } ]
1,694,163,899
2,147,483,647
PyPy 3-64
OK
TESTS
34
216
15,872,000
from cmath import inf import math import sys from os import path #import bisect #import math from functools import reduce import collections import sys if (path.exists('CP/input.txt')): sys.stdout = open('CP/output.txt', 'w') sys.stdin = open('CP/input.txt', 'r') def ok(mid,arr,maxi): d = 0 for x in arr: d += (mid - x) #print(d) if(d>=mid): return True return False def answer(): n = int(input()) arr = list(map(int,input().split())) l,r = 0,(2**31 - 1) for x in arr: l = max(l,x) maxi = l ans=-1 while(l<=r): #print(l," ",r) mid = (l+r)//2 #print(mid) if(ok(mid,arr,maxi)): ans = mid r=mid-1 else: l=mid+1 print(ans) #t = int(input()) t=1 for _ in range(t): answer()
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. Output Specification: In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\n3 2 2\n', '4\n2 2 2 2\n'] Demo Output: ['4\n', '3\n'] Note: You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
```python from cmath import inf import math import sys from os import path #import bisect #import math from functools import reduce import collections import sys if (path.exists('CP/input.txt')): sys.stdout = open('CP/output.txt', 'w') sys.stdin = open('CP/input.txt', 'r') def ok(mid,arr,maxi): d = 0 for x in arr: d += (mid - x) #print(d) if(d>=mid): return True return False def answer(): n = int(input()) arr = list(map(int,input().split())) l,r = 0,(2**31 - 1) for x in arr: l = max(l,x) maxi = l ans=-1 while(l<=r): #print(l," ",r) mid = (l+r)//2 #print(mid) if(ok(mid,arr,maxi)): ans = mid r=mid-1 else: l=mid+1 print(ans) #t = int(input()) t=1 for _ in range(t): answer() ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481 554 1000 821", "output": "15" }, { "input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396", "output": "144" }, { "input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366", "output": "145" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n2", "output": "2" }, { "input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19", "output": "63" }, { "input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386", "output": "31" }, { "input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518", "output": "75" }, { "input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397", "output": "41" }, { "input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118", "output": "116" } ]
1,691,168,574
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,h=map(int, input().split()) a= list(map(int, input().strip().split())) [:n] c=0 for i in a: if(i>h): c+=2 else: c+=1 print(c)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? Input Specification: The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. Output Specification: Print a single integer — the minimum possible valid width of the road. Demo Input: ['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n'] Demo Output: ['4\n', '6\n', '11\n'] Note: In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
```python n,h=map(int, input().split()) a= list(map(int, input().strip().split())) [:n] c=0 for i in a: if(i>h): c+=2 else: c+=1 print(c) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,663,185,732
2,147,483,647
PyPy 3-64
OK
TESTS
44
62
0
wheel = input() counter = 0 pointer = 'a' for c in wheel: distance = abs(ord(pointer) - ord(c)) if distance < 13: counter += distance else: counter += (26 - distance) pointer = c print(counter)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python wheel = input() counter = 0 pointer = 'a' for c in wheel: distance = abs(ord(pointer) - ord(c)) if distance < 13: counter += distance else: counter += (26 - distance) pointer = c print(counter) ```
3
628
A
Tennis Tournament
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement.
Print two integers *x* and *y* — the number of bottles and towels need for the tournament.
[ "5 2 3\n", "8 2 4\n" ]
[ "20 15\n", "35 32\n" ]
In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
0
[ { "input": "5 2 3", "output": "20 15" }, { "input": "8 2 4", "output": "35 32" }, { "input": "10 1 500", "output": "27 5000" }, { "input": "20 500 1", "output": "19019 20" }, { "input": "100 123 99", "output": "24453 9900" }, { "input": "500 1 1", "output": "1497 500" }, { "input": "500 500 500", "output": "499499 250000" }, { "input": "500 237 474", "output": "237025 237000" }, { "input": "1 2 3", "output": "0 3" }, { "input": "1 2 133", "output": "0 133" }, { "input": "1 2 100", "output": "0 100" }, { "input": "1 3 4", "output": "0 4" }, { "input": "1 10 15", "output": "0 15" }, { "input": "1 1 1", "output": "0 1" }, { "input": "1 2 5", "output": "0 5" }, { "input": "1 500 500", "output": "0 500" }, { "input": "1 3 8", "output": "0 8" }, { "input": "10 10 10", "output": "189 100" }, { "input": "1 3 5", "output": "0 5" }, { "input": "1 2 1", "output": "0 1" }, { "input": "1 2 4", "output": "0 4" }, { "input": "1 10 10", "output": "0 10" }, { "input": "1 345 345", "output": "0 345" }, { "input": "7 12 13", "output": "150 91" }, { "input": "1 500 1", "output": "0 1" }, { "input": "1 12 13", "output": "0 13" }, { "input": "1 500 499", "output": "0 499" }, { "input": "1 100 90", "output": "0 90" }, { "input": "2 100 90", "output": "201 180" }, { "input": "53 1 1", "output": "156 53" }, { "input": "73 73 73", "output": "10584 5329" }, { "input": "67 1 1", "output": "198 67" }, { "input": "63 1 1", "output": "186 63" }, { "input": "59 1 1", "output": "174 59" }, { "input": "57 1 1", "output": "168 57" }, { "input": "13 1 1", "output": "36 13" }, { "input": "349 2 5", "output": "1740 1745" }, { "input": "456 456 456", "output": "415415 207936" } ]
1,593,529,073
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
140
0
n,b,p = map(int,input().split()) k = 2 cnt = 0 while n>k: if k*2>n: break else: k*=2 c = n%k k = (k-1+c) print(k*b*2+k,n*p)
Title: Tennis Tournament Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). Input Specification: The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. Output Specification: Print two integers *x* and *y* — the number of bottles and towels need for the tournament. Demo Input: ['5 2 3\n', '8 2 4\n'] Demo Output: ['20 15\n', '35 32\n'] Note: In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
```python n,b,p = map(int,input().split()) k = 2 cnt = 0 while n>k: if k*2>n: break else: k*=2 c = n%k k = (k-1+c) print(k*b*2+k,n*p) ```
0
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,500,459,169
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
4,608,000
import math n = int(input()) string = input() radii = sorted(map(int, string.split())) a = 0 for x in range(n): a += (radii[x] ** 2) * ((-1) ** x) print(a * math.pi)
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 import math n = int(input()) string = input() radii = sorted(map(int, string.split())) a = 0 for x in range(n): a += (radii[x] ** 2) * ((-1) ** x) print(a * math.pi) ```
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,687,535,146
2,147,483,647
Python 3
OK
TESTS
49
62
102,400
sList = [int(x) for x in input().split()][:4] game = input() count = 0 for i in game: count += sList[int(i)-1] print(count)
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 sList = [int(x) for x in input().split()][:4] game = input() count = 0 for i in game: count += sList[int(i)-1] print(count) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,663,772,699
2,147,483,647
Python 3
OK
TESTS
32
46
0
s, v_1, v_2, t_1, t_2 = map(int, input().split()) if (result_1 := s * v_1 + 2 * t_1) != (result_2 := s * v_2 + 2 * t_2): if result_1 > result_2: print('Second') else: print('First') else: print('Friendship')
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s, v_1, v_2, t_1, t_2 = map(int, input().split()) if (result_1 := s * v_1 + 2 * t_1) != (result_2 := s * v_2 + 2 * t_2): if result_1 > result_2: print('Second') else: print('First') else: print('Friendship') ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", "output": "18" }, { "input": "z\na", "output": "2" }, { "input": "ama\nsama", "output": "1" }, { "input": "aaabc\nbc", "output": "3" }, { "input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "output": "32" }, { "input": "ahmedaly\naly", "output": "5" }, { "input": "aa\na", "output": "1" }, { "input": "aa\nba", "output": "2" }, { "input": "cccba\nba", "output": "3" }, { "input": "a\nab", "output": "3" }, { "input": "dadc\ndddc", "output": "4" }, { "input": "aacaaab\nb", "output": "6" }, { "input": "dddc\ncdcde", "output": "9" }, { "input": "bbdab\ndab", "output": "2" }, { "input": "a\naa", "output": "1" }, { "input": "aa\nab", "output": "4" }, { "input": "codeforces\nces", "output": "7" } ]
1,688,904,485
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
819,200
s1 = input() s2 = input() moves = 0 is_done = False if len(s1) == len(s2): while True: if s1 == s2: break moves += 2 s1 = s1[1:] s2 = s2[1:] print(moves) else: diff = abs(len(s1)-len(s2)) if len(s1) > len(s2): s1 = s1[diff:] else: s2 = s2[diff:] while True: if s1 == s2: break moves += 2 s1 = s1[1:] s2 = s2[1:] print(moves+diff)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python s1 = input() s2 = input() moves = 0 is_done = False if len(s1) == len(s2): while True: if s1 == s2: break moves += 2 s1 = s1[1:] s2 = s2[1:] print(moves) else: diff = abs(len(s1)-len(s2)) if len(s1) > len(s2): s1 = s1[diff:] else: s2 = s2[diff:] while True: if s1 == s2: break moves += 2 s1 = s1[1:] s2 = s2[1:] print(moves+diff) ```
0
359
A
Table
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*). Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table. Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2). Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50). Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
Print a single number — the minimum number of operations Simon needs to carry out his idea.
[ "3 3\n0 0 0\n0 1 0\n0 0 0\n", "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n" ]
[ "4\n", "2\n" ]
In the first sample, the sequence of operations can be like this: - For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3). In the second sample the sequence of operations can be like this: - For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1).
500
[ { "input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "4" }, { "input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0", "output": "2" }, { "input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0", "output": "4" }, { "input": "5 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "4 32\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "7 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0", "output": "2" }, { "input": "13 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "3 3\n0 1 0\n0 0 0\n0 0 0", "output": "2" }, { "input": "3 3\n0 0 0\n0 0 0\n0 1 0", "output": "2" }, { "input": "3 3\n0 0 0\n1 0 0\n0 0 0", "output": "2" }, { "input": "3 3\n0 0 0\n0 0 1\n0 0 0", "output": "2" }, { "input": "3 4\n0 1 0 0\n0 0 0 0\n0 0 0 0", "output": "2" }, { "input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "2" }, { "input": "3 5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "3 5\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "2" }, { "input": "3 5\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "4" }, { "input": "4 3\n0 1 0\n0 0 0\n0 0 0\n0 0 0", "output": "2" }, { "input": "4 3\n0 0 0\n0 0 0\n0 0 0\n0 1 0", "output": "2" }, { "input": "5 3\n0 0 0\n0 0 0\n1 0 0\n0 0 0\n0 0 0", "output": "2" }, { "input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 0 0\n0 0 0", "output": "2" }, { "input": "5 3\n0 0 0\n0 1 0\n0 0 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "4 4\n0 0 0 0\n0 1 1 0\n0 1 1 0\n0 0 0 0", "output": "4" }, { "input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 1 0\n0 0 0", "output": "2" }, { "input": "3 3\n0 0 0\n0 1 1\n0 0 0", "output": "2" }, { "input": "4 3\n0 0 0\n0 0 0\n0 1 0\n0 0 0", "output": "4" }, { "input": "5 5\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "5 3\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n0 0 0", "output": "2" } ]
1,665,051,490
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
61
3,072,000
x = input().split() a,b = int(x[0]), int(x[1]) y = [] for i in range(N): y.append(input().split()) result = 0 if any(e == '1' for e in y[0]): result = 2 elif any(e == '1' for e in y[-1]): result = 2 else: for i in range(N): if y[i][0] == '1': result = 2 elif y[i][-1] == '1': y = 2 if result == 0: print('4') else: print(result)
Title: Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*). Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table. Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2). Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times. Input Specification: The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50). Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner. Output Specification: Print a single number — the minimum number of operations Simon needs to carry out his idea. Demo Input: ['3 3\n0 0 0\n0 1 0\n0 0 0\n', '4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n'] Demo Output: ['4\n', '2\n'] Note: In the first sample, the sequence of operations can be like this: - For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3). In the second sample the sequence of operations can be like this: - For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1).
```python x = input().split() a,b = int(x[0]), int(x[1]) y = [] for i in range(N): y.append(input().split()) result = 0 if any(e == '1' for e in y[0]): result = 2 elif any(e == '1' for e in y[-1]): result = 2 else: for i in range(N): if y[i][0] == '1': result = 2 elif y[i][-1] == '1': y = 2 if result == 0: print('4') else: print(result) ```
-1
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24" } ]
1,548,161,892
2,147,483,647
Python 3
OK
TESTS
41
109
614,400
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) jb = 0 cnt = 0 for ai in a: while jb < m and b[jb] < ai: jb += 1 if jb == m: break cnt += 1 jb += 1 print(len(a) - cnt)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n'] Demo Output: ['0\n', '2\n', '3\n'] Note: In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
```python n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) jb = 0 cnt = 0 for ai in a: while jb < m and b[jb] < ai: jb += 1 if jb == m: break cnt += 1 jb += 1 print(len(a) - cnt) ```
3
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,666,552,625
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
s=str(input()).split(",") t=[] for i in s: t+=i.split(";") a=[] b=[] for i in t: if i.isnumeric() and not (len(i)>1 and (i[0]=='0')): a.append(i) else: b.append(i) print('"'+ ",".join(a)+'"' if a else '"-"') print('"'+",".join(b) +'"' if b else '"-"')
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 s=str(input()).split(",") t=[] for i in s: t+=i.split(";") a=[] b=[] for i in t: if i.isnumeric() and not (len(i)>1 and (i[0]=='0')): a.append(i) else: b.append(i) print('"'+ ",".join(a)+'"' if a else '"-"') print('"'+",".join(b) +'"' if b else '"-"') ```
0
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
1,592,812,484
2,147,483,647
PyPy 3
OK
TESTS
46
140
0
a,b = list(map(int,input().split())) ans = 0 while True: if b>a: a,b = b,a if a%b==0: ans+=a//b break else: ans+=a//b a = a%b print(ans)
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python a,b = list(map(int,input().split())) ans = 0 while True: if b>a: a,b = b,a if a%b==0: ans+=a//b break else: ans+=a//b a = a%b print(ans) ```
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1" } ]
1,697,982,719
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n=int(input()) g_g=list(map(int,input().split())) g_r=[0]*n for _ in range(n): g_r[g_g[i]-1]=i+1 print(" ".join(map(str,g_r)))
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python n=int(input()) g_g=list(map(int,input().split())) g_r=[0]*n for _ in range(n): g_r[g_g[i]-1]=i+1 print(" ".join(map(str,g_r))) ```
-1
125
A
Measuring Lengths in Baden
PROGRAMMING
1,400
[ "math" ]
null
null
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches. Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000).
Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches.
[ "42\n", "5\n" ]
[ "1 2\n", "0 2\n" ]
none
1,000
[ { "input": "42", "output": "1 2" }, { "input": "5", "output": "0 2" }, { "input": "24", "output": "0 8" }, { "input": "1", "output": "0 0" }, { "input": "2", "output": "0 1" }, { "input": "3", "output": "0 1" }, { "input": "4", "output": "0 1" }, { "input": "8", "output": "0 3" }, { "input": "10", "output": "0 3" }, { "input": "12", "output": "0 4" }, { "input": "13", "output": "0 4" }, { "input": "100", "output": "2 9" }, { "input": "120", "output": "3 4" }, { "input": "199", "output": "5 6" }, { "input": "501", "output": "13 11" }, { "input": "1000", "output": "27 9" }, { "input": "1233", "output": "34 3" }, { "input": "9876", "output": "274 4" }, { "input": "9999", "output": "277 9" }, { "input": "10000", "output": "277 9" }, { "input": "35", "output": "1 0" }, { "input": "71", "output": "2 0" } ]
1,597,230,293
2,147,483,647
Python 3
OK
TESTS
22
216
6,656,000
x = int(input()) x = (x+1)//3 print(x//12, x%12)
Title: Measuring Lengths in Baden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches. Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000). Output Specification: Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches. Demo Input: ['42\n', '5\n'] Demo Output: ['1 2\n', '0 2\n'] Note: none
```python x = int(input()) x = (x+1)//3 print(x//12, x%12) ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", "output": "18" }, { "input": "z\na", "output": "2" }, { "input": "ama\nsama", "output": "1" }, { "input": "aaabc\nbc", "output": "3" }, { "input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "output": "32" }, { "input": "ahmedaly\naly", "output": "5" }, { "input": "aa\na", "output": "1" }, { "input": "aa\nba", "output": "2" }, { "input": "cccba\nba", "output": "3" }, { "input": "a\nab", "output": "3" }, { "input": "dadc\ndddc", "output": "4" }, { "input": "aacaaab\nb", "output": "6" }, { "input": "dddc\ncdcde", "output": "9" }, { "input": "bbdab\ndab", "output": "2" }, { "input": "a\naa", "output": "1" }, { "input": "aa\nab", "output": "4" }, { "input": "codeforces\nces", "output": "7" } ]
1,636,077,207
2,147,483,647
Python 3
OK
TESTS
28
124
5,734,400
string1 = input() string2 = input() same = 0 minn = min(len(string1),len(string2)) for i in range(minn): if string1[-1-i]==string2[-1-i]: same += 2 else: break print((len(string1)+len(string2))-same)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python string1 = input() string2 = input() same = 0 minn = min(len(string1),len(string2)) for i in range(minn): if string1[-1-i]==string2[-1-i]: same += 2 else: break print((len(string1)+len(string2))-same) ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,692,554,147
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
1,331,200
def isPrime(n): a=True k=2 while k*k<=n: if n%k==0: a=False break return a n=int(input()) for i in range(4,n//2+1): if not isPrime(i) and not isPrime(n-i): print(i,n-i)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python def isPrime(n): a=True k=2 while k*k<=n: if n%k==0: a=False break return a n=int(input()) for i in range(4,n//2+1): if not isPrime(i) and not isPrime(n-i): print(i,n-i) ```
0
363
A
Soroban
PROGRAMMING
800
[ "implementation" ]
null
null
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: - Set the value of a digit equal to 0. - If the go-dama is shifted to the right, add 5. - Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720. Write the program that prints the way Soroban shows the given number *n*.
The first line contains a single integer *n* (0<=≤<=*n*<=&lt;<=109).
Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number *n* without leading zeroes. We can assume that number 0 has no leading zeroes.
[ "2\n", "13\n", "720\n" ]
[ "O-|OO-OO\n", "O-|OOO-O\nO-|O-OOO\n", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n" ]
none
500
[ { "input": "2", "output": "O-|OO-OO" }, { "input": "13", "output": "O-|OOO-O\nO-|O-OOO" }, { "input": "720", "output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO" }, { "input": "0", "output": "O-|-OOOO" }, { "input": "1", "output": "O-|O-OOO" }, { "input": "3", "output": "O-|OOO-O" }, { "input": "4", "output": "O-|OOOO-" }, { "input": "5", "output": "-O|-OOOO" }, { "input": "6", "output": "-O|O-OOO" }, { "input": "637", "output": "-O|OO-OO\nO-|OOO-O\n-O|O-OOO" }, { "input": "7", "output": "-O|OO-OO" }, { "input": "8", "output": "-O|OOO-O" }, { "input": "9", "output": "-O|OOOO-" }, { "input": "10", "output": "O-|-OOOO\nO-|O-OOO" }, { "input": "11", "output": "O-|O-OOO\nO-|O-OOO" }, { "input": "100", "output": "O-|-OOOO\nO-|-OOOO\nO-|O-OOO" }, { "input": "99", "output": "-O|OOOO-\n-O|OOOO-" }, { "input": "245", "output": "-O|-OOOO\nO-|OOOO-\nO-|OO-OO" }, { "input": "118", "output": "-O|OOO-O\nO-|O-OOO\nO-|O-OOO" }, { "input": "429", "output": "-O|OOOO-\nO-|OO-OO\nO-|OOOO-" }, { "input": "555", "output": "-O|-OOOO\n-O|-OOOO\n-O|-OOOO" }, { "input": "660", "output": "O-|-OOOO\n-O|O-OOO\n-O|O-OOO" }, { "input": "331", "output": "O-|O-OOO\nO-|OOO-O\nO-|OOO-O" }, { "input": "987", "output": "-O|OO-OO\n-O|OOO-O\n-O|OOOO-" }, { "input": "123456789", "output": "-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO\nO-|O-OOO" }, { "input": "234567890", "output": "O-|-OOOO\n-O|OOOO-\n-O|OOO-O\n-O|OO-OO\n-O|O-OOO\n-O|-OOOO\nO-|OOOO-\nO-|OOO-O\nO-|OO-OO" }, { "input": "100000000", "output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO" }, { "input": "111111111", "output": "O-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO\nO-|O-OOO" }, { "input": "90909090", "output": "O-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-\nO-|-OOOO\n-O|OOOO-" }, { "input": "987654321", "output": "O-|O-OOO\nO-|OO-OO\nO-|OOO-O\nO-|OOOO-\n-O|-OOOO\n-O|O-OOO\n-O|OO-OO\n-O|OOO-O\n-O|OOOO-" }, { "input": "45165125", "output": "-O|-OOOO\nO-|OO-OO\nO-|O-OOO\n-O|-OOOO\n-O|O-OOO\nO-|O-OOO\n-O|-OOOO\nO-|OOOO-" }, { "input": "445511006", "output": "-O|O-OOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO\nO-|O-OOO\n-O|-OOOO\n-O|-OOOO\nO-|OOOO-\nO-|OOOO-" }, { "input": "999999999", "output": "-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-\n-O|OOOO-" }, { "input": "984218523", "output": "O-|OOO-O\nO-|OO-OO\n-O|-OOOO\n-O|OOO-O\nO-|O-OOO\nO-|OO-OO\nO-|OOOO-\n-O|OOO-O\n-O|OOOO-" }, { "input": "19", "output": "-O|OOOO-\nO-|O-OOO" }, { "input": "10000000", "output": "O-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|-OOOO\nO-|O-OOO" } ]
1,683,366,017
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
n = int(input()) while n>0: digit = n%10 if digit>=5: left = digit-5 right = 4-left print("-O|",end="") else: left = digit right = 4-digit print("O-|",end="") if left>0: print("O"*left,end="") print("-",end="") if right>0: print("O"*right) n = n//10
Title: Soroban Time Limit: None seconds Memory Limit: None megabytes Problem Description: You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: - Set the value of a digit equal to 0. - If the go-dama is shifted to the right, add 5. - Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720. Write the program that prints the way Soroban shows the given number *n*. Input Specification: The first line contains a single integer *n* (0<=≤<=*n*<=&lt;<=109). Output Specification: Print the description of the decimal digits of number *n* from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number *n* without leading zeroes. We can assume that number 0 has no leading zeroes. Demo Input: ['2\n', '13\n', '720\n'] Demo Output: ['O-|OO-OO\n', 'O-|OOO-O\nO-|O-OOO\n', 'O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n'] Note: none
```python n = int(input()) while n>0: digit = n%10 if digit>=5: left = digit-5 right = 4-left print("-O|",end="") else: left = digit right = 4-digit print("O-|",end="") if left>0: print("O"*left,end="") print("-",end="") if right>0: print("O"*right) n = n//10 ```
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,694,183,550
2,147,483,647
Python 3
OK
TESTS
15
46
0
while True: try: a, b, c = map(int, input().split()) t = sum(i * a for i in range(1, c + 1)) res = max(0, t - b) print(res) except EOFError: break
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python while True: try: a, b, c = map(int, input().split()) t = sum(i * a for i in range(1, c + 1)) res = max(0, t - b) print(res) except EOFError: break ```
3
841
B
Godsend
PROGRAMMING
1,100
[ "games", "math" ]
null
null
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
[ "4\n1 3 2 3\n", "2\n2 2\n" ]
[ "First\n", "Second\n" ]
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
1,000
[ { "input": "4\n1 3 2 3", "output": "First" }, { "input": "2\n2 2", "output": "Second" }, { "input": "4\n2 4 6 8", "output": "Second" }, { "input": "5\n1 1 1 1 1", "output": "First" }, { "input": "4\n720074544 345031254 849487632 80870826", "output": "Second" }, { "input": "1\n0", "output": "Second" }, { "input": "1\n999999999", "output": "First" }, { "input": "2\n1 999999999", "output": "First" }, { "input": "4\n3 3 4 4", "output": "First" }, { "input": "2\n1 2", "output": "First" }, { "input": "8\n2 2 2 1 1 2 2 2", "output": "First" }, { "input": "5\n3 3 2 2 2", "output": "First" }, { "input": "4\n0 1 1 0", "output": "First" }, { "input": "3\n1 2 2", "output": "First" }, { "input": "6\n2 2 1 1 4 2", "output": "First" }, { "input": "8\n2 2 2 3 3 2 2 2", "output": "First" }, { "input": "4\n2 3 3 4", "output": "First" }, { "input": "10\n2 2 2 2 3 1 2 2 2 2", "output": "First" }, { "input": "6\n2 2 1 1 2 2", "output": "First" }, { "input": "3\n1 1 2", "output": "First" }, { "input": "6\n2 4 3 3 4 6", "output": "First" }, { "input": "6\n4 4 3 3 4 4", "output": "First" }, { "input": "4\n1 1 2 2", "output": "First" }, { "input": "4\n1 3 5 7", "output": "First" }, { "input": "4\n2 1 1 2", "output": "First" }, { "input": "4\n1 3 3 2", "output": "First" }, { "input": "5\n3 2 2 2 2", "output": "First" }, { "input": "3\n2 1 1", "output": "First" }, { "input": "4\n1000000000 1000000000 1000000000 99999999", "output": "First" }, { "input": "4\n2 2 1 1", "output": "First" }, { "input": "5\n2 3 2 3 2", "output": "First" }, { "input": "1\n1", "output": "First" }, { "input": "4\n1000000000 1000000000 1000000000 1", "output": "First" }, { "input": "5\n2 2 2 1 1", "output": "First" }, { "input": "6\n2 1 1 1 1 2", "output": "First" }, { "input": "6\n1 2 2 2 2 1", "output": "First" }, { "input": "11\n2 2 2 2 2 1 2 2 2 2 2", "output": "First" }, { "input": "5\n1 3 2 2 2", "output": "First" }, { "input": "3\n2 3 2", "output": "First" }, { "input": "2\n1 1", "output": "First" }, { "input": "5\n4 4 4 3 3", "output": "First" }, { "input": "5\n3 3 4 4 4", "output": "First" }, { "input": "1\n2", "output": "Second" } ]
1,587,375,209
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
18
998
61,542,400
n = int(input().strip()) a = [ int(i)%2 for i in input().strip().split(' ')] if sum(a)%2==1: print('First') else: if a[0]==1 or a[-1]==1: print('First') else: print('Second')
Title: Godsend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally? Input Specification: First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). Demo Input: ['4\n1 3 2 3\n', '2\n2 2\n'] Demo Output: ['First\n', 'Second\n'] Note: In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
```python n = int(input().strip()) a = [ int(i)%2 for i in input().strip().split(' ')] if sum(a)%2==1: print('First') else: if a[0]==1 or a[-1]==1: print('First') else: print('Second') ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,664,200,403
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
0
n = int(input()) cashDeskPrev = '' cashDeskMin = 1 for i in range(n): cashDeskCurr = input() if cashDeskCurr == '0 4': cashDeskMin = 8 break if cashDeskCurr == cashDeskPrev: cashDeskMin += 1 else: cashDeskPrev = cashDeskCurr print(cashDeskMin)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python n = int(input()) cashDeskPrev = '' cashDeskMin = 1 for i in range(n): cashDeskCurr = input() if cashDeskCurr == '0 4': cashDeskMin = 8 break if cashDeskCurr == cashDeskPrev: cashDeskMin += 1 else: cashDeskPrev = cashDeskCurr print(cashDeskMin) ```
0
554
B
Ohana Cleans Up
PROGRAMMING
1,200
[ "brute force", "greedy", "strings" ]
null
null
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean.
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty.
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
[ "4\n0101\n1000\n1111\n0101\n", "3\n111\n111\n111\n" ]
[ "2\n", "3\n" ]
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
500
[ { "input": "4\n0101\n1000\n1111\n0101", "output": "2" }, { "input": "3\n111\n111\n111", "output": "3" }, { "input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "9" }, { "input": "1\n1", "output": "1" }, { "input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011", "output": "6" }, { "input": "20\n10101011101000011010\n11111010001100110101\n01011100010000001111\n10110100000101010011\n11010001110111101101\n00100110011011101010\n01000110101011001100\n01101100111101101101\n10111010010100111100\n00010010110001101110\n10111110010000101010\n10010111110100100100\n11010111001111110100\n11110111101100000001\n00011010100111011000\n11110001011000011010\n10001101010000011011\n01010101110010000111\n11100110111101101111\n11011111110010001111", "output": "1" }, { "input": "10\n1001000000\n0111101111\n1111001011\n1000010100\n0111101111\n0101100110\n1001000000\n1000010100\n0111101111\n1001000000", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "10" }, { "input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111", "output": "10" }, { "input": "10\n1000000000\n0100000000\n0010000000\n0001000000\n0000100000\n0000010000\n0000001000\n0000000100\n0000000010\n0000000001", "output": "1" }, { "input": "2\n10\n01", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "4\n0000\n0000\n1111\n1111", "output": "2" }, { "input": "11\n10000000001\n10000000001\n10000000001\n10000000001\n10001000001\n10001000000\n10001000001\n10001000001\n10001000000\n10001000000\n10001000100", "output": "4" } ]
1,606,082,537
2,147,483,647
Python 3
OK
TESTS
36
124
409,600
from collections import defaultdict n = int(input()) ans = 0 rows = defaultdict() for _ in range(n): row = str(input()) if row in rows: rows[row] += 1 else: rows[row] = 1 curr = rows[row] if curr > ans: ans = curr print(ans)
Title: Ohana Cleans Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean. Input Specification: The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty. Output Specification: The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. Demo Input: ['4\n0101\n1000\n1111\n0101\n', '3\n111\n111\n111\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
```python from collections import defaultdict n = int(input()) ans = 0 rows = defaultdict() for _ in range(n): row = str(input()) if row in rows: rows[row] += 1 else: rows[row] = 1 curr = rows[row] if curr > ans: ans = curr print(ans) ```
3
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,548,536,535
2,147,483,647
Python 3
OK
TESTS
23
186
0
n=int(input()) s=input() r=0 for i in range(n): if s[i]=='R': r=1 if r==0: for i in range(n): if s[i]=='L': a=i break for j in range(i,n): if s[j]=='.': b=j break print(b,a) else: for i in range(n): if s[i]!='.': print(i+1,end=" ") k=s[i] break if k=='L': k='R' else: k='L' q=0 for j in range(i,n): if s[j]==k: print(j) q=1 break elif s[j]=='.': print(j+1) q=1 break if q==0: print(n)
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. Output Specification: Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. Demo Input: ['9\n..RRLL...\n', '11\n.RRRLLLLL..\n'] Demo Output: ['3 4\n', '7 5\n'] Note: The first test sample is the one in the picture.
```python n=int(input()) s=input() r=0 for i in range(n): if s[i]=='R': r=1 if r==0: for i in range(n): if s[i]=='L': a=i break for j in range(i,n): if s[j]=='.': b=j break print(b,a) else: for i in range(n): if s[i]!='.': print(i+1,end=" ") k=s[i] break if k=='L': k='R' else: k='L' q=0 for j in range(i,n): if s[j]==k: print(j) q=1 break elif s[j]=='.': print(j+1) q=1 break if q==0: print(n) ```
3
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71", "output": "51" }, { "input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29", "output": "1" }, { "input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24", "output": "2" }, { "input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6", "output": "10" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "99" }, { "input": "7\n1 2 3 3 3 1 2", "output": "3" }, { "input": "5\n1 2 3 4 5", "output": "1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "1" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "11\n1 2 3 4 5 6 7 8 9 1 1", "output": "3" }, { "input": "12\n1 2 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "14" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "16" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "10\n1 1 1 1 2 2 1 1 9 10", "output": "6" }, { "input": "2\n1 1", "output": "2" }, { "input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "56" }, { "input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92", "output": "6" }, { "input": "10\n1 2 2 3 3 3 4 4 4 4", "output": "4" }, { "input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21", "output": "3" }, { "input": "5\n5 5 5 5 1", "output": "4" }, { "input": "6\n2 3 2 5 2 6", "output": "3" }, { "input": "3\n58 59 58", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 8", "output": "2" }, { "input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "97" }, { "input": "3\n95 95 4", "output": "2" }, { "input": "3\n2 2 5", "output": "2" } ]
1,632,744,847
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
# Hydro submission #6151b53ae1e942053715046a@1632744762395 6 1 2 4 3 3 2
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. Output Specification: Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. Demo Input: ['6\n1 2 4 3 3 2\n', '1\n100\n'] Demo Output: ['2\n', '1\n'] Note: none
```python # Hydro submission #6151b53ae1e942053715046a@1632744762395 6 1 2 4 3 3 2 ```
-1
224
B
Array
PROGRAMMING
1,500
[ "bitmasks", "implementation", "two pointers" ]
null
null
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
[ "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "7 4\n4 7 7 4 7 4 7\n" ]
[ "1 2\n", "2 5\n", "-1 -1\n" ]
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
1,000
[ { "input": "4 2\n1 2 2 3", "output": "1 2" }, { "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5" }, { "input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1" }, { "input": "5 1\n1 7 2 3 2", "output": "1 1" }, { "input": "1 2\n666", "output": "-1 -1" }, { "input": "1 1\n5", "output": "1 1" }, { "input": "10 4\n1 1 2 2 3 3 4 4 4 4", "output": "2 7" }, { "input": "4 2\n3 3 4 3", "output": "2 3" }, { "input": "4 3\n4 4 4 2", "output": "-1 -1" }, { "input": "10 5\n15 17 2 13 3 16 4 5 9 12", "output": "1 5" }, { "input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148", "output": "1 13" }, { "input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796", "output": "-1 -1" }, { "input": "8 5\n1 2 1 1 2 3 4 5", "output": "4 8" }, { "input": "7 3\n2 1 2 2 1 2 3", "output": "5 7" }, { "input": "6 3\n1 3 1 1 4 5", "output": "2 5" }, { "input": "5 3\n1 2 1 1 3", "output": "2 5" }, { "input": "9 3\n1 2 1 2 1 2 2 3 1", "output": "5 8" }, { "input": "4 3\n1 2 1 3", "output": "2 4" }, { "input": "5 3\n1 3 1 3 4", "output": "3 5" }, { "input": "6 3\n1 3 3 1 4 4", "output": "3 5" }, { "input": "5 3\n1 2 1 2 3", "output": "3 5" }, { "input": "8 4\n1 2 3 2 1 2 3 4", "output": "5 8" }, { "input": "10 4\n1 2 3 1 2 3 4 3 2 1", "output": "4 7" }, { "input": "10 3\n1 1 1 2 1 2 3 3 3 4", "output": "5 7" }, { "input": "10 3\n1 1 2 1 2 2 3 4 5 6", "output": "4 7" } ]
1,677,126,990
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
n, k = map (int, input().strip().split()) A = list (map (int, input().strip().split())) k1 = 0 for i in range (n-1): if A[i]==A[i+1]: sp=i+1 break else: sp=i break for i in range (sp, n-1): if A[i]!=A[i+1]: k1 += 1 if k1==k: ep=i+1 print (sp+1, " ", ep)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. Input Specification: The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. Demo Input: ['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n'] Demo Output: ['1 2\n', '2 5\n', '-1 -1\n'] Note: In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
```python n, k = map (int, input().strip().split()) A = list (map (int, input().strip().split())) k1 = 0 for i in range (n-1): if A[i]==A[i+1]: sp=i+1 break else: sp=i break for i in range (sp, n-1): if A[i]!=A[i+1]: k1 += 1 if k1==k: ep=i+1 print (sp+1, " ", ep) ```
0
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,651,401,004
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n,k=map(int,input().split()) a=list(map(int,input().split())) s=[] for i in a: if i+k<=5: s.append(i) print(len(s)//6)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n,k=map(int,input().split()) a=list(map(int,input().split())) s=[] for i in a: if i+k<=5: s.append(i) print(len(s)//6) ```
0
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,587,655,620
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
3,276,800
n=int(input()) m=int(input()) if n > m: print(">") elif n < m : 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 n=int(input()) m=int(input()) if n > m: print(">") elif n < m : print("<") else : print("=") ```
0
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "input": "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10", "output": "15" }, { "input": "100\n28 20 67 103 72 81 82 83 7 109 122 30 50 118 83 89 108 82 92 17 97 3 62 12 9 100 14 11 99 106 10 8 60 101 88 119 104 62 76 6 5 57 32 94 60 50 58 97 1 97 107 108 80 24 45 20 112 1 98 106 49 98 25 57 47 90 74 68 14 35 22 10 61 80 10 4 53 13 90 99 57 100 40 84 22 116 60 61 98 57 74 127 61 73 49 51 20 19 56 111", "output": "127" }, { "input": "99\n87 67 4 84 13 20 35 7 11 86 25 1 58 1 74 64 74 86 98 74 72 46 63 78 84 13 60 38 30 45 45 60 9 44 36 70 33 22 82 15 71 7 43 47 23 2 20 49 42 43 54 27 51 51 53 23 27 37 17 66 90 89 61 0 18 20 49 30 84 20 13 32 64 69 56 68 59 10 91 96 43 64 19 10 2 57 62 23 100 39 32 19 95 55 77 19 24 4 77", "output": "127" }, { "input": "1\n100", "output": "100" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n4 10", "output": "14" }, { "input": "99\n3511 2076 9314 3598 7737 271 4110 4454 5830 8661 8584 8227 2236 2626 1025 3806 3162 2837 6071 9627 1836 7729 6629 4054 9377 3261 1325 8859 3610 7616 5052 9736 1249 6224 7031 6074 4196 8075 4005 5419 5664 8214 4391 731 8714 8622 6122 6976 4057 1770 8025 3778 2792 994 5204 1826 6083 5438 8409 8029 1962 3133 9836 8884 1234 1776 824 1630 6523 2869 9950 8609 5397 1472 7120 5012 6490 5958 8030 7741 5077 2771 7925 9784 9456 8596 6288 8939 4779 4415 3743 5188 5574 9686 1483 4245 4769 4917 1887", "output": "16383" }, { "input": "27\n78 918 443 3900 591 12 4 10 1 24 70 88 429 2 3257 65 275 2 258 62 587 625 25 26 853 728 765", "output": "4027" }, { "input": "2\n3 1", "output": "3" }, { "input": "2\n3 2", "output": "3" }, { "input": "3\n7 3 1", "output": "7" }, { "input": "3\n1 7 2", "output": "7" }, { "input": "2\n7 1", "output": "7" }, { "input": "4\n1 2 7 1", "output": "7" }, { "input": "3\n10 5 1", "output": "15" } ]
1,627,482,837
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
154
7,475,200
import bisect import heapq import math import collections import sys import copy from functools import reduce import decimal from io import BytesIO, IOBase import os sys.setrecursionlimit(10 ** 9) decimal.getcontext().rounding = decimal.ROUND_HALF_UP graphDict = collections.defaultdict queue = collections.deque class Graphs: def __init__(self): self.graph = graphDict(list) def add_edge(self, u, v): self.graph[u].append(v) def dfs_utility(self, nodes, visited_nodes): visited_nodes.add(nodes) for neighbour in self.graph[nodes]: if neighbour not in visited_nodes: self.dfs_utility(neighbour, visited_nodes) else: return neighbour def dfs(self, node): Visited = set() self.dfs_utility(node, Visited) def bfs(self, node): visited = set() if node not in visited: queue.append(node) visited.add(node) while queue: parent = queue.popleft() print(parent) for item in self.graph[parent]: if item not in visited: queue.append(item) visited.add(item) def rounding(n): return int(decimal.Decimal(f'{n}').to_integral_value()) def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) ################################ <fast I/O> ########################################### BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) #############################################<I/O Region >############################################## def inp(): return sys.stdin.readline().strip() def map_inp(v_type): return map(v_type, inp().split()) def list_inp(v_type): return list(map_inp(v_type)) ######################################## Solution #################################### n = int(inp()) arr = list_inp(int) ans = 0 for i in range(n): ans = max(arr[i],ans) for j in range(i + 1, n): ans = max(ans ^ arr[j], ans) print(ans)
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. Output Specification: Print a single integer — the required maximal *xor* of a segment of consecutive elements. Demo Input: ['5\n1 2 1 1 2\n', '3\n1 2 7\n', '4\n4 2 4 8\n'] Demo Output: ['3\n', '7\n', '14\n'] Note: In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
```python import bisect import heapq import math import collections import sys import copy from functools import reduce import decimal from io import BytesIO, IOBase import os sys.setrecursionlimit(10 ** 9) decimal.getcontext().rounding = decimal.ROUND_HALF_UP graphDict = collections.defaultdict queue = collections.deque class Graphs: def __init__(self): self.graph = graphDict(list) def add_edge(self, u, v): self.graph[u].append(v) def dfs_utility(self, nodes, visited_nodes): visited_nodes.add(nodes) for neighbour in self.graph[nodes]: if neighbour not in visited_nodes: self.dfs_utility(neighbour, visited_nodes) else: return neighbour def dfs(self, node): Visited = set() self.dfs_utility(node, Visited) def bfs(self, node): visited = set() if node not in visited: queue.append(node) visited.add(node) while queue: parent = queue.popleft() print(parent) for item in self.graph[parent]: if item not in visited: queue.append(item) visited.add(item) def rounding(n): return int(decimal.Decimal(f'{n}').to_integral_value()) def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) ################################ <fast I/O> ########################################### BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) #############################################<I/O Region >############################################## def inp(): return sys.stdin.readline().strip() def map_inp(v_type): return map(v_type, inp().split()) def list_inp(v_type): return list(map_inp(v_type)) ######################################## Solution #################################### n = int(inp()) arr = list_inp(int) ans = 0 for i in range(n): ans = max(arr[i],ans) for j in range(i + 1, n): ans = max(ans ^ arr[j], ans) print(ans) ```
0
11
D
A Simple Task
PROGRAMMING
2,200
[ "bitmasks", "dp", "graphs" ]
D. A Simple Task
2
256
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains two integers *a* and *b*, (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*) indicating that vertices *a* and *b* are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.
Output the number of cycles in the given graph.
[ "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n" ]
[ "7\n" ]
The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.
0
[ { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "7" }, { "input": "10 3\n4 8\n9 4\n8 9", "output": "1" }, { "input": "8 28\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8", "output": "8018" }, { "input": "12 10\n1 6\n4 5\n4 9\n5 10\n6 12\n7 9\n7 10\n8 10\n10 12\n11 12", "output": "1" }, { "input": "3 0", "output": "0" }, { "input": "6 0", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "3 3\n1 2\n1 3\n2 3", "output": "1" }, { "input": "3 0", "output": "0" }, { "input": "3 0", "output": "0" }, { "input": "3 0", "output": "0" }, { "input": "7 16\n1 2\n1 3\n1 5\n1 7\n2 3\n2 4\n2 6\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n6 7", "output": "214" }, { "input": "14 32\n1 2\n1 3\n1 6\n1 7\n1 9\n1 11\n1 13\n2 8\n2 9\n2 14\n3 7\n3 8\n3 9\n3 13\n4 5\n4 11\n4 14\n6 7\n6 8\n6 9\n6 14\n7 12\n7 13\n8 9\n8 10\n8 11\n9 10\n10 13\n10 14\n11 12\n11 13\n13 14", "output": "9239" }, { "input": "18 45\n1 2\n1 5\n1 12\n1 13\n2 3\n2 4\n2 11\n2 14\n2 15\n3 7\n3 16\n4 7\n4 8\n4 10\n4 18\n5 8\n5 10\n5 16\n5 17\n6 12\n6 16\n7 9\n7 12\n8 10\n8 16\n9 11\n9 12\n9 16\n9 17\n10 11\n10 15\n11 12\n11 14\n11 15\n12 13\n12 14\n12 15\n12 18\n13 15\n13 16\n13 17\n14 15\n14 18\n16 17\n17 18", "output": "467111" }, { "input": "19 11\n3 4\n3 12\n3 14\n4 12\n5 11\n8 9\n8 10\n9 10\n9 13\n11 19\n15 16", "output": "2" }, { "input": "1 0", "output": "0" }, { "input": "10 44\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n3 8\n3 10\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 6\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n7 8\n7 9\n7 10\n8 9\n8 10\n9 10", "output": "446414" }, { "input": "16 11\n1 2\n2 7\n2 12\n3 12\n4 5\n4 15\n6 7\n6 9\n7 8\n12 14\n14 16", "output": "0" }, { "input": "1 0", "output": "0" }, { "input": "3 3\n1 2\n1 3\n2 3", "output": "1" }, { "input": "6 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "3 3\n1 2\n1 3\n2 3", "output": "1" }, { "input": "2 0", "output": "0" }, { "input": "1 0", "output": "0" }, { "input": "18 54\n1 7\n1 11\n1 14\n1 15\n1 18\n2 7\n3 4\n3 9\n3 10\n3 11\n3 12\n3 13\n3 16\n3 17\n3 18\n4 5\n4 9\n4 11\n4 13\n5 12\n5 13\n5 14\n5 15\n5 16\n5 18\n6 9\n6 10\n6 12\n6 13\n6 17\n7 8\n7 17\n8 10\n8 11\n8 12\n8 14\n8 15\n9 11\n9 12\n10 11\n10 13\n10 16\n10 17\n11 12\n11 15\n11 16\n12 15\n12 18\n13 15\n13 17\n14 15\n14 16\n15 17\n17 18", "output": "6418594" }, { "input": "3 0", "output": "0" }, { "input": "5 8\n1 3\n1 4\n1 5\n2 3\n2 4\n3 4\n3 5\n4 5", "output": "12" }, { "input": "19 48\n1 5\n1 6\n1 14\n1 17\n1 18\n2 3\n2 4\n2 7\n2 13\n2 16\n2 18\n2 19\n3 8\n3 11\n3 16\n3 17\n4 5\n4 13\n4 17\n4 19\n5 8\n5 13\n5 15\n5 16\n5 19\n6 7\n6 11\n6 12\n6 14\n7 8\n7 11\n8 11\n8 19\n9 14\n9 17\n9 18\n10 13\n10 19\n11 12\n11 18\n12 14\n13 16\n13 17\n13 19\n14 15\n16 17\n17 18\n18 19", "output": "824798" }, { "input": "2 0", "output": "0" }, { "input": "6 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6", "output": "197" }, { "input": "19 22\n1 10\n1 14\n1 17\n2 10\n2 12\n2 13\n3 8\n3 13\n3 14\n4 10\n4 19\n7 9\n7 12\n9 18\n10 11\n11 13\n11 19\n12 13\n14 16\n16 17\n16 19\n17 19", "output": "60" }, { "input": "1 0", "output": "0" }, { "input": "3 0", "output": "0" } ]
1,689,256,917
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689256917.8022442")# 1689256917.802282
Title: A Simple Task Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains two integers *a* and *b*, (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*) indicating that vertices *a* and *b* are connected by an undirected edge. There is no more than one edge connecting any pair of vertices. Output Specification: Output the number of cycles in the given graph. Demo Input: ['4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n'] Demo Output: ['7\n'] Note: The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.
```python print("_RANDOM_GUESS_1689256917.8022442")# 1689256917.802282 ```
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,698,515,903
2,147,483,647
PyPy 3-64
OK
TESTS
25
124
0
def solve(word): return word[0].upper() + word[1:] def main(): word = input().strip() # string values print(solve(word)) if __name__ == "__main__": main()
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python def solve(word): return word[0].upper() + word[1:] def main(): word = input().strip() # string values print(solve(word)) if __name__ == "__main__": main() ```
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,686,707,584
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
def convert_word(word): uppercase_count = sum(1 for letter in word if letter.isupper()) lowercase_count = len(word) - uppercase_count if uppercase_count > lowercase_count: return word.upper() else: return word.lower() # Example usage input_word = "HoUse" converted_word = convert_word(input_word) print(converted_word) # Output: house
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 def convert_word(word): uppercase_count = sum(1 for letter in word if letter.isupper()) lowercase_count = len(word) - uppercase_count if uppercase_count > lowercase_count: return word.upper() else: return word.lower() # Example usage input_word = "HoUse" converted_word = convert_word(input_word) print(converted_word) # Output: house ```
0
980
B
Marlin
PROGRAMMING
1,600
[ "constructive algorithms" ]
null
null
The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the Salmon pond at $(1, n)$. The mayor of Fishtopia wants to place $k$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells. A person can move from one cell to another if those cells are not occupied by hotels and share a side. Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is odd, the width of the city, and the number of hotels to be placed, respectively.
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
[ "7 2\n", "5 3\n" ]
[ "YES\n.......\n.#.....\n.#.....\n.......\n", "YES\n.....\n.###.\n.....\n.....\n" ]
none
1,000
[ { "input": "7 2", "output": "YES\n.......\n.#.....\n.#.....\n......." }, { "input": "5 3", "output": "YES\n.....\n.###.\n.....\n....." }, { "input": "3 2", "output": "YES\n...\n.#.\n.#.\n..." }, { "input": "3 0", "output": "YES\n...\n...\n...\n..." }, { "input": "49 1", "output": "YES\n.................................................\n........................#........................\n.................................................\n................................................." }, { "input": "9 4", "output": "YES\n.........\n.##......\n.##......\n........." }, { "input": "9 5", "output": "YES\n.........\n.#.#.....\n.###.....\n........." }, { "input": "99 193", "output": "YES\n...................................................................................................\n.###############################################################################################.#.\n.#################################################################################################.\n..................................................................................................." }, { "input": "99 14", "output": "YES\n...................................................................................................\n.#######...........................................................................................\n.#######...........................................................................................\n..................................................................................................." }, { "input": "57 15", "output": "YES\n.........................................................\n.######.#................................................\n.########................................................\n........................................................." }, { "input": "99 3", "output": "YES\n...................................................................................................\n................................................###................................................\n...................................................................................................\n..................................................................................................." }, { "input": "3 1", "output": "YES\n...\n.#.\n...\n..." }, { "input": "9 9", "output": "YES\n.........\n.###.#...\n.#####...\n........." }, { "input": "67 9", "output": "YES\n...................................................................\n.###.#.............................................................\n.#####.............................................................\n..................................................................." }, { "input": "99 99", "output": "YES\n...................................................................................................\n.################################################.#................................................\n.##################################################................................................\n..................................................................................................." }, { "input": "31 32", "output": "YES\n...............................\n.################..............\n.################..............\n..............................." }, { "input": "5 1", "output": "YES\n.....\n..#..\n.....\n....." }, { "input": "5 2", "output": "YES\n.....\n.#...\n.#...\n....." }, { "input": "5 4", "output": "YES\n.....\n.##..\n.##..\n....." }, { "input": "5 6", "output": "YES\n.....\n.###.\n.###.\n....." }, { "input": "5 5", "output": "YES\n.....\n.#.#.\n.###.\n....." }, { "input": "7 9", "output": "YES\n.......\n.###.#.\n.#####.\n......." }, { "input": "7 10", "output": "YES\n.......\n.#####.\n.#####.\n......." }, { "input": "19 12", "output": "YES\n...................\n.######............\n.######............\n..................." }, { "input": "19 3", "output": "YES\n...................\n........###........\n...................\n..................." }, { "input": "37 14", "output": "YES\n.....................................\n.#######.............................\n.#######.............................\n....................................." }, { "input": "37 15", "output": "YES\n.....................................\n.######.#............................\n.########............................\n....................................." }, { "input": "37 37", "output": "YES\n.....................................\n.#################.#.................\n.###################.................\n....................................." }, { "input": "37 36", "output": "YES\n.....................................\n.##################..................\n.##################..................\n....................................." }, { "input": "37 35", "output": "YES\n.....................................\n.################.#..................\n.##################..................\n....................................." }, { "input": "37 34", "output": "YES\n.....................................\n.#################...................\n.#################...................\n....................................." }, { "input": "37 38", "output": "YES\n.....................................\n.###################.................\n.###################.................\n....................................." }, { "input": "37 39", "output": "YES\n.....................................\n.##################.#................\n.####################................\n....................................." }, { "input": "37 40", "output": "YES\n.....................................\n.####################................\n.####################................\n....................................." }, { "input": "5 0", "output": "YES\n.....\n.....\n.....\n....." }, { "input": "67 1", "output": "YES\n...................................................................\n.................................#.................................\n...................................................................\n..................................................................." }, { "input": "37 19", "output": "YES\n.....................................\n.########.#..........................\n.##########..........................\n....................................." }, { "input": "77 7", "output": "YES\n.............................................................................\n.##.#........................................................................\n.####........................................................................\n............................................................................." }, { "input": "33 47", "output": "YES\n.................................\n.######################.#........\n.########################........\n................................." }, { "input": "33 48", "output": "YES\n.................................\n.########################........\n.########################........\n................................." }, { "input": "23 40", "output": "YES\n.......................\n.####################..\n.####################..\n......................." }, { "input": "23 39", "output": "YES\n.......................\n.##################.#..\n.####################..\n......................." }, { "input": "49 3", "output": "YES\n.................................................\n.......................###.......................\n.................................................\n................................................." }, { "input": "99 1", "output": "YES\n...................................................................................................\n.................................................#.................................................\n...................................................................................................\n..................................................................................................." }, { "input": "77 0", "output": "YES\n.............................................................................\n.............................................................................\n.............................................................................\n............................................................................." }, { "input": "99 0", "output": "YES\n...................................................................................................\n...................................................................................................\n...................................................................................................\n..................................................................................................." }, { "input": "99 5", "output": "YES\n...................................................................................................\n.#.#...............................................................................................\n.###...............................................................................................\n..................................................................................................." }, { "input": "99 4", "output": "YES\n...................................................................................................\n.##................................................................................................\n.##................................................................................................\n..................................................................................................." }, { "input": "99 20", "output": "YES\n...................................................................................................\n.##########........................................................................................\n.##########........................................................................................\n..................................................................................................." }, { "input": "99 194", "output": "YES\n...................................................................................................\n.#################################################################################################.\n.#################################################################################################.\n..................................................................................................." }, { "input": "99 192", "output": "YES\n...................................................................................................\n.################################################################################################..\n.################################################################################################..\n..................................................................................................." }, { "input": "99 190", "output": "YES\n...................................................................................................\n.###############################################################################################...\n.###############################################################################################...\n..................................................................................................." }, { "input": "99 189", "output": "YES\n...................................................................................................\n.#############################################################################################.#...\n.###############################################################################################...\n..................................................................................................." }, { "input": "99 177", "output": "YES\n...................................................................................................\n.#######################################################################################.#.........\n.#########################################################################################.........\n..................................................................................................." }, { "input": "99 154", "output": "YES\n...................................................................................................\n.#############################################################################.....................\n.#############################################################################.....................\n..................................................................................................." }, { "input": "99 127", "output": "YES\n...................................................................................................\n.##############################################################.#..................................\n.################################################################..................................\n..................................................................................................." }, { "input": "99 55", "output": "YES\n...................................................................................................\n.##########################.#......................................................................\n.############################......................................................................\n..................................................................................................." }, { "input": "99 40", "output": "YES\n...................................................................................................\n.####################..............................................................................\n.####################..............................................................................\n..................................................................................................." }, { "input": "97 190", "output": "YES\n.................................................................................................\n.###############################################################################################.\n.###############################################################################################.\n................................................................................................." }, { "input": "97 100", "output": "YES\n.................................................................................................\n.##################################################..............................................\n.##################################################..............................................\n................................................................................................." }, { "input": "97 111", "output": "YES\n.................................................................................................\n.######################################################.#........................................\n.########################################################........................................\n................................................................................................." }, { "input": "97 64", "output": "YES\n.................................................................................................\n.################################................................................................\n.################################................................................................\n................................................................................................." }, { "input": "97 77", "output": "YES\n.................................................................................................\n.#####################################.#.........................................................\n.#######################################.........................................................\n................................................................................................." }, { "input": "91 77", "output": "YES\n...........................................................................................\n.#####################################.#...................................................\n.#######################################...................................................\n..........................................................................................." }, { "input": "91 128", "output": "YES\n...........................................................................................\n.################################################################..........................\n.################################################################..........................\n..........................................................................................." }, { "input": "91 113", "output": "YES\n...........................................................................................\n.#######################################################.#.................................\n.#########################################################.................................\n..........................................................................................." }, { "input": "55 55", "output": "YES\n.......................................................\n.##########################.#..........................\n.############################..........................\n......................................................." }, { "input": "43 34", "output": "YES\n...........................................\n.#################.........................\n.#################.........................\n..........................................." }, { "input": "13 21", "output": "YES\n.............\n.#########.#.\n.###########.\n............." }, { "input": "27 50", "output": "YES\n...........................\n.#########################.\n.#########################.\n..........................." }, { "input": "27 49", "output": "YES\n...........................\n.#######################.#.\n.#########################.\n..........................." }, { "input": "27 48", "output": "YES\n...........................\n.########################..\n.########################..\n..........................." }, { "input": "27 40", "output": "YES\n...........................\n.####################......\n.####################......\n..........................." }, { "input": "87 80", "output": "YES\n.......................................................................................\n.########################################..............................................\n.########################################..............................................\n......................................................................................." }, { "input": "69 17", "output": "YES\n.....................................................................\n.#######.#...........................................................\n.#########...........................................................\n....................................................................." }, { "input": "39 73", "output": "YES\n.......................................\n.###################################.#.\n.#####################################.\n......................................." }, { "input": "39 72", "output": "YES\n.......................................\n.####################################..\n.####################################..\n......................................." }, { "input": "33 57", "output": "YES\n.................................\n.###########################.#...\n.#############################...\n................................." }, { "input": "33 54", "output": "YES\n.................................\n.###########################.....\n.###########################.....\n................................." }, { "input": "99 2", "output": "YES\n...................................................................................................\n.#.................................................................................................\n.#.................................................................................................\n..................................................................................................." }, { "input": "99 7", "output": "YES\n...................................................................................................\n.##.#..............................................................................................\n.####..............................................................................................\n..................................................................................................." }, { "input": "99 37", "output": "YES\n...................................................................................................\n.#################.#...............................................................................\n.###################...............................................................................\n..................................................................................................." }, { "input": "57 67", "output": "YES\n.........................................................\n.################################.#......................\n.##################################......................\n........................................................." }, { "input": "57 34", "output": "YES\n.........................................................\n.#################.......................................\n.#################.......................................\n........................................................." }, { "input": "73 17", "output": "YES\n.........................................................................\n.#######.#...............................................................\n.#########...............................................................\n........................................................................." }, { "input": "73 43", "output": "YES\n.........................................................................\n.####################.#..................................................\n.######################..................................................\n........................................................................." }, { "input": "7 3", "output": "YES\n.......\n..###..\n.......\n......." }, { "input": "7 7", "output": "YES\n.......\n.##.#..\n.####..\n......." } ]
1,525,797,832
5,931
Python 3
WRONG_ANSWER
PRETESTS
4
78
7,065,600
r, o = (int(i) for i in input().split()) print('YES') rm = [['.' for i in range(r)], ['.' for i in range(r)], ['.' for i in range(r)], ['.' for i in range(r)]] if o % 2 == 0: for i in range(o // 2): rm[1][i + 1] = '#' rm[2][i + 1] = '#' elif o <= r - 2: for i in range(1, o + 1, 1): rm[1][i] = '#' else: for i in range(1, r - 1, 1): rm[1][i] = '#' rm[2][1] = '#' rm[2][r - 2] = '#' for i in range(2, o - r + 2, 1): rm[2][i] = '#' for tr in rm: print(*tr, sep='')
Title: Marlin Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the Salmon pond at $(1, n)$. The mayor of Fishtopia wants to place $k$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells. A person can move from one cell to another if those cells are not occupied by hotels and share a side. Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond? Input Specification: The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is odd, the width of the city, and the number of hotels to be placed, respectively. Output Specification: Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "#" if that cell has a hotel on it, or "." if not. Demo Input: ['7 2\n', '5 3\n'] Demo Output: ['YES\n.......\n.#.....\n.#.....\n.......\n', 'YES\n.....\n.###.\n.....\n.....\n'] Note: none
```python r, o = (int(i) for i in input().split()) print('YES') rm = [['.' for i in range(r)], ['.' for i in range(r)], ['.' for i in range(r)], ['.' for i in range(r)]] if o % 2 == 0: for i in range(o // 2): rm[1][i + 1] = '#' rm[2][i + 1] = '#' elif o <= r - 2: for i in range(1, o + 1, 1): rm[1][i] = '#' else: for i in range(1, r - 1, 1): rm[1][i] = '#' rm[2][1] = '#' rm[2][r - 2] = '#' for i in range(2, o - r + 2, 1): rm[2][i] = '#' for tr in rm: print(*tr, sep='') ```
0
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", "output": "9" }, { "input": "10\n10 5 8 9 5 6 8 7 2 8", "output": "46" }, { "input": "10\n1 1 1 1 1 1 2 3 4 4", "output": "14" }, { "input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4", "output": "296" }, { "input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2", "output": "313" }, { "input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9", "output": "298" }, { "input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5", "output": "312" }, { "input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2", "output": "287" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2", "output": "265" }, { "input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9", "output": "328" }, { "input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9", "output": "324" }, { "input": "10\n7 4 5 3 9 1 10 3 4 5", "output": "34" }, { "input": "10\n8 9 6 5 6 4 10 9 1 4", "output": "39" }, { "input": "10\n1 7 1 4 9 10 8 2 9 9", "output": "40" }, { "input": "1\n100000", "output": "100000" } ]
1,675,515,105
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
4,505,600
def mode(a): a.sort(reverse=True) allocation = {} for i in a: if i not in allocation: allocation[i] = 0 allocation[i] += 1 return max(allocation, key=allocation.get) def move(a, k): tmp1 = list() for element in a: if not ((element == k - 1) or (element == k + 1)): tmp1.append(element) tmp1.remove(k) return tmp1 def main(a): main_score = 0 iterations = 0 while len(a) > 0: k = mode(a) a = move(a, k) main_score += k return main_score n = int(input()) a = list(map(int, input().split())) print(main(a))
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python def mode(a): a.sort(reverse=True) allocation = {} for i in a: if i not in allocation: allocation[i] = 0 allocation[i] += 1 return max(allocation, key=allocation.get) def move(a, k): tmp1 = list() for element in a: if not ((element == k - 1) or (element == k + 1)): tmp1.append(element) tmp1.remove(k) return tmp1 def main(a): main_score = 0 iterations = 0 while len(a) > 0: k = mode(a) a = move(a, k) main_score += k return main_score n = int(input()) a = list(map(int, input().split())) print(main(a)) ```
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,695,701,447
2,147,483,647
PyPy 3-64
OK
TESTS
15
62
0
number = input() list = number.split() cost = int(list[0]) money = int(list[1]) want = int(list[2]) for i in range(want): current_cost = cost*(i + 1) money -= current_cost if money < 0: money *= -1 print(money) else: print(0)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python number = input() list = number.split() cost = int(list[0]) money = int(list[1]) want = int(list[2]) for i in range(want): current_cost = cost*(i + 1) money -= current_cost if money < 0: money *= -1 print(money) else: print(0) ```
3
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes).
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth", "output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv", "output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES" }, { "input": "1\nz", "output": "NO" }, { "input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO" }, { "input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr", "output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES" }, { "input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES" }, { "input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO\nNO\nNO" }, { "input": "2\nab\nba", "output": "NO\nNO" }, { "input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", "output": "NO\nYES" }, { "input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,584,385,794
2,147,483,647
Python 3
OK
TESTS
55
124
0
n=int(input()) a=[] for i in range(n): c=0 a.append(input()) for j in range(0,i): if j!=i: if a[i]==a[j]: c+=1 if c>0: print("YES") else: print("NO")
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes). Input Specification: First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. Output Specification: Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower). Demo Input: ['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n'] Demo Output: ['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n'] Note: In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
```python n=int(input()) a=[] for i in range(n): c=0 a.append(input()) for j in range(0,i): if j!=i: if a[i]==a[j]: c+=1 if c>0: print("YES") else: print("NO") ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,443,190,151
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
def main(): mode="file" if mode=="file":f=open("test.txt","r") #f.readline() #input() get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [a]=get() [b]=get() cc=a+b a=list(str(a)) if "0" in a:a.remove("0") a=int("".join(a)) b=list(str(b)) if "0" in b:b.remove("0") b=int("".join(b)) c=list(str(cc)) if "0" in c:c.remove("0") c=int("".join(c)) cc=a+b print("YES" if c==cc else "NO") if mode=="file":f.close() if __name__=="__main__": main()
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python def main(): mode="file" if mode=="file":f=open("test.txt","r") #f.readline() #input() get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] [a]=get() [b]=get() cc=a+b a=list(str(a)) if "0" in a:a.remove("0") a=int("".join(a)) b=list(str(b)) if "0" in b:b.remove("0") b=int("".join(b)) c=list(str(cc)) if "0" in c:c.remove("0") c=int("".join(c)) cc=a+b print("YES" if c==cc else "NO") if mode=="file":f.close() if __name__=="__main__": main() ```
-1
849
A
Odds and Ends
PROGRAMMING
1,000
[ "implementation" ]
null
null
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not.
The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence.
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).
[ "3\n1 3 5\n", "5\n1 0 1 5 1\n", "3\n4 3 1\n", "4\n3 9 9 3\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n" ]
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
500
[ { "input": "3\n1 3 5", "output": "Yes" }, { "input": "5\n1 0 1 5 1", "output": "Yes" }, { "input": "3\n4 3 1", "output": "No" }, { "input": "4\n3 9 9 3", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "5\n100 99 100 99 99", "output": "No" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "2\n1 1", "output": "No" }, { "input": "2\n10 10", "output": "No" }, { "input": "2\n54 21", "output": "No" }, { "input": "5\n0 0 0 0 0", "output": "No" }, { "input": "5\n67 92 0 26 43", "output": "Yes" }, { "input": "15\n45 52 35 80 68 80 93 57 47 32 69 23 63 90 43", "output": "Yes" }, { "input": "15\n81 28 0 82 71 64 63 89 87 92 38 30 76 72 36", "output": "No" }, { "input": "50\n49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99", "output": "No" }, { "input": "55\n65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46", "output": "No" }, { "input": "99\n73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69", "output": "Yes" }, { "input": "99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "output": "Yes" }, { "input": "100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83", "output": "No" }, { "input": "6\n1 2 2 2 2 1", "output": "No" }, { "input": "3\n1 2 1", "output": "Yes" }, { "input": "4\n1 3 2 3", "output": "No" }, { "input": "6\n1 1 1 1 1 1", "output": "No" }, { "input": "6\n1 1 0 0 1 1", "output": "No" }, { "input": "4\n1 4 9 3", "output": "No" }, { "input": "4\n1 0 1 1", "output": "No" }, { "input": "10\n1 0 0 1 1 1 1 1 1 1", "output": "No" }, { "input": "10\n9 2 5 7 8 3 1 9 4 9", "output": "No" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "output": "No" }, { "input": "6\n1 2 1 2 2 1", "output": "No" }, { "input": "6\n1 0 1 0 0 1", "output": "No" }, { "input": "4\n1 3 4 7", "output": "No" }, { "input": "8\n1 1 1 2 1 1 1 1", "output": "No" }, { "input": "3\n1 1 2", "output": "No" }, { "input": "5\n1 2 1 2 1", "output": "Yes" }, { "input": "5\n5 4 4 2 1", "output": "Yes" }, { "input": "6\n1 3 3 3 3 1", "output": "No" }, { "input": "7\n1 2 1 2 2 2 1", "output": "Yes" }, { "input": "4\n1 2 2 1", "output": "No" }, { "input": "6\n1 2 3 4 6 5", "output": "No" }, { "input": "5\n1 1 2 2 2", "output": "No" }, { "input": "5\n1 0 0 1 1", "output": "Yes" }, { "input": "3\n1 2 4", "output": "No" }, { "input": "3\n1 0 2", "output": "No" }, { "input": "5\n1 1 1 0 1", "output": "Yes" }, { "input": "4\n3 9 2 3", "output": "No" }, { "input": "6\n1 1 1 4 4 1", "output": "No" }, { "input": "6\n1 2 3 5 6 7", "output": "No" }, { "input": "6\n1 1 1 2 2 1", "output": "No" }, { "input": "6\n1 1 1 0 0 1", "output": "No" }, { "input": "5\n1 2 2 5 5", "output": "Yes" }, { "input": "5\n1 3 2 4 5", "output": "Yes" }, { "input": "8\n1 2 3 5 7 8 8 5", "output": "No" }, { "input": "10\n1 1 1 2 1 1 1 1 1 1", "output": "No" }, { "input": "4\n1 0 0 1", "output": "No" }, { "input": "7\n1 0 1 1 0 0 1", "output": "Yes" }, { "input": "7\n1 4 5 7 6 6 3", "output": "Yes" }, { "input": "4\n2 2 2 2", "output": "No" }, { "input": "5\n2 3 4 5 6", "output": "No" }, { "input": "4\n1 1 2 1", "output": "No" }, { "input": "3\n1 2 3", "output": "Yes" }, { "input": "6\n1 3 3 2 2 3", "output": "No" }, { "input": "4\n1 1 2 3", "output": "No" }, { "input": "4\n1 2 3 5", "output": "No" }, { "input": "5\n3 4 4 3 3", "output": "Yes" }, { "input": "4\n3 2 2 3", "output": "No" }, { "input": "6\n1 1 1 1 2 1", "output": "No" }, { "input": "6\n1 1 2 2 1 1", "output": "No" }, { "input": "10\n3 4 2 4 3 2 2 4 4 3", "output": "No" }, { "input": "7\n1 2 4 3 2 4 5", "output": "Yes" }, { "input": "28\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67", "output": "No" }, { "input": "79\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18", "output": "No" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "No" } ]
1,504,274,939
2,039
Python 3
WRONG_ANSWER
TESTS
13
62
0
n=int(input()) l=[int(i) for i in input().split()] count=0 number=0 flag=0 for i in range(n): if (count==0): if (l[i]%2 !=0): count+=1 else: print ("No") flag=1 break elif (count%2!=0): if (l[i]%2==0): count+=1 else: count=1 number+=1 else: if (l[i]%2!=0): count=0 number+=1 else: count+=1 if (count%2!=0): number+=1 if (flag==0): if (number%2!=0): print ('Yes') elif (number%2==0 or (count%2==0 and count!=0)): print ('No')
Title: Odds and Ends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not. Input Specification: The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. Output Specification: Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower). Demo Input: ['3\n1 3 5\n', '5\n1 0 1 5 1\n', '3\n4 3 1\n', '4\n3 9 9 3\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n', 'No\n'] Note: In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
```python n=int(input()) l=[int(i) for i in input().split()] count=0 number=0 flag=0 for i in range(n): if (count==0): if (l[i]%2 !=0): count+=1 else: print ("No") flag=1 break elif (count%2!=0): if (l[i]%2==0): count+=1 else: count=1 number+=1 else: if (l[i]%2!=0): count=0 number+=1 else: count+=1 if (count%2!=0): number+=1 if (flag==0): if (number%2!=0): print ('Yes') elif (number%2==0 or (count%2==0 and count!=0)): print ('No') ```
0
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100", "output": "1824868942000000000000000000000000000000000000000000000000000" }, { "input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000", "output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "9" }, { "input": "2\n10 50", "output": "500" }, { "input": "3\n500 1 10", "output": "5000" } ]
1,521,471,673
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
500
7,987,200
from functools import reduce i = int(input()) lis = list(map(int,input().split())) print(reduce(lambda x,y:x*y,lis))
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. Input Specification: The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. Output Specification: Print a single number without leading zeroes — the product of the number of tanks presented by each country. Demo Input: ['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n'] Demo Output: ['50', '110', '0'] Note: In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
```python from functools import reduce i = int(input()) lis = list(map(int,input().split())) print(reduce(lambda x,y:x*y,lis)) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,682,502,797
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
46
186
0
num = int(input()) var = "" num_1 = 0 num_2 = 0 num_3 = 0 for i in range(1, num+1): values = input() var = var + values + "," newVar = var.split(",") for i in range(0, num): x = newVar[i].split(" ") num_1 = num_1 + int(x[0]) num_2 = num_2 + int(x[1]) num_3 = num_3 + int(x[2]) if num_1 == num_2 and num_2 == num_3: k = bool(num_1) if k == False: 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 num = int(input()) var = "" num_1 = 0 num_2 = 0 num_3 = 0 for i in range(1, num+1): values = input() var = var + values + "," newVar = var.split(",") for i in range(0, num): x = newVar[i].split(" ") num_1 = num_1 + int(x[0]) num_2 = num_2 + int(x[1]) num_3 = num_3 + int(x[2]) if num_1 == num_2 and num_2 == num_3: k = bool(num_1) if k == False: print("YES") else: print("NO") ```
0
409
H
A + B Strikes Back
PROGRAMMING
1,500
[ "*special", "brute force", "constructive algorithms", "dsu", "implementation" ]
null
null
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output the sum of the given integers.
[ "5 14\n", "381 492\n" ]
[ "19\n", "873\n" ]
none
0
[ { "input": "5 14", "output": "19" }, { "input": "381 492", "output": "873" }, { "input": "536 298", "output": "834" }, { "input": "143 522", "output": "665" }, { "input": "433 126", "output": "559" }, { "input": "723 350", "output": "1073" }, { "input": "632 264", "output": "896" }, { "input": "923 488", "output": "1411" }, { "input": "522 92", "output": "614" }, { "input": "953 553", "output": "1506" }, { "input": "242 86", "output": "328" }, { "input": "151 691", "output": "842" }, { "input": "441 915", "output": "1356" }, { "input": "740 519", "output": "1259" }, { "input": "339 433", "output": "772" }, { "input": "629 657", "output": "1286" }, { "input": "538 261", "output": "799" }, { "input": "828 485", "output": "1313" }, { "input": "117 399", "output": "516" }, { "input": "399 280", "output": "679" } ]
1,674,205,903
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a, i = map(int, input()) print(a+i)
Title: A + B Strikes Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input Specification: The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. Output Specification: Output the sum of the given integers. Demo Input: ['5 14\n', '381 492\n'] Demo Output: ['19\n', '873\n'] Note: none
```python a, i = map(int, input()) print(a+i) ```
-1
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,614,438,233
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
d1, d2, d3 = [int(x) for x in input().split()] w1 = 2*(d1+d2) w2=d1+d2+d3 print(min(w1,w2))
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 d1, d2, d3 = [int(x) for x in input().split()] w1 = 2*(d1+d2) w2=d1+d2+d3 print(min(w1,w2)) ```
0
902
B
Coloring a Tree
PROGRAMMING
1,200
[ "dfs and similar", "dsu", "greedy" ]
null
null
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*. It is guaranteed that you have to color each vertex in a color different from 0. You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)).
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*. The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into. It is guaranteed that the given graph is a tree.
Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.
[ "6\n1 2 2 1 5\n2 1 1 1 1 1\n", "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n" ]
[ "3\n", "5\n" ]
The tree from the first sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/> On seond step we color all vertices in the subtree of vertex 5 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 2 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/> The tree from the second sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/> On second step we color all vertices in the subtree of vertex 3 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 6 into color 2: <img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fourth step we color all vertices in the subtree of vertex 4 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fith step we color all vertices in the subtree of vertex 7 into color 3: <img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6\n1 2 2 1 5\n2 1 1 1 1 1", "output": "3" }, { "input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "output": "5" }, { "input": "2\n1\n2 2", "output": "1" }, { "input": "3\n1 1\n2 2 2", "output": "1" }, { "input": "4\n1 2 1\n1 2 3 4", "output": "4" }, { "input": "4\n1 2 3\n4 1 2 4", "output": "4" }, { "input": "5\n1 2 1 4\n1 1 1 2 2", "output": "2" }, { "input": "3\n1 2\n2 1 1", "output": "2" }, { "input": "4\n1 1 1\n3 1 3 1", "output": "3" }, { "input": "4\n1 1 2\n4 1 4 1", "output": "2" }, { "input": "4\n1 2 2\n3 1 2 3", "output": "4" }, { "input": "3\n1 1\n1 2 2", "output": "3" } ]
1,513,700,454
2,754
Python 3
OK
TESTS
50
92
6,963,200
N = int(input()) con = [0] vert = [i for i in range(1,N+1)] a = input().split(" ") for i in range(N-1): con.append(int(a[i])-1) color=[] a = input().split(" ") for i in range(N): color.append(int(a[i])) cur = [color[0] for i in range(N)] steps=1 for i in range(1,N): if cur[con[i]]==color[i]: cur[i] = color[i] else: steps+=1 cur[i] = color[i] print(steps) #print(con) #print(color) #print(vert)
Title: Coloring a Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*. It is guaranteed that you have to color each vertex in a color different from 0. You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)). Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*. The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into. It is guaranteed that the given graph is a tree. Output Specification: Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. Demo Input: ['6\n1 2 2 1 5\n2 1 1 1 1 1\n', '7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n'] Demo Output: ['3\n', '5\n'] Note: The tree from the first sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/> On seond step we color all vertices in the subtree of vertex 5 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 2 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/> The tree from the second sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/> On second step we color all vertices in the subtree of vertex 3 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 6 into color 2: <img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fourth step we color all vertices in the subtree of vertex 4 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fith step we color all vertices in the subtree of vertex 7 into color 3: <img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python N = int(input()) con = [0] vert = [i for i in range(1,N+1)] a = input().split(" ") for i in range(N-1): con.append(int(a[i])-1) color=[] a = input().split(" ") for i in range(N): color.append(int(a[i])) cur = [color[0] for i in range(N)] steps=1 for i in range(1,N): if cur[con[i]]==color[i]: cur[i] = color[i] else: steps+=1 cur[i] = color[i] print(steps) #print(con) #print(color) #print(vert) ```
3
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,547,691,758
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
4,300,800
import math import queue from itertools import permutations n=int(input()) m=0 i=0 while n!=0: m+=(n%10)*pow(2,i) i+=1 n//=10 n=m answer=0 while n!=1: if n%2==0: n//=2 else: n+=1 answer+=1 print(answer)
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 import math import queue from itertools import permutations n=int(input()) m=0 i=0 while n!=0: m+=(n%10)*pow(2,i) i+=1 n//=10 n=m answer=0 while n!=1: if n%2==0: n//=2 else: n+=1 answer+=1 print(answer) ```
0
0
none
none
none
0
[ "none" ]
null
null
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments. After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process. Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000). Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
After each cut print on a single line the area of the maximum available glass fragment in mm2.
[ "4 3 4\nH 2\nV 2\nV 3\nV 1\n", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n" ]
[ "8\n4\n4\n2\n", "28\n16\n12\n6\n4\n" ]
Picture for the first sample test:
0
[ { "input": "4 3 4\nH 2\nV 2\nV 3\nV 1", "output": "8\n4\n4\n2" }, { "input": "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "output": "28\n16\n12\n6\n4" }, { "input": "2 2 1\nV 1", "output": "2" }, { "input": "2 2 1\nH 1", "output": "2" }, { "input": "2 2 2\nV 1\nH 1", "output": "2\n1" }, { "input": "2 2 2\nH 1\nV 1", "output": "2\n1" }, { "input": "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7", "output": "60\n48\n32\n32\n24\n12\n12\n12\n8\n8" }, { "input": "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3", "output": "40\n40\n32\n24\n24\n24\n24\n18\n12\n8" }, { "input": "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4\nH 3", "output": "65\n50\n35\n21\n18\n12\n12\n12\n9\n6" }, { "input": "2 3 1\nH 1", "output": "4" }, { "input": "200000 200000 1\nH 1", "output": "39999800000" }, { "input": "2 4 1\nH 2", "output": "4" } ]
1,691,611,355
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691611355.33468")# 1691611355.334696
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments. After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process. Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree? Input Specification: The first line contains three integers *w*,<=*h*,<=*n* (2<=≤<=*w*,<=*h*<=≤<=200<=000, 1<=≤<=*n*<=≤<=200<=000). Next *n* lines contain the descriptions of the cuts. Each description has the form *H* *y* or *V* *x*. In the first case Leonid makes the horizontal cut at the distance *y* millimeters (1<=≤<=*y*<=≤<=*h*<=-<=1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance *x* (1<=≤<=*x*<=≤<=*w*<=-<=1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts. Output Specification: After each cut print on a single line the area of the maximum available glass fragment in mm2. Demo Input: ['4 3 4\nH 2\nV 2\nV 3\nV 1\n', '7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n'] Demo Output: ['8\n4\n4\n2\n', '28\n16\n12\n6\n4\n'] Note: Picture for the first sample test:
```python print("_RANDOM_GUESS_1691611355.33468")# 1691611355.334696 ```
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,689,222,558
2,147,483,647
Python 3
OK
TESTS
39
92
0
n = int(input()) lst = list(map(int,input().split())) a=0 b=100 max_ind=0 min_ind=0 for i in range(n): if lst[i]>a: a=lst[i] max_ind = i if lst[i]<=b: b = lst[i] min_ind = i if max_ind<min_ind: print(max_ind+(n-min_ind)-1) else: print(max_ind+((n-min_ind)-2))
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()) lst = list(map(int,input().split())) a=0 b=100 max_ind=0 min_ind=0 for i in range(n): if lst[i]>a: a=lst[i] max_ind = i if lst[i]<=b: b = lst[i] min_ind = i if max_ind<min_ind: print(max_ind+(n-min_ind)-1) else: print(max_ind+((n-min_ind)-2)) ```
3
578
B
"Or" Game
PROGRAMMING
1,700
[ "brute force", "greedy" ]
null
null
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally.
The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output the maximum value of a bitwise OR of sequence elements after performing operations.
[ "3 1 2\n1 1 1\n", "4 2 3\n1 2 4 8\n" ]
[ "3\n", "79\n" ]
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
500
[ { "input": "3 1 2\n1 1 1", "output": "3" }, { "input": "4 2 3\n1 2 4 8", "output": "79" }, { "input": "2 1 2\n12 9", "output": "30" }, { "input": "2 1 2\n12 7", "output": "31" }, { "input": "3 1 3\n3 2 0", "output": "11" }, { "input": "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1073741825000000000" }, { "input": "1 2 3\n612635770", "output": "5513721930" }, { "input": "3 2 5\n0 2 3", "output": "75" }, { "input": "2 1 8\n18 17", "output": "154" }, { "input": "5 10 8\n0 0 0 0 0", "output": "0" }, { "input": "1 1 2\n1", "output": "2" }, { "input": "1 1 2\n0", "output": "0" }, { "input": "3 2 6\n724148075 828984987 810015532", "output": "29996605423" }, { "input": "3 1 2\n17 18 4", "output": "54" }, { "input": "3 1 2\n4 17 18", "output": "54" }, { "input": "2 2 2\n60 59", "output": "252" }, { "input": "2 2 2\n9 10", "output": "46" }, { "input": "3 1 2\n10 12 5", "output": "31" }, { "input": "3 1 2\n20 17 8", "output": "62" }, { "input": "3 1 2\n5 12 10", "output": "31" }, { "input": "3 1 8\n10 17 18", "output": "155" }, { "input": "3 1 2\n17 20 28", "output": "62" }, { "input": "5 1 3\n1 5 13 8 16", "output": "63" } ]
1,443,866,806
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
217
15,360,000
n, k, x = list(map(int, input().split())) a = list(map(int, input().split())) prefix = [0 for i in range(200001)] suffix = [0 for i in range(200001)] mul = x ** k for i in range(1, n + 1): prefix[i] = prefix[i-1] | a[i - 1]; for i in range(n, 0, -1): suffix[i] = suffix[i+1] | a[i - 1]; ans = 0 for i in range(1, n + 1): ans = max(ans, prefix[i-1] | (a[i - 1] * mul) | suffix[i+1]); print(ans);
Title: "Or" Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. Input Specification: The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Output the maximum value of a bitwise OR of sequence elements after performing operations. Demo Input: ['3 1 2\n1 1 1\n', '4 2 3\n1 2 4 8\n'] Demo Output: ['3\n', '79\n'] Note: For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
```python n, k, x = list(map(int, input().split())) a = list(map(int, input().split())) prefix = [0 for i in range(200001)] suffix = [0 for i in range(200001)] mul = x ** k for i in range(1, n + 1): prefix[i] = prefix[i-1] | a[i - 1]; for i in range(n, 0, -1): suffix[i] = suffix[i+1] | a[i - 1]; ans = 0 for i in range(1, n + 1): ans = max(ans, prefix[i-1] | (a[i - 1] * mul) | suffix[i+1]); print(ans); ```
-1
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3", "output": "125" }, { "input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5", "output": "480" }, { "input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4", "output": "240" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4", "output": "190" }, { "input": "1\n1\n100", "output": "515" }, { "input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90", "output": "41850" } ]
1,668,685,804
2,147,483,647
Python 3
OK
TESTS
20
46
0
def solve(): n = int(input()) ak = [int(i) for i in input().split()] ans = float("inf") for i in range(n): a = [int(k) for k in input().split()] s = 0 for j in range(len(a)): s+=a[j]*5 s+=15*ak[i] ans = min(ans,s) print(ans) return # t = int(input()) # for _ in range(t): # solve() solve()
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. Output Specification: Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. Demo Input: ['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n'] Demo Output: ['20\n', '100\n'] Note: In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
```python def solve(): n = int(input()) ak = [int(i) for i in input().split()] ans = float("inf") for i in range(n): a = [int(k) for k in input().split()] s = 0 for j in range(len(a)): s+=a[j]*5 s+=15*ak[i] ans = min(ans,s) print(ans) return # t = int(input()) # for _ in range(t): # solve() solve() ```
3
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
1,699,880,126
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
15,052,800
from sys import stdin def input(): return stdin.readline()[:-1] def ili(): return list(map(int, input().split())) import math from collections import defaultdict # def prime(k): # for i in range(2, math.isqrt(k)+1): # if k%i == 0: # return False # return True def check(n): d = defaultdict(lambda : 0) while n % 2 == 0: d[2] += 1 n = n // 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: d[i] += 1 n = n // i if n > 2: d[n] += 1 if len(d.keys()) == 1 and list(d.values())[0] == 2: return True return False def solve(): n = int(input()) s = ili() for i in s: if i == 1: print("NO") continue print("YES") if check(i) else print("NO") case_num = 1 # case_num = int(input()) for case in range(case_num): solve()
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. Input Specification: The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output Specification: Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. Demo Input: ['3\n4 5 6\n'] Demo Output: ['YES\nNO\nNO\n'] Note: The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
```python from sys import stdin def input(): return stdin.readline()[:-1] def ili(): return list(map(int, input().split())) import math from collections import defaultdict # def prime(k): # for i in range(2, math.isqrt(k)+1): # if k%i == 0: # return False # return True def check(n): d = defaultdict(lambda : 0) while n % 2 == 0: d[2] += 1 n = n // 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: d[i] += 1 n = n // i if n > 2: d[n] += 1 if len(d.keys()) == 1 and list(d.values())[0] == 2: return True return False def solve(): n = int(input()) s = ili() for i in s: if i == 1: print("NO") continue print("YES") if check(i) else print("NO") case_num = 1 # case_num = int(input()) for case in range(case_num): solve() ```
0