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
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50", "output": "49" }, { "input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2", "output": "-1" }, { "input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90", "output": "46" }, { "input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66", "output": "14" }, { "input": "1 1\n4\n9", "output": "8" }, { "input": "1 1\n2\n4", "output": "-1" }, { "input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58", "output": "-1" }, { "input": "1 1\n50\n100", "output": "-1" }, { "input": "1 1\n49\n100", "output": "98" }, { "input": "1 1\n100\n100", "output": "-1" }, { "input": "1 1\n99\n100", "output": "-1" }, { "input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100", "output": "99" }, { "input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2", "output": "-1" }, { "input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75", "output": "2" }, { "input": "3 3\n2 3 4\n8 9 10", "output": "4" }, { "input": "2 1\n2 3\n15", "output": "4" }, { "input": "2 1\n2 4\n4", "output": "-1" }, { "input": "2 3\n4 5\n10 11 12", "output": "8" }, { "input": "3 1\n2 3 3\n5", "output": "4" }, { "input": "2 1\n9 10\n100", "output": "18" }, { "input": "3 3\n3 12 15\n7 8 9", "output": "-1" }, { "input": "2 2\n3 5\n7 8", "output": "6" }, { "input": "3 3\n4 5 6\n10 11 12", "output": "8" }, { "input": "3 5\n2 3 3\n6 6 6 6 2", "output": "-1" }, { "input": "3 6\n4 5 3\n8 9 7 10 7 11", "output": "6" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 4", "output": "-1" }, { "input": "2 1\n4 6\n10", "output": "8" }, { "input": "1 2\n1\n3 1", "output": "-1" }, { "input": "2 1\n5 6\n20", "output": "10" }, { "input": "2 1\n1 5\n5", "output": "-1" }, { "input": "3 2\n10 20 30\n30 40", "output": "-1" }, { "input": "2 2\n5 6\n7 100", "output": "-1" }, { "input": "2 1\n2 5\n7", "output": "5" }, { "input": "1 1\n5\n20", "output": "10" }, { "input": "2 1\n10 11\n100", "output": "20" }, { "input": "1 1\n1\n10", "output": "2" }, { "input": "1 1\n10\n100", "output": "20" } ]
1,618,272,560
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
122
0
p,f = map(int,input().split()) tl = 0 lp = [int(x) for x in input().split()] lf = [int(x) for x in input().split()] ma = max(lp) if min(lf) <= ma: tl = -1 else: if min(lp)*2 <= ma: if min(lf) > ma: tl = ma else: tl = -1 print(tl)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python p,f = map(int,input().split()) tl = 0 lp = [int(x) for x in input().split()] lf = [int(x) for x in input().split()] ma = max(lp) if min(lf) <= ma: tl = -1 else: if min(lp)*2 <= ma: if min(lf) > ma: tl = ma else: tl = -1 print(tl) ```
0
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "output": "130" }, { "input": "900000000 16", "output": "1" }, { "input": "909090909 50", "output": "3" }, { "input": "1001 2", "output": "100" }, { "input": "5 2", "output": "3" }, { "input": "2 1", "output": "1" } ]
1,695,483,640
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
first_line=input().split() for i in range(int(first_line[1])): if int(first_line[0])%10==0: first_line[0]=int(first_line[0])/10 else: first_line[0] =int(first_line[0])-1 print(first_line[0])
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number. Input Specification: The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Specification: Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number. Demo Input: ['512 4\n', '1000000000 9\n'] Demo Output: ['50\n', '1\n'] Note: The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
```python first_line=input().split() for i in range(int(first_line[1])): if int(first_line[0])%10==0: first_line[0]=int(first_line[0])/10 else: first_line[0] =int(first_line[0])-1 print(first_line[0]) ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,696,065,323
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
77
2,150,400
socks, day_bought = map(int, input().split()) total_wear = socks total_wear = total_wear + socks//day_bought total_wear = total_wear + total//socks//day_bought print(total_wear)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python socks, day_bought = map(int, input().split()) total_wear = socks total_wear = total_wear + socks//day_bought total_wear = total_wear + total//socks//day_bought print(total_wear) ```
-1
545
D
Queue
PROGRAMMING
1,300
[ "greedy", "implementation", "sortings" ]
null
null
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Print a single number — the maximum number of not disappointed people in the queue.
[ "5\n15 2 1 5 3\n" ]
[ "4\n" ]
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
1,750
[ { "input": "5\n15 2 1 5 3", "output": "4" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10\n13 2 5 55 21 34 1 8 1 3", "output": "6" }, { "input": "10\n8 256 16 1 2 1 64 4 128 32", "output": "10" }, { "input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "output": "6" }, { "input": "1\n1000000000", "output": "1" }, { "input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "output": "6" }, { "input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064", "output": "5" }, { "input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697", "output": "21" } ]
1,697,890,732
2,147,483,647
Python 3
OK
TESTS
61
93
14,233,600
s=t=0 for i in sorted(map(int,[*open(0)][1].split())): if i>=s:t+=1;s+=i print(t)
Title: Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. Output Specification: Print a single number — the maximum number of not disappointed people in the queue. Demo Input: ['5\n15 2 1 5 3\n'] Demo Output: ['4\n'] Note: Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
```python s=t=0 for i in sorted(map(int,[*open(0)][1].split())): if i>=s:t+=1;s+=i print(t) ```
3
355
A
Vasya and Digital Root
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist.
The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9).
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
[ "4 4\n", "5 1\n", "1 0\n" ]
[ "5881\n", "36172\n", "0\n" ]
For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
500
[ { "input": "4 4", "output": "5881" }, { "input": "5 1", "output": "36172" }, { "input": "1 0", "output": "0" }, { "input": "8 7", "output": "49722154" }, { "input": "487 0", "output": "No solution" }, { "input": "1000 5", "output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..." }, { "input": "22 9", "output": "1583569962049529809017" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "13 5", "output": "1381199538344" }, { "input": "100 4", "output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478" }, { "input": "123 6", "output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343" }, { "input": "1000 1", "output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..." }, { "input": "2 0", "output": "No solution" }, { "input": "734 9", "output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..." }, { "input": "678 8", "output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..." }, { "input": "955 7", "output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..." }, { "input": "893 3", "output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..." }, { "input": "998 2", "output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..." }, { "input": "960 6", "output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..." } ]
1,690,339,736
2,147,483,647
Python 3
OK
TESTS
20
31
0
k,d=map(int,input().split(' ')) if (d==0 and k>1): print('No solution') else: print(str(d)+(k-1)*"0")
Title: Vasya and Digital Root Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. Input Specification: The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). Output Specification: In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. Demo Input: ['4 4\n', '5 1\n', '1 0\n'] Demo Output: ['5881\n', '36172\n', '0\n'] Note: For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
```python k,d=map(int,input().split(' ')) if (d==0 and k>1): print('No solution') else: print(str(d)+(k-1)*"0") ```
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "input": "24 22 9235", "output": "34" }, { "input": "74 8 417", "output": "1" }, { "input": "972 1 203", "output": "0" }, { "input": "550 1 754", "output": "1" }, { "input": "860 1 884", "output": "1" }, { "input": "358 2 809", "output": "2" }, { "input": "33 27 216", "output": "0" }, { "input": "2940 1 9311", "output": "3" }, { "input": "4624 1 1953", "output": "0" }, { "input": "2696 2 7345", "output": "2" }, { "input": "3443 2 6701", "output": "0" }, { "input": "3 613 2275", "output": "1" }, { "input": "1 10000 10000", "output": "1" }, { "input": "10000 1 10000", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1 10000", "output": "10000" }, { "input": "34 27 10000", "output": "10" }, { "input": "2 2 9999", "output": "4999" }, { "input": "2 2 1", "output": "0" }, { "input": "6 4 36", "output": "3" }, { "input": "33 6 3005", "output": "45" }, { "input": "5 1 20", "output": "4" }, { "input": "1 2 10", "output": "5" }, { "input": "2 1 100", "output": "50" }, { "input": "10 20 10000", "output": "500" }, { "input": "8 12 12", "output": "0" } ]
1,590,645,840
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
n = int(input()) home = input() flights = [] while n > 0: s, t = input().split("->") flights.append(s) flights.append(t) n -= 1 count = 0 for flight in flights: if flight == home: count += 1 if count % 2 == 0: print("home") else: print("contest")
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input Specification: The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). Output Specification: Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Demo Input: ['1 1 10\n', '1 2 5\n', '2 3 9\n'] Demo Output: ['10\n', '2\n', '1\n'] Note: Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
```python n = int(input()) home = input() flights = [] while n > 0: s, t = input().split("->") flights.append(s) flights.append(t) n -= 1 count = 0 for flight in flights: if flight == home: count += 1 if count % 2 == 0: print("home") else: print("contest") ```
-1
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,667,285,886
2,147,483,647
Python 3
OK
TESTS
40
46
0
a = str(input()) helo = ['h','e','l','l','o'] i = -1 for c in helo: i = a.find(c, i+1) if i == -1: print('NO') exit() print('YES')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a = str(input()) helo = ['h','e','l','l','o'] i = -1 for c in helo: i = a.find(c, i+1) if i == -1: print('NO') exit() print('YES') ```
3.977
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,666,775,048
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n = int(input()) m = int(input()) print(n * m / 2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python n = int(input()) m = int(input()) print(n * m / 2) ```
-1
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days?
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697681824", "output": "14" }, { "input": "41313494", "output": "14" }, { "input": "673935585", "output": "13" }, { "input": "117422204", "output": "19" }, { "input": "954746654", "output": "15" }, { "input": "536838144", "output": "14" }, { "input": "1000000000", "output": "13" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "1" }, { "input": "6", "output": "2" }, { "input": "7", "output": "3" }, { "input": "9", "output": "2" }, { "input": "10", "output": "2" }, { "input": "999999999", "output": "21" }, { "input": "999999998", "output": "20" }, { "input": "999999997", "output": "20" }, { "input": "999999996", "output": "19" }, { "input": "999999995", "output": "20" }, { "input": "999999994", "output": "19" }, { "input": "999999993", "output": "19" }, { "input": "999999992", "output": "18" }, { "input": "999999991", "output": "20" }, { "input": "999999990", "output": "19" }, { "input": "536870910", "output": "28" }, { "input": "536870912", "output": "1" }, { "input": "536870913", "output": "2" }, { "input": "536870914", "output": "2" }, { "input": "22", "output": "3" }, { "input": "14", "output": "3" } ]
1,679,720,745
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
b = int(input()) x = 1 while x <= b : x *= 2 x /= 2 print(int((b-x)+1))
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input Specification: The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). Output Specification: The only line containing one integer: the answer. Demo Input: ['5\n', '8\n'] Demo Output: ['2\n', '1\n'] Note: For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
```python b = int(input()) x = 1 while x <= b : x *= 2 x /= 2 print(int((b-x)+1)) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,693,791,384
2,147,483,647
Python 3
OK
TESTS
20
46
0
numero = int(input()) for _ in range(numero): palabra = input() # Lee una palabra if len(palabra) > 10: abbreviation = palabra[0] + str(len(palabra) - 2) + palabra[-1] print(abbreviation) else: print(palabra)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python numero = int(input()) for _ in range(numero): palabra = input() # Lee una palabra if len(palabra) > 10: abbreviation = palabra[0] + str(len(palabra) - 2) + palabra[-1] print(abbreviation) else: print(palabra) ```
3.977
152
C
Pocket Book
PROGRAMMING
1,400
[ "combinatorics" ]
null
null
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*, 1<=≤<=*k*<=≤<=*m*), then he took names number *i* and *j* and swapped their prefixes of length *k*. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers *i*, *j*, *k* independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109<=+<=7).
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters.
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7).
[ "2 3\nAAB\nBAA\n", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n" ]
[ "4\n", "216\n" ]
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
1,500
[ { "input": "2 3\nAAB\nBAA", "output": "4" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216" }, { "input": "1 1\nE", "output": "1" }, { "input": "2 2\nNS\nPD", "output": "4" }, { "input": "3 4\nPJKD\nNFJX\nFGFK", "output": "81" }, { "input": "4 5\nSXFMY\nATHLM\nKDDQW\nZWGDS", "output": "1024" }, { "input": "20 14\nJNFKBBBJYZHWQE\nLBOKZCPFNKDBJY\nXKNWGHQHIOXUPF\nDDNRUKVUGHWMXW\nMTIZFNAAFEAPHX\nIXBQOOHEULZYHU\nMRCSREUEOOMUUN\nHJTSQWKUFYZDQU\nGMCMUZCOPRVEIQ\nXBKKGGJECOBLTH\nXXHTLXCNJZJUAF\nVLJRKXXXWMTPKZ\nPTYMNPTBBCWKAD\nQYJGOBUBHMEDYE\nGTKUUVVNKAHTUI\nZNKXYZPCYLBZFP\nQCBLJTRMBDWNNE\nTDOKJOBKEOVNLZ\nFKZUITYAFJOQIM\nUWQNSGLXEEIRWF", "output": "515139391" }, { "input": "5 14\nAQRXUQQNSKZPGC\nDTTKSPFGGVCLPT\nVLZQWWESCHDTAZ\nCOKOWDWDRUOMHP\nXDTRBIZTTCIDGS", "output": "124999979" }, { "input": "9 23\nOILBYKHRGMPENVFNHLSIUOW\nLPJFHTUQUINAALRDGLSQUXR\nLYYJJEBNZATAFQWTDZSPUNZ\nHSJPIQKKWWERJZIEMLCZUKI\nOJYIEYDGPFWRHCMISJCCUEM\nLMGKZVFYIVDRTIHBWPCNUTG\nUBGGNCITVHAIPKXCLTSAULQ\nOWSAWUOXQDBSXXBHTLSXUVD\nUGQTIZQPBGMASRQPVPSFUWK", "output": "454717784" }, { "input": "25 4\nLVKG\nMICU\nZHKW\nLFGG\nOWQO\nLCQG\nLVXU\nOUKB\nLNQX\nZJTO\nOOQX\nLVQP\nMFQB\nMRQV\nOIQH\nOPXX\nXFKU\nFCQB\nZPKH\nLVCH\nNFCU\nOVQW\nOZKU\nLFHX\nLPXO", "output": "5733" }, { "input": "30 10\nUTNTGOKZYJ\nQHOUHNYZVW\nLTVGHJRZVW\nMZHYHOLZYJ\nERYEUEPZYE\nUZDBFTURYJ\nRVSMQTIZGW\nWDJQHMIRYY\nKCORHQPZYE\nRRPLFOZZVY\nJTXMFNNNYJ\nMVTGGOZZVV\nEHAFFNUZVF\nLBRNWJZNYE\nJVMOHTPZYJ\nWTARFJLZVV\nLVJCWOURVW\nLCLQFJYRVV\nQVBVGNJRYF\nNTZGHOLRYE\nMGQKHOUPYJ\nRRSSBXPZYJ\nRYCRGTLZYJ\nJRDEGNKRVW\nRZKFGHYRVG\nMDJBFNIZYG\nMPLWHXIZYE\nSRZMHMURVE\nMTEBBMRZYJ\nJPJIFOLZYM", "output": "919913906" }, { "input": "40 7\nPNTVVER\nPAHTQDR\nRXMJVAS\nVIQNLYC\nILPUSVX\nYJOXQDJ\nSEFODTO\nOTJMREL\nLIQRZGD\nLBJJPOR\nRUTYHQO\nRIWEPBD\nKQUMFIB\nISTRRYH\nXBTOTGK\nRFQODEY\nHDSTZTP\nYCXFAGL\nAREGRFU\nLELZUYU\nGVABDKH\nFJAMMME\nACVULXE\nJHVPJAS\nAAQNMBX\nJJGUCXG\nOQATILQ\nNEOSHJM\nHFLWOFM\nICYEQHY\nFACGLYP\nPLLXJEQ\nDCHXYPB\nAGDDZJJ\nLSQRXTN\nHDQZXIY\nNAHDDWW\nQCMXRQN\nFDUDSZO\nHKBEVTW", "output": "206575993" }, { "input": "2 2\nAA\nBB", "output": "4" }, { "input": "1 10\nAAAAAAAAAA", "output": "1" }, { "input": "2 8\nAAAAAAAA\nBBBBBBBB", "output": "256" }, { "input": "10 10\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB", "output": "1048576" }, { "input": "1 20\nAAAAAAAAAAAAAAAAAAAA", "output": "1" }, { "input": "20 1\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF", "output": "7" }, { "input": "5 60\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", "output": "449874206" }, { "input": "50 4\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ", "output": "10000" }, { "input": "1 100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "1" }, { "input": "100 1\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\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\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA", "output": "1" }, { "input": "100 1\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB", "output": "2" }, { "input": "100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB", "output": "14" }, { "input": "100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV", "output": "26" } ]
1,627,875,836
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
122
6,963,200
n,m=list(map(int,input().split())) l=[] for i in range(n): l.append(input()) ans=1 for j in range(m): d={} c=0 for i in range(n): d[l[i][j]]=d.get(l[i][j],0)+1 if d[l[i][j]]==1: c=c+1 ans=ans*c print(ans%(10**9+5))
Title: Pocket Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*, 1<=≤<=*k*<=≤<=*m*), then he took names number *i* and *j* and swapped their prefixes of length *k*. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers *i*, *j*, *k* independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109<=+<=7). Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. Output Specification: Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). Demo Input: ['2 3\nAAB\nBAA\n', '4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n'] Demo Output: ['4\n', '216\n'] Note: In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
```python n,m=list(map(int,input().split())) l=[] for i in range(n): l.append(input()) ans=1 for j in range(m): d={} c=0 for i in range(n): d[l[i][j]]=d.get(l[i][j],0)+1 if d[l[i][j]]==1: c=c+1 ans=ans*c print(ans%(10**9+5)) ```
0
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,606,058,793
2,147,483,647
PyPy 3
OK
TESTS
34
280
0
n=int(input()) report=[] for _ in range(n): report.append(input()) zero=0 for team in report: if team==report[0]: zero+=1 if team!=report[0]: other=team if zero>n-zero: print(report[0]) else: print(other)
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()) report=[] for _ in range(n): report.append(input()) zero=0 for team in report: if team==report[0]: zero+=1 if team!=report[0]: other=team if zero>n-zero: print(report[0]) else: print(other) ```
3.93
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,698,740,263
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
10,649,600
n,m=map(int,input().split()) a=list(map(int,input().split())) def control(l): num=l-1 ls=a[num:] x=0 for i in range(len(ls)) : x+=1 if ls[i] in ls[:i] : x-=1 print(x) for t in range (m): l=int(input()) control(l)
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n,m=map(int,input().split()) a=list(map(int,input().split())) def control(l): num=l-1 ls=a[num:] x=0 for i in range(len(ls)) : x+=1 if ls[i] in ls[:i] : x-=1 print(x) for t in range (m): l=int(input()) control(l) ```
0
583
B
Robot's Task
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it. The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1. It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information.
[ "3\n0 2 0\n", "5\n4 2 3 0 1\n", "7\n0 3 1 0 5 2 6\n" ]
[ "1\n", "3\n", "2\n" ]
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer. In the third sample the optimal order of collecting parts from computers can look like that: 1-&gt;3-&gt;4-&gt;6-&gt;2-&gt;5-&gt;7.
1,000
[ { "input": "3\n0 2 0", "output": "1" }, { "input": "5\n4 2 3 0 1", "output": "3" }, { "input": "7\n0 3 1 0 5 2 6", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 1", "output": "0" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "3\n0 2 1", "output": "1" }, { "input": "10\n7 1 9 3 5 8 6 0 2 4", "output": "9" }, { "input": "10\n1 3 5 7 9 8 6 4 2 0", "output": "9" }, { "input": "10\n5 0 0 1 3 2 2 2 5 7", "output": "1" }, { "input": "10\n8 6 5 3 9 7 1 4 2 0", "output": "8" }, { "input": "10\n1 2 4 5 0 1 3 7 1 4", "output": "2" }, { "input": "10\n3 4 8 9 5 1 2 0 6 7", "output": "6" }, { "input": "10\n2 2 0 0 6 2 9 0 2 0", "output": "2" }, { "input": "10\n1 7 5 3 2 6 0 8 4 9", "output": "8" }, { "input": "9\n1 3 8 6 2 4 5 0 7", "output": "7" }, { "input": "9\n1 3 5 7 8 6 4 2 0", "output": "8" }, { "input": "9\n2 4 3 1 3 0 5 4 3", "output": "3" }, { "input": "9\n3 5 6 8 7 0 4 2 1", "output": "5" }, { "input": "9\n2 0 8 1 0 3 0 5 3", "output": "2" }, { "input": "9\n6 2 3 7 4 8 5 1 0", "output": "4" }, { "input": "9\n3 1 5 6 0 3 2 0 0", "output": "2" }, { "input": "9\n2 6 4 1 0 8 5 3 7", "output": "7" }, { "input": "100\n27 20 18 78 93 38 56 2 48 75 36 88 96 57 69 10 25 74 68 86 65 85 66 14 22 12 43 80 99 34 42 63 61 71 77 15 37 54 21 59 23 94 28 30 50 84 62 76 47 16 26 64 82 92 72 53 17 11 41 91 35 83 79 95 67 13 1 7 3 4 73 90 8 19 33 58 98 32 39 45 87 52 60 46 6 44 49 70 51 9 5 29 31 24 40 97 81 0 89 55", "output": "69" }, { "input": "100\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0", "output": "99" }, { "input": "100\n13 89 81 0 62 1 59 92 29 13 1 37 2 8 53 15 20 34 12 70 0 85 97 55 84 60 37 54 14 65 22 69 30 22 95 44 59 85 50 80 9 71 91 93 74 21 11 78 28 21 40 81 76 24 26 60 48 85 61 68 89 76 46 73 34 52 98 29 4 38 94 51 5 55 6 27 74 27 38 37 82 70 44 89 51 59 30 37 15 55 63 78 42 39 71 43 4 10 2 13", "output": "21" }, { "input": "100\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 81 79 83 85 87 89 91 93 95 97 48 98 96 94 92 90 88 44 84 82 80 78 76 74 72 70 68 66 64 62 60 9 56 54 52 50 99 46 86 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0", "output": "96" }, { "input": "100\n32 47 74 8 14 4 12 68 18 0 44 80 14 38 6 57 4 72 69 3 21 78 74 22 39 32 58 63 34 33 23 6 39 11 6 12 18 4 0 11 20 28 16 1 22 12 57 55 13 48 43 1 50 18 87 6 11 45 38 67 37 14 7 56 6 41 1 55 5 73 78 64 38 18 38 8 37 0 18 61 37 58 58 62 86 5 0 2 15 43 34 61 2 21 15 9 69 1 11 24", "output": "4" }, { "input": "100\n40 3 55 7 6 77 13 46 17 64 21 54 25 27 91 41 1 15 37 82 23 43 42 47 26 95 53 5 11 59 61 9 78 67 69 58 73 0 36 79 60 83 2 87 63 33 71 89 97 99 98 93 56 92 19 88 86 84 39 28 65 20 34 76 51 94 66 12 62 49 96 72 24 52 48 50 44 35 74 31 38 57 81 32 22 80 70 29 30 18 68 16 14 90 10 8 85 4 45 75", "output": "75" }, { "input": "100\n34 16 42 21 84 27 11 7 82 16 95 39 36 64 26 0 38 37 2 2 16 56 16 61 55 42 26 5 61 8 30 20 19 15 9 78 5 34 15 0 3 17 36 36 1 5 4 26 18 0 14 25 7 5 91 7 43 26 79 37 17 27 40 55 66 7 0 2 16 23 68 35 2 5 9 21 1 7 2 9 4 3 22 15 27 6 0 47 5 0 12 9 20 55 36 10 6 8 5 1", "output": "3" }, { "input": "100\n35 53 87 49 13 24 93 20 5 11 31 32 40 52 96 46 1 25 66 69 28 88 84 82 70 9 75 39 26 21 18 29 23 57 90 16 48 22 95 0 58 43 7 73 8 62 63 30 64 92 79 3 6 94 34 12 76 99 67 55 56 97 14 91 68 36 44 78 41 71 86 89 47 74 4 45 98 37 80 33 83 27 42 59 72 54 17 60 51 81 15 77 65 50 10 85 61 19 38 2", "output": "67" }, { "input": "99\n89 96 56 31 32 14 9 66 87 34 69 5 92 54 41 52 46 30 22 26 16 18 20 68 62 73 90 43 79 33 58 98 37 45 10 78 94 51 19 0 91 39 28 47 17 86 3 61 77 7 15 64 55 83 65 71 97 88 6 48 24 11 8 42 81 4 63 93 50 74 35 12 95 27 53 82 29 85 84 60 72 40 36 57 23 13 38 59 49 1 75 44 76 2 21 25 70 80 67", "output": "75" }, { "input": "99\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0", "output": "98" }, { "input": "99\n82 7 6 77 17 28 90 3 68 12 63 60 24 20 4 81 71 85 57 45 11 84 3 91 49 34 89 82 0 50 48 88 36 76 36 5 62 48 20 2 20 45 69 27 37 62 42 31 57 51 92 84 89 25 7 62 12 23 23 56 30 90 27 10 77 58 48 38 56 68 57 15 33 1 34 67 16 47 75 70 69 28 38 16 5 61 85 76 44 90 37 22 77 94 55 1 97 8 69", "output": "22" }, { "input": "99\n1 51 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 42 43 45 47 49 3 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 98 96 94 92 90 88 86 84 82 80 8 76 74 72 70 68 66 22 62 60 58 56 54 52 0 48 46 44 41 40 38 36 34 32 30 28 26 24 64 20 18 16 14 12 10 78 6 4 2 50", "output": "96" }, { "input": "99\n22 3 19 13 65 87 28 17 41 40 31 21 8 37 29 65 65 53 16 33 13 5 76 4 72 9 2 76 57 72 50 15 75 0 30 13 83 36 12 31 49 51 65 22 48 31 60 15 2 17 6 1 8 0 1 63 3 16 7 7 2 1 47 28 26 21 2 36 1 5 20 25 44 0 2 39 46 30 33 11 15 34 34 4 84 52 0 39 7 3 17 15 6 38 52 64 26 1 0", "output": "3" }, { "input": "99\n24 87 25 82 97 11 37 15 23 19 34 17 76 13 45 89 33 1 27 78 63 43 54 47 49 2 42 41 75 83 61 90 65 67 21 71 60 57 77 62 81 58 85 69 3 91 68 55 72 93 29 94 66 16 88 86 84 53 14 39 35 44 9 70 80 92 56 79 74 5 64 31 52 50 48 46 51 59 40 38 36 96 32 30 28 95 7 22 20 18 26 73 12 10 8 6 4 98 0", "output": "74" }, { "input": "99\n22 14 0 44 6 17 6 6 37 45 0 48 19 8 57 8 10 0 3 12 25 2 5 53 9 49 15 6 38 14 9 40 38 22 27 12 64 10 11 35 89 19 46 39 12 24 48 0 52 1 27 27 24 4 64 24 5 0 67 3 5 39 0 1 13 37 2 8 46 1 28 70 6 79 14 15 33 6 7 34 6 18 4 71 1 55 33 71 18 11 47 23 72 53 65 32 2 7 28", "output": "3" }, { "input": "99\n28 59 73 89 52 27 0 20 36 12 83 95 31 24 54 94 49 14 51 34 50 93 13 1 2 68 63 48 41 81 23 43 18 9 16 38 33 60 62 3 40 85 72 69 90 98 11 37 22 44 35 6 21 39 82 10 64 66 96 42 74 30 8 67 97 46 84 32 17 57 75 71 5 26 4 55 58 29 7 15 45 19 92 91 78 65 88 25 86 80 77 87 79 53 47 70 56 76 61", "output": "63" } ]
1,443,966,808
2,147,483,647
Python 3
OK
TESTS
56
233
0
n=int(input()) arr=list(map(int,input().split())) found=0 ans=-1 cur=0 while found<n: if ans%2==1: for i in range(0,len(arr)): if arr[i]!=-1 and arr[i]<=found: found+=1 arr[i]=-1 #print(i+1) ans+=1 else: for i in range(len(arr)-1,-1,-1): if arr[i]!=-1 and arr[i]<=found: found+=1 arr[i]=-1 #print(i+1) ans+=1 print(ans)
Title: Robot's Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to collect at least *a**i* any pieces of information from the other computers. Doc can hack the computer only if he is right next to it. The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all *n* parts of information if initially it is next to computer with number 1. It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*n*), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. Output Specification: Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all *n* parts of information. Demo Input: ['3\n0 2 0\n', '5\n4 2 3 0 1\n', '7\n0 3 1 0 5 2 6\n'] Demo Output: ['1\n', '3\n', '2\n'] Note: In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer. In the third sample the optimal order of collecting parts from computers can look like that: 1-&gt;3-&gt;4-&gt;6-&gt;2-&gt;5-&gt;7.
```python n=int(input()) arr=list(map(int,input().split())) found=0 ans=-1 cur=0 while found<n: if ans%2==1: for i in range(0,len(arr)): if arr[i]!=-1 and arr[i]<=found: found+=1 arr[i]=-1 #print(i+1) ans+=1 else: for i in range(len(arr)-1,-1,-1): if arr[i]!=-1 and arr[i]<=found: found+=1 arr[i]=-1 #print(i+1) ans+=1 print(ans) ```
3
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,699,354,827
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) lst = list(map(str, input().split())) a, d = 0, 0 for i in lst: if i == 'A': a += 1 else: d += 1 if a > d: print('Anton') elif a == d: print('Friendship') else: print('Danik')
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python n = int(input()) lst = list(map(str, input().split())) a, d = 0, 0 for i in lst: if i == 'A': a += 1 else: d += 1 if a > d: print('Anton') elif a == d: print('Friendship') else: print('Danik') ```
0
261
A
Maxim and Discounts
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the customer takes a special basket, where he puts exactly *q**i* items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the *q**i* items in the cart. Maxim now needs to buy *n* items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well. Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.
The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of discount types. The second line contains *m* integers: *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=105). The third line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of items Maxim needs. The fourth line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — the items' prices. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "1\n2\n4\n50 50 100 100\n", "2\n2 3\n5\n50 50 50 50 50\n", "1\n1\n7\n1 1 1 1 1 1 1\n" ]
[ "200\n", "150\n", "3\n" ]
In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
500
[ { "input": "1\n2\n4\n50 50 100 100", "output": "200" }, { "input": "2\n2 3\n5\n50 50 50 50 50", "output": "150" }, { "input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3" }, { "input": "60\n7 4 20 15 17 6 2 2 3 18 13 14 16 11 13 12 6 10 14 1 16 6 4 9 10 8 10 15 16 13 13 9 16 11 5 4 11 1 20 5 11 20 19 9 14 13 10 6 6 9 2 13 11 4 1 6 8 18 10 3\n26\n2481 6519 9153 741 9008 6601 6117 1689 5911 2031 2538 5553 1358 6863 7521 4869 6276 5356 5305 6761 5689 7476 5833 257 2157 218", "output": "44768" }, { "input": "88\n8 3 4 3 1 17 5 10 18 12 9 12 4 6 19 14 9 10 10 8 15 11 18 3 11 4 10 11 7 9 14 7 13 2 8 2 15 2 8 16 7 1 9 1 11 13 13 15 8 9 4 2 13 12 12 11 1 5 20 19 13 15 6 6 11 20 14 18 11 20 20 13 8 4 17 12 17 4 13 14 1 20 19 5 7 3 19 16\n33\n7137 685 2583 6751 2104 2596 2329 9948 7961 9545 1797 6507 9241 3844 5657 1887 225 7310 1165 6335 5729 5179 8166 9294 3281 8037 1063 6711 8103 7461 4226 2894 9085", "output": "61832" }, { "input": "46\n11 6 8 8 11 8 2 8 17 3 16 1 9 12 18 2 2 5 17 19 3 9 8 19 2 4 2 15 2 11 13 13 8 6 10 12 7 7 17 15 10 19 7 7 19 6\n71\n6715 8201 9324 276 8441 2378 4829 9303 5721 3895 8193 7725 1246 8845 6863 2897 5001 5055 2745 596 9108 4313 1108 982 6483 7256 4313 8981 9026 9885 2433 2009 8441 7441 9044 6969 2065 6721 424 5478 9128 5921 11 6201 3681 4876 3369 6205 4865 8201 9751 371 2881 7995 641 5841 3595 6041 2403 1361 5121 3801 8031 7909 3809 7741 1026 9633 8711 1907 6363", "output": "129008" }, { "input": "18\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\n15\n371 2453 905 1366 6471 4331 4106 2570 4647 1648 7911 2147 1273 6437 3393", "output": "38578" }, { "input": "2\n12 4\n28\n5366 5346 1951 3303 1613 5826 8035 7079 7633 6155 9811 9761 3207 4293 3551 5245 7891 4463 3981 2216 3881 1751 4495 96 671 1393 1339 4241", "output": "89345" }, { "input": "57\n3 13 20 17 18 18 17 2 17 8 20 2 11 12 11 14 4 20 9 20 14 19 20 4 4 8 8 18 17 16 18 10 4 7 9 8 10 8 20 4 11 8 12 16 16 4 11 12 16 1 6 14 11 12 19 8 20\n7\n5267 7981 1697 826 6889 1949 2413", "output": "11220" }, { "input": "48\n14 2 5 3 10 10 5 6 14 8 19 13 4 4 3 13 18 19 9 16 3 1 14 9 13 10 13 4 12 11 8 2 18 20 14 11 3 11 18 11 4 2 7 2 18 19 2 8\n70\n9497 5103 1001 2399 5701 4053 3557 8481 1736 4139 5829 1107 6461 4089 5936 7961 6017 1416 1191 4635 4288 5605 8857 1822 71 1435 2837 5523 6993 2404 2840 8251 765 5678 7834 8595 3091 7073 8673 2299 2685 7729 8017 3171 9155 431 3773 7927 671 4063 1123 5384 2721 7901 2315 5199 8081 7321 8196 2887 9384 56 7501 1931 4769 2055 7489 3681 6321 8489", "output": "115395" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "1\n2\n1\n1", "output": "1" }, { "input": "1\n1\n3\n3 1 1", "output": "3" } ]
1,377,979,516
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
import sys n_discounts = int(sys.stdin.readline()) discount_values = [int(x) for x in sys.stdin.readline().split()] n_items = int(sys.stdin.readline()) item_values = [int(x) for x in sys.stdin.readline().split()] min_discount_req = 10000000 for discount_value in discount_values: min_discount_req = min(min_discount_req, discount_value) item_values.sort(reverse=True) print(item_values) index = 0 overall_price = 0 while index < n_items: n_left = min(min_discount_req, n_items - index) for i in range(n_left): overall_price += item_values[index+i] index += n_left + 2 print(overall_price)
Title: Maxim and Discounts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the customer takes a special basket, where he puts exactly *q**i* items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the *q**i* items in the cart. Maxim now needs to buy *n* items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well. Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts. Input Specification: The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of discount types. The second line contains *m* integers: *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=105). The third line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of items Maxim needs. The fourth line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — the items' prices. The numbers in the lines are separated by single spaces. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['1\n2\n4\n50 50 100 100\n', '2\n2 3\n5\n50 50 50 50 50\n', '1\n1\n7\n1 1 1 1 1 1 1\n'] Demo Output: ['200\n', '150\n', '3\n'] Note: In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200. In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.
```python import sys n_discounts = int(sys.stdin.readline()) discount_values = [int(x) for x in sys.stdin.readline().split()] n_items = int(sys.stdin.readline()) item_values = [int(x) for x in sys.stdin.readline().split()] min_discount_req = 10000000 for discount_value in discount_values: min_discount_req = min(min_discount_req, discount_value) item_values.sort(reverse=True) print(item_values) index = 0 overall_price = 0 while index < n_items: n_left = min(min_discount_req, n_items - index) for i in range(n_left): overall_price += item_values[index+i] index += n_left + 2 print(overall_price) ```
0
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*).
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3", "output": "0\n0\n1\n1\n0" }, { "input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5", "output": "2\n1\n1\n1\n1\n1\n1" }, { "input": "#..#\n1\n1 4", "output": "1" }, { "input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4", "output": "2\n2\n3\n2\n1\n4\n0" }, { "input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3", "output": "0\n0\n0\n0\n0\n0\n0" }, { "input": "###..#...#\n2\n2 4\n1 2", "output": "1\n1" }, { "input": "..\n1\n1 2", "output": "1" }, { "input": "##\n1\n1 2", "output": "1" }, { "input": ".#\n1\n1 2", "output": "0" }, { "input": "#.\n1\n1 2", "output": "0" }, { "input": "...\n2\n1 2\n1 2", "output": "1\n1" } ]
1,698,065,505
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
3,276,800
def thing(s, q1,q2): section = s[q1-1:q2] c=0 for i in range(len(section) -1): if section[i] == section[i+1]: c += 1 return c s = input() m = input() for i in range(int(m)): a,b = [int(x) for x in input().split()] print(thing(s,a,b))
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. Input Specification: The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the answers to the queries in the order in which they are given in the input. Demo Input: ['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n'] Demo Output: ['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n'] Note: none
```python def thing(s, q1,q2): section = s[q1-1:q2] c=0 for i in range(len(section) -1): if section[i] == section[i+1]: c += 1 return c s = input() m = input() for i in range(int(m)): a,b = [int(x) for x in input().split()] print(thing(s,a,b)) ```
0
873
A
Chores
PROGRAMMING
800
[ "implementation" ]
null
null
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.
The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1.
Print one number — minimum time Luba needs to do all *n* chores.
[ "4 2 2\n3 6 7 10\n", "5 2 1\n100 100 100 100 100\n" ]
[ "13\n", "302\n" ]
In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
0
[ { "input": "4 2 2\n3 6 7 10", "output": "13" }, { "input": "5 2 1\n100 100 100 100 100", "output": "302" }, { "input": "1 1 1\n100", "output": "1" }, { "input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "9999" }, { "input": "100 100 1\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "100 50 50\n51 51 52 53 55 55 55 55 56 56 56 57 57 58 58 59 59 59 60 60 61 61 62 62 63 64 64 64 64 65 65 65 65 66 66 66 67 68 68 68 69 69 70 70 70 70 71 71 71 71 71 71 72 72 76 76 76 76 77 79 79 81 81 81 81 82 82 82 82 83 84 85 86 87 87 88 88 88 89 89 89 90 90 90 91 91 91 92 92 93 95 95 96 96 96 97 97 98 99 100", "output": "5618" }, { "input": "100 100 1\n2 4 4 4 5 5 5 6 10 10 11 11 12 12 13 13 13 14 17 18 20 20 21 21 22 22 23 24 24 25 26 29 29 32 32 34 34 35 38 39 39 40 40 42 42 43 45 47 48 49 51 52 52 54 57 59 59 60 61 61 62 63 63 64 65 65 68 70 70 72 74 75 75 76 76 77 77 78 78 78 79 80 81 82 82 83 83 83 84 89 90 92 92 93 94 96 96 97 98 99", "output": "100" }, { "input": "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 37 38 40 42 44 44 46 47 47 48 48 48 50 50 51 51 54 54 54 55 55 56 56 56 60 61 62 62 63 64 65 65 68 70 70 71 71 71 71 75 75 76 76 79 79 79 79 81 81 82 82 86 86 86 86 88 90 90 92 96 97 97 98 98 98 98 100 100", "output": "5202" }, { "input": "100 50 49\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "output": "4950" }, { "input": "100 50 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "151" }, { "input": "100 1 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "199" } ]
1,585,902,138
2,147,483,647
PyPy 3
OK
TESTS
11
140
0
#----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- n,k,x=map(int,input().split()) a=list(map(int,input().split())) E=sum(a) for i in range(min(n,k)): E-=a[-i-1]-x print(E)
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* (). Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously. Input Specification: The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself. The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore. It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1. Output Specification: Print one number — minimum time Luba needs to do all *n* chores. Demo Input: ['4 2 2\n3 6 7 10\n', '5 2 1\n100 100 100 100 100\n'] Demo Output: ['13\n', '302\n'] Note: In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13. In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302.
```python #----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- n,k,x=map(int,input().split()) a=list(map(int,input().split())) E=sum(a) for i in range(min(n,k)): E-=a[-i-1]-x print(E) ```
3
919
A
Supermarket
PROGRAMMING
800
[ "brute force", "greedy", "implementation" ]
null
null
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo. Now imagine you'd like to buy $m$ kilos of apples. You've asked $n$ supermarkets and got the prices. Find the minimum cost for those apples. You can assume that there are enough apples in all supermarkets.
The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples. The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b \leq 100$), denoting that in this supermarket, you are supposed to pay $a$ yuan for $b$ kilos of apples.
The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$. Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} \le 10^{-6}$.
[ "3 5\n1 2\n3 4\n1 3\n", "2 1\n99 100\n98 99\n" ]
[ "1.66666667\n", "0.98989899\n" ]
In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan. In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan.
500
[ { "input": "3 5\n1 2\n3 4\n1 3", "output": "1.66666667" }, { "input": "2 1\n99 100\n98 99", "output": "0.98989899" }, { "input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 82\n38 62\n11 50\n55 84\n1 97\n12 67\n51 96\n51 7\n1 100\n79 61\n66 54\n97 93\n52 75\n80 54\n98 73\n29 28\n73 96\n24 73\n3 25\n1 29\n43 50\n97 95\n54 64\n38 97\n68 16\n22 68\n25 91\n77 13", "output": "0.37000000" }, { "input": "5 1\n5 100\n55 6\n53 27\n57 53\n62 24", "output": "0.05000000" }, { "input": "10 7\n83 93\n90 2\n63 51\n51 97\n7 97\n25 78\n17 68\n30 10\n46 14\n22 28", "output": "0.50515464" }, { "input": "1 100\n100 1", "output": "10000.00000000" }, { "input": "1 1\n59 1", "output": "59.00000000" }, { "input": "1 100\n1 100", "output": "1.00000000" }, { "input": "1 100\n1 99", "output": "1.01010101" }, { "input": "1 1\n100 1", "output": "100.00000000" }, { "input": "15 100\n1 2\n3 4\n10 11\n12 13\n20 21\n28 29\n34 35\n42 43\n59 60\n61 62\n74 75\n89 90\n96 97\n98 99\n99 100", "output": "50.00000000" }, { "input": "15 100\n3 2\n5 4\n12 11\n14 13\n22 21\n30 29\n36 35\n44 43\n61 60\n63 62\n76 75\n91 90\n98 97\n99 98\n100 99", "output": "101.01010101" }, { "input": "1 1\n100 10", "output": "10.00000000" }, { "input": "1 1\n100 3", "output": "33.33333333" }, { "input": "1 100\n100 3", "output": "3333.33333333" }, { "input": "1 100\n100 1", "output": "10000.00000000" }, { "input": "7 8\n9 8\n5 1\n3 1\n6 2\n7 3\n2 1\n3 1", "output": "9.00000000" }, { "input": "5 8\n9 8\n3 1\n2 1\n4 2\n13 5", "output": "9.00000000" }, { "input": "2 1\n1 2\n2 10", "output": "0.20000000" }, { "input": "2 1\n99 100\n95 95", "output": "0.99000000" }, { "input": "1 5\n10 1", "output": "50.00000000" }, { "input": "5 10\n9 1\n10 1\n11 1\n12 1\n13 1", "output": "90.00000000" }, { "input": "1 100\n3 1", "output": "300.00000000" } ]
1,699,697,579
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
a, b = [int(i) for i in input().split()] minimum=float('inf') for i in range(a): c,d =int(input()) price=c/d if price<minimum: minimum=price print(minimum)
Title: Supermarket Time Limit: None seconds Memory Limit: None megabytes Problem Description: We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo. Now imagine you'd like to buy $m$ kilos of apples. You've asked $n$ supermarkets and got the prices. Find the minimum cost for those apples. You can assume that there are enough apples in all supermarkets. Input Specification: The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples. The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b \leq 100$), denoting that in this supermarket, you are supposed to pay $a$ yuan for $b$ kilos of apples. Output Specification: The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$. Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} \le 10^{-6}$. Demo Input: ['3 5\n1 2\n3 4\n1 3\n', '2 1\n99 100\n98 99\n'] Demo Output: ['1.66666667\n', '0.98989899\n'] Note: In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan. In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan.
```python a, b = [int(i) for i in input().split()] minimum=float('inf') for i in range(a): c,d =int(input()) price=c/d if price<minimum: minimum=price print(minimum) ```
-1
884
D
Boxes And Balls
PROGRAMMING
2,300
[ "data structures", "greedy" ]
null
null
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some turns. Each turn he does the following: 1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3. The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes. Help Ivan to determine the minimum possible penalty of the game!
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*.
Print one number — the minimum possible penalty of the game.
[ "3\n1 2 3\n", "4\n2 3 4 5\n" ]
[ "6\n", "19\n" ]
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5. Total penalty is 19.
0
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "4\n2 3 4 5", "output": "19" }, { "input": "6\n1 4 4 4 4 4", "output": "38" }, { "input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158", "output": "8176373828" }, { "input": "1\n10", "output": "0" }, { "input": "1\n4", "output": "0" }, { "input": "1\n12312", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "2\n3 4", "output": "7" } ]
1,510,185,241
2,147,483,647
Python 3
OK
TESTS
32
514
15,974,400
import heapq as h n = int(input()) line2 = input().split() a = [] for i in range(n): h.heappush(a,int(line2[i])) if n == 1: print(0) else: result = 0 if n%2 == 1: k = n else: a.append(0) k = n + 1 while k > 3: previous = h.heappop(a) + h.heappop(a)+ h.heappop(a) result += previous h.heappush(a, previous) k -= 2 result += sum(a) print(result)
Title: Boxes And Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some turns. Each turn he does the following: 1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3. The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes. Help Ivan to determine the minimum possible penalty of the game! Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. Output Specification: Print one number — the minimum possible penalty of the game. Demo Input: ['3\n1 2 3\n', '4\n2 3 4 5\n'] Demo Output: ['6\n', '19\n'] Note: In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5. Total penalty is 19.
```python import heapq as h n = int(input()) line2 = input().split() a = [] for i in range(n): h.heappush(a,int(line2[i])) if n == 1: print(0) else: result = 0 if n%2 == 1: k = n else: a.append(0) k = n + 1 while k > 3: previous = h.heappop(a) + h.heappop(a)+ h.heappop(a) result += previous h.heappush(a, previous) k -= 2 result += sum(a) print(result) ```
3
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n1 2 3 3 4", "output": "3" }, { "input": "4\n1 2 2 3", "output": "2" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "3\n1 2 1", "output": "2" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 1 2", "output": "2" }, { "input": "11\n1 2 3 1 2 3 2 1 2 3 4", "output": "4" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n3 2 1", "output": "1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "7" }, { "input": "1\n1234394", "output": "1" } ]
1,654,505,452
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n, ls, c, res, mx, = int(input()), list(map(int, input().split())), 0, 0, 0 for i in ls: if i > c: c, res = i, res + 1 else: res, mx = 1, max(res, mx) print(max(mx, c))
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input Specification: The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print the maximum length of an increasing subarray of the given array. Demo Input: ['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n'] Demo Output: ['3\n', '1\n', '3\n'] Note: none
```python n, ls, c, res, mx, = int(input()), list(map(int, input().split())), 0, 0, 0 for i in ls: if i > c: c, res = i, res + 1 else: res, mx = 1, max(res, mx) print(max(mx, c)) ```
0
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n1305" }, { "input": "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\n102\n486\n333\n580\n431\n537\n355\n624\n23\n429\n276\n84\n704\n96\n536\n855\n653\n72\n718\n776\n658\n802\n777\n995\n285\n328\n405\n184\n555\n956\n410\n846\n853\n525\n983\n65\n549\n839\n929\n620\n725\n635\n303\n201\n878\n580\n139\n182\n69\n400\n788\n985\n792\n103\n248\n570\n839\n253\n417", "output": "404305\n251782\n0\n227457\n210832\n284857\n462120\n8535\n20605\n392670\n357082\n39164\n172890\n482574\n-1\n1765\n144024\n484545\n449679\n264039\n5206\n29380\n124228\n105469\n31116\n232909\n197350\n320760\n136555\n178254\n498454\n402504\n83644\n23580\n176457\n57631\n295560\n59704\n127756\n298654\n102263\n4999\n117319\n54589\n166444\n92074\n142407\n62168\n192954\n214\n91213\n37204\n3316\n246114\n4402\n141870\n363894\n211485\n2374\n256075\n299430\n214765\n319957\n300207\n493464\n39733\n52934\n81193\n16510\n15..." }, { "input": "1\n16", "output": "74" }, { "input": "60\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457", "output": "144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875..." }, { "input": "13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73", "output": "-1\n128\n434\n128\n128\n4024\n2521\n2161\n402\n402\n3932\n777\n2447" }, { "input": "1\n16383", "output": "134176770" }, { "input": "16\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100", "output": "5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908" }, { "input": "1\n414234", "output": "85794061921" }, { "input": "1\n414232", "output": "85793233454" }, { "input": "3\n414231\n414231\n414231", "output": "85792819222\n85792819222\n85792819222" }, { "input": "1\n121", "output": "7127" } ]
1,636,130,652
2,147,483,647
PyPy 3-64
OK
TESTS
21
62
30,412,800
t = int(input()) for i in range(t): n = int(input()) s = ((n+1)*n)//2 i = 1 while i<=n: s -= i*2 i*=2 print(s)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Input Specification: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the requested sum for each of *t* integers *n* given in the input. Demo Input: ['2\n4\n1000000000\n'] Demo Output: ['-4\n499999998352516354\n'] Note: The answer for the first sample is explained in the statement.
```python t = int(input()) for i in range(t): n = int(input()) s = ((n+1)*n)//2 i = 1 while i<=n: s -= i*2 i*=2 print(s) ```
3
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,681,262,583
2,147,483,647
Python 3
OK
TESTS
35
46
0
n,k=map(int,input().split()) *a,=map(int,input().split()) print(sum(1 for i in a if i<=5-k)//3)
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,=map(int,input().split()) print(sum(1 for i in a if i<=5-k)//3) ```
3
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,540,831,003
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n = int(input()) tree = list(map(int,input().split())) tree2, tree3 = [], [] node_nr, last_nodes = 0, 0 for nodes in tree: for i in range(nodes): tree2.append(node_nr) if nodes >= 2 and last_nodes >= 2: tree3.append(node_nr - 1) for i in range(nodes - 1): tree3.append(node_nr) else: for i in range(nodes): tree3.append(node_nr) node_nr += nodes last_nodes = nodes def a(): print('ambiguous') print(*tree2) print(*tree3) return '' print('perfect\n' if tree2 == tree3 else a())
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()) tree = list(map(int,input().split())) tree2, tree3 = [], [] node_nr, last_nodes = 0, 0 for nodes in tree: for i in range(nodes): tree2.append(node_nr) if nodes >= 2 and last_nodes >= 2: tree3.append(node_nr - 1) for i in range(nodes - 1): tree3.append(node_nr) else: for i in range(nodes): tree3.append(node_nr) node_nr += nodes last_nodes = nodes def a(): print('ambiguous') print(*tree2) print(*tree3) return '' print('perfect\n' if tree2 == tree3 else a()) ```
0
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,691,597,302
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
for _ in range(int(input())): l= list(map(int,input().split(" "))) flag=0 for i in range(len(l)): for j in range(i+1,len(l)): if l[i]+l[j] >= 10: flag=1 if flag==0: print("No") else: print("Yes")
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python for _ in range(int(input())): l= list(map(int,input().split(" "))) flag=0 for i in range(len(l)): for j in range(i+1,len(l)): if l[i]+l[j] >= 10: flag=1 if flag==0: print("No") else: print("Yes") ```
-1
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7", "output": "37 37" }, { "input": "40 10\n1 2 3 4 5 6 7 10 10 10", "output": "223 158" }, { "input": "1 1\n6", "output": "6 6" }, { "input": "1 2\n10 9", "output": "10 9" }, { "input": "2 1\n7", "output": "13 13" }, { "input": "2 2\n7 2", "output": "13 3" }, { "input": "3 2\n4 7", "output": "18 9" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "10 10\n3 1 2 2 1 1 2 1 2 3", "output": "20 13" }, { "input": "10 2\n7 3", "output": "34 34" }, { "input": "10 1\n19", "output": "145 145" }, { "input": "100 3\n29 36 35", "output": "1731 1731" }, { "input": "100 5\n3 38 36 35 2", "output": "2019 1941" }, { "input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62", "output": "50279 5479" }, { "input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4", "output": "1501 1501" }, { "input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2", "output": "12204 8871" } ]
1,589,625,216
2,147,483,647
Python 3
OK
TESTS
33
466
6,963,200
n,m = map(int,input().split()) a = list(map(int,input().split())) b = [i for i in a] mx,mn = 0,0 for i in range(n): mx = mx + max(a) d = a.index(max(a)) if(a[d]>0): a[d]-=1 for i in range(n): mn = mn + min(b) d = b.index(min(b)) if(b[d]==1): b[d]=1000000000 elif(b[d]>1): b[d]-=1 print(mx,mn)
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. Output Specification: Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. Demo Input: ['4 3\n2 1 1\n', '4 3\n2 2 2\n'] Demo Output: ['5 5\n', '7 6\n'] Note: In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
```python n,m = map(int,input().split()) a = list(map(int,input().split())) b = [i for i in a] mx,mn = 0,0 for i in range(n): mx = mx + max(a) d = a.index(max(a)) if(a[d]>0): a[d]-=1 for i in range(n): mn = mn + min(b) d = b.index(min(b)) if(b[d]==1): b[d]=1000000000 elif(b[d]>1): b[d]-=1 print(mx,mn) ```
3
928
B
Chat
PROGRAMMING
1,400
[ "*special", "dp" ]
null
null
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to *n* where *n* is the total number of messages in the chat. Each message might contain a link to an earlier message which it is a reply to. When opening a message *x* or getting a link to it, the dialogue is shown in such a way that *k* previous messages, message *x* and *k* next messages are visible (with respect to message *x*). In case there are less than *k* messages somewhere, they are yet all shown. Digging deep into your message history, you always read all visible messages and then go by the link in the current message *x* (if there is one) and continue reading in the same manner. Determine the number of messages you'll read if your start from message number *t* for all *t* from 1 to *n*. Calculate these numbers independently. If you start with message *x*, the initial configuration is *x* itself, *k* previous and *k* next messages. Messages read multiple times are considered as one.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible. The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*i*), where *a**i* denotes the *i*-th message link destination or zero, if there's no link from *i*. All messages are listed in chronological order. It's guaranteed that the link from message *x* goes to message with number strictly less than *x*.
Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible.
[ "6 0\n0 1 1 2 3 2\n", "10 1\n0 1 0 3 4 5 2 3 7 0\n", "2 2\n0 1\n" ]
[ "1 2 2 3 3 3 \n", "2 3 3 4 5 6 6 6 8 2 \n", "2 2 \n" ]
Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go. In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
1,250
[ { "input": "6 0\n0 1 1 2 3 2", "output": "1 2 2 3 3 3 " }, { "input": "10 1\n0 1 0 3 4 5 2 3 7 0", "output": "2 3 3 4 5 6 6 6 8 2 " }, { "input": "2 2\n0 1", "output": "2 2 " }, { "input": "1 1\n0", "output": "1 " }, { "input": "5 2\n0 1 2 3 1", "output": "3 4 5 5 5 " }, { "input": "30 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 0 0 0 0 0 2 1 0", "output": "2 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 3 3 3 3 3 6 3 3 3 3 3 6 5 2 " }, { "input": "100 5\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33 46 26 31 0 21 57 57 31 63 63 25 59 65 56 68 0 30 55 55 0 70 43 59 49 59 79 66 74 0 11 65 0 80 63 0 84 73 49 73 81 0 86 76 98", "output": "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 11 11 23 22 15 23 24 28 29 30 31 11 11 11 13 11 14 38 18 33 11 11 34 13 22 23 24 17 28 19 42 29 44 11 11 33 40 27 36 11 49 53 42 22 11 34 58 59 22 61 62 41 31 65 60 34 11 24 22 22 11 67 28 33 22 33 36 73 32 11 27 72 11 31 70 11 40 35 22 35 43 9 35 18 35 " }, { "input": "2 2\n0 0", "output": "2 2 " }, { "input": "2 1\n0 0", "output": "2 2 " }, { "input": "2 1\n0 1", "output": "2 2 " }, { "input": "2 0\n0 0", "output": "1 1 " }, { "input": "2 0\n0 1", "output": "1 2 " }, { "input": "3 0\n0 0 0", "output": "1 1 1 " }, { "input": "3 0\n0 0 1", "output": "1 1 2 " }, { "input": "3 0\n0 0 2", "output": "1 1 2 " }, { "input": "3 0\n0 1 0", "output": "1 2 1 " }, { "input": "3 0\n0 1 1", "output": "1 2 2 " }, { "input": "3 0\n0 1 2", "output": "1 2 3 " }, { "input": "3 1\n0 0 0", "output": "2 3 2 " }, { "input": "3 1\n0 0 1", "output": "2 3 3 " }, { "input": "3 1\n0 0 2", "output": "2 3 3 " }, { "input": "3 1\n0 1 0", "output": "2 3 2 " }, { "input": "3 1\n0 1 1", "output": "2 3 3 " }, { "input": "3 1\n0 1 2", "output": "2 3 3 " }, { "input": "3 2\n0 0 0", "output": "3 3 3 " }, { "input": "3 2\n0 0 1", "output": "3 3 3 " }, { "input": "3 2\n0 0 2", "output": "3 3 3 " }, { "input": "3 2\n0 1 0", "output": "3 3 3 " }, { "input": "3 2\n0 1 1", "output": "3 3 3 " }, { "input": "3 2\n0 1 2", "output": "3 3 3 " }, { "input": "3 3\n0 0 0", "output": "3 3 3 " }, { "input": "3 3\n0 0 1", "output": "3 3 3 " }, { "input": "3 3\n0 0 2", "output": "3 3 3 " }, { "input": "3 3\n0 1 0", "output": "3 3 3 " }, { "input": "3 3\n0 1 1", "output": "3 3 3 " }, { "input": "3 3\n0 1 2", "output": "3 3 3 " }, { "input": "10 3\n0 0 0 0 0 0 0 4 0 4", "output": "4 5 6 7 7 7 7 10 5 10 " }, { "input": "20 2\n0 0 0 0 2 1 0 3 0 1 1 11 0 10 0 0 9 17 9 0", "output": "3 4 5 5 7 8 5 10 5 8 8 9 5 12 5 5 10 11 9 3 " }, { "input": "40 0\n0 1 2 3 4 5 0 0 0 0 0 11 12 0 14 10 0 16 15 0 19 21 22 0 23 25 25 24 24 29 29 0 0 31 0 35 31 36 34 29", "output": "1 2 3 4 5 6 1 1 1 1 1 2 3 1 2 2 1 3 3 1 4 5 6 1 7 8 8 2 2 3 3 1 1 4 1 2 4 3 5 3 " } ]
1,519,561,395
74,895
PyPy 3
WRONG_ANSWER
TESTS
21
295
30,924,800
s = input().split() n = int(s[0]) k = int(s[1]) a = [int(i) for i in input().split()] if n < k+2: print(str(n)+(' ' + str(n))*(n-1)) else: twok = k*2+1 counts = [] for i in range(1, k+2): counts.append(i + k) for i in range(k+2, n-k): if a[i-1] == 0: counts.append(twok) else: p = i - a[i-1] if p < twok: counts.append(counts[a[i-1]-1]+p) else: counts.append(counts[a[i-1]-1]+twok) for i in range(n-k, n+1): if a[i-1] == 0: counts.append(n-i+1+k) elif n-k < a[i-1]: counts.append(counts[a[i-1]-1]) else: p = i - a[i-1] if p < twok: counts.append(counts[a[i-1]-1]+n-i-k+p) else: counts.append(counts[a[i-1]-1]+n-i+1+k) print(counts[0], end='') [print(' ' + str(counts[i]), end='') for i in range(1,n)]
Title: Chat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to *n* where *n* is the total number of messages in the chat. Each message might contain a link to an earlier message which it is a reply to. When opening a message *x* or getting a link to it, the dialogue is shown in such a way that *k* previous messages, message *x* and *k* next messages are visible (with respect to message *x*). In case there are less than *k* messages somewhere, they are yet all shown. Digging deep into your message history, you always read all visible messages and then go by the link in the current message *x* (if there is one) and continue reading in the same manner. Determine the number of messages you'll read if your start from message number *t* for all *t* from 1 to *n*. Calculate these numbers independently. If you start with message *x*, the initial configuration is *x* itself, *k* previous and *k* next messages. Messages read multiple times are considered as one. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible. The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=&lt;<=*i*), where *a**i* denotes the *i*-th message link destination or zero, if there's no link from *i*. All messages are listed in chronological order. It's guaranteed that the link from message *x* goes to message with number strictly less than *x*. Output Specification: Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible. Demo Input: ['6 0\n0 1 1 2 3 2\n', '10 1\n0 1 0 3 4 5 2 3 7 0\n', '2 2\n0 1\n'] Demo Output: ['1 2 2 3 3 3 \n', '2 3 3 4 5 6 6 6 8 2 \n', '2 2 \n'] Note: Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go. In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
```python s = input().split() n = int(s[0]) k = int(s[1]) a = [int(i) for i in input().split()] if n < k+2: print(str(n)+(' ' + str(n))*(n-1)) else: twok = k*2+1 counts = [] for i in range(1, k+2): counts.append(i + k) for i in range(k+2, n-k): if a[i-1] == 0: counts.append(twok) else: p = i - a[i-1] if p < twok: counts.append(counts[a[i-1]-1]+p) else: counts.append(counts[a[i-1]-1]+twok) for i in range(n-k, n+1): if a[i-1] == 0: counts.append(n-i+1+k) elif n-k < a[i-1]: counts.append(counts[a[i-1]-1]) else: p = i - a[i-1] if p < twok: counts.append(counts[a[i-1]-1]+n-i-k+p) else: counts.append(counts[a[i-1]-1]+n-i+1+k) print(counts[0], end='') [print(' ' + str(counts[i]), end='') for i in range(1,n)] ```
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,692,033,810
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
def valerathehorse(shoes): shoesNeed = 0 d = {} for i in range(len(shoes)): if d.get(shoes[i]): d[n[i]] = 1 else: shoesNeed += 1 print(shoesNeed) if __name__ == "__main__": shoes = list(map(int, input().split())) valerathehorse(shoes)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python def valerathehorse(shoes): shoesNeed = 0 d = {} for i in range(len(shoes)): if d.get(shoes[i]): d[n[i]] = 1 else: shoesNeed += 1 print(shoesNeed) if __name__ == "__main__": shoes = list(map(int, input().split())) valerathehorse(shoes) ```
0
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "output": "547306902373544674" }, { "input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "output": "1876641179289775029" }, { "input": "1 0 0 0\n0", "output": "0" }, { "input": "1 1000000000 1000000000 1000000000\n1000000000", "output": "3000000000000000000" }, { "input": "1 -1000000000 -1000000000 1000000000\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 -1000000000\n1000000000", "output": "-3000000000000000000" }, { "input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000", "output": "-3000000000000000000" }, { "input": "1 1 1 1\n-1", "output": "-3" }, { "input": "1 -1 -1 -1\n1", "output": "-3" }, { "input": "1 1000000000 1000000000 1000000000\n-1000000000", "output": "-3000000000000000000" }, { "input": "1 1 2 3\n-1", "output": "-6" }, { "input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "3 1 1 1\n-1 -1 -1", "output": "-3" }, { "input": "1 -1000000000 0 0\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -100 -100 -100\n100", "output": "-30000" }, { "input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "1 999999999 999999999 999999999\n-999999999", "output": "-2999999994000000003" }, { "input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000", "output": "-1999999999000000000" }, { "input": "3 -2 3 -2\n1 2 1", "output": "2" }, { "input": "2 1 -1 1\n1 -1", "output": "1" }, { "input": "1 -1000000000 1 -1000000000\n1000000000", "output": "-1999999999000000000" }, { "input": "1 1000000000 1000000000 -1000000000\n-1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 0\n1000000000", "output": "-2000000000000000000" } ]
1,648,179,190
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
def check_x(): params = input().split() n, p, q, r = int(params[0]), int(params[1]), int(params[2]), int(params[3]) arr = input().split() arr = [int(x) for x in arr] x = find_x(p, q, r, arr) print(x) def find_x(p, q, r, a): pqr = [p, q, r] x = 0 # preprocess overall_max = None overall_min = None has_zero = False for i in range(len(a)): # get overall max if overall_max is None: overall_max = a[i] else: overall_max = max(overall_max, a[i]) # get overall min if overall_min is None: overall_min = a[i] else: overall_min = min(overall_min, a[i]) # check for 0 if a[i] == 0: has_zero = True for num in pqr: # num is positive if num > 0: x += num * overall_max # num is negative elif num < 0: if overall_min < 0 or not has_zero: x += num * overall_min return x check_x()
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. Input Specification: First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Output Specification: Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Demo Input: ['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n'] Demo Output: ['30\n', '12\n'] Note: In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
```python def check_x(): params = input().split() n, p, q, r = int(params[0]), int(params[1]), int(params[2]), int(params[3]) arr = input().split() arr = [int(x) for x in arr] x = find_x(p, q, r, arr) print(x) def find_x(p, q, r, a): pqr = [p, q, r] x = 0 # preprocess overall_max = None overall_min = None has_zero = False for i in range(len(a)): # get overall max if overall_max is None: overall_max = a[i] else: overall_max = max(overall_max, a[i]) # get overall min if overall_min is None: overall_min = a[i] else: overall_min = min(overall_min, a[i]) # check for 0 if a[i] == 0: has_zero = True for num in pqr: # num is positive if num > 0: x += num * overall_max # num is negative elif num < 0: if overall_min < 0 or not has_zero: x += num * overall_min return x check_x() ```
0
682
B
Alyona and Mex
PROGRAMMING
1,200
[ "sortings" ]
null
null
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
[ "5\n1 3 3 3 6\n", "2\n2 1\n" ]
[ "5\n", "3\n" ]
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
1,000
[ { "input": "5\n1 3 3 3 6", "output": "5" }, { "input": "2\n2 1", "output": "3" }, { "input": "1\n1", "output": "2" }, { "input": "1\n1000000000", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n1 3", "output": "3" }, { "input": "2\n2 2", "output": "3" }, { "input": "2\n2 3", "output": "3" }, { "input": "2\n3 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "3\n2 1 1", "output": "3" }, { "input": "3\n3 1 1", "output": "3" }, { "input": "3\n1 1 4", "output": "3" }, { "input": "3\n2 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "4" }, { "input": "3\n2 4 1", "output": "4" }, { "input": "3\n3 3 1", "output": "4" }, { "input": "3\n1 3 4", "output": "4" }, { "input": "3\n4 1 4", "output": "4" }, { "input": "3\n2 2 2", "output": "3" }, { "input": "3\n3 2 2", "output": "4" }, { "input": "3\n4 2 2", "output": "4" }, { "input": "3\n2 3 3", "output": "4" }, { "input": "3\n4 2 3", "output": "4" }, { "input": "3\n4 4 2", "output": "4" }, { "input": "3\n3 3 3", "output": "4" }, { "input": "3\n4 3 3", "output": "4" }, { "input": "3\n4 3 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "4\n1 1 1 1", "output": "2" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "4\n1 1 3 1", "output": "3" }, { "input": "4\n1 4 1 1", "output": "3" }, { "input": "4\n1 2 1 2", "output": "3" }, { "input": "4\n1 3 2 1", "output": "4" }, { "input": "4\n2 1 4 1", "output": "4" }, { "input": "4\n3 3 1 1", "output": "4" }, { "input": "4\n1 3 4 1", "output": "4" }, { "input": "4\n1 1 4 4", "output": "4" }, { "input": "4\n2 2 2 1", "output": "3" }, { "input": "4\n1 2 2 3", "output": "4" }, { "input": "4\n2 4 1 2", "output": "4" }, { "input": "4\n3 3 1 2", "output": "4" }, { "input": "4\n2 3 4 1", "output": "5" }, { "input": "4\n1 4 2 4", "output": "5" }, { "input": "4\n3 1 3 3", "output": "4" }, { "input": "4\n3 4 3 1", "output": "5" }, { "input": "4\n1 4 4 3", "output": "5" }, { "input": "4\n4 1 4 4", "output": "5" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "4\n2 2 3 2", "output": "4" }, { "input": "4\n2 2 2 4", "output": "4" }, { "input": "4\n2 2 3 3", "output": "4" }, { "input": "4\n2 2 3 4", "output": "5" }, { "input": "4\n2 4 4 2", "output": "5" }, { "input": "4\n2 3 3 3", "output": "4" }, { "input": "4\n2 4 3 3", "output": "5" }, { "input": "4\n4 4 2 3", "output": "5" }, { "input": "4\n4 4 4 2", "output": "5" }, { "input": "4\n3 3 3 3", "output": "4" }, { "input": "4\n3 3 3 4", "output": "5" }, { "input": "4\n4 3 3 4", "output": "5" }, { "input": "4\n4 4 3 4", "output": "5" }, { "input": "4\n4 4 4 4", "output": "5" }, { "input": "11\n1 1 1 1 1 1 1 1 1 3 3", "output": "4" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8", "output": "9" }, { "input": "4\n2 2 2 3", "output": "4" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100", "output": "15" }, { "input": "7\n1 2 2 2 5 5 1", "output": "5" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "5\n1 1 1 1 10000", "output": "3" }, { "input": "5\n1 1 1 1 2", "output": "3" }, { "input": "7\n1 3 3 3 3 3 6", "output": "5" }, { "input": "4\n1 1 1 3", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 100", "output": "3" }, { "input": "4\n1 1 2 2", "output": "3" }, { "input": "5\n1 1 1 3 4", "output": "4" }, { "input": "8\n1 1 1 1 2 2 3 40", "output": "5" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "7\n1 2 2 2 2 2 4", "output": "4" }, { "input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 2 3", "output": "4" }, { "input": "4\n8 8 8 8", "output": "5" }, { "input": "5\n5 6 6 6 7", "output": "6" } ]
1,609,868,733
2,147,483,647
PyPy 3
OK
TESTS
127
264
10,956,800
# RawCoder : https://bit.ly/RCyouTube # Author : MehulYK n = int(input()) w = list(map(int,input().split())) w.sort() ans = 1 for i in w: ans += i >= ans print(ans)
Title: Alyona and Mex Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≤<=*b**i*<=≤<=*a**i* for every 1<=≤<=*i*<=≤<=*n*. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. Output Specification: Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Demo Input: ['5\n1 3 3 3 6\n', '2\n2 1\n'] Demo Output: ['5\n', '3\n'] Note: In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
```python # RawCoder : https://bit.ly/RCyouTube # Author : MehulYK n = int(input()) w = list(map(int,input().split())) w.sort() ans = 1 for i in w: ans += i >= ans print(ans) ```
3
678
C
Joty and Chocolate
PROGRAMMING
1,600
[ "implementation", "math", "number theory" ]
null
null
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get.
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "5 2 3 12 15\n", "20 2 3 3 5\n" ]
[ "39\n", "51\n" ]
none
0
[ { "input": "5 2 3 12 15", "output": "39" }, { "input": "20 2 3 3 5", "output": "51" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1 2 2 2 2", "output": "0" }, { "input": "2 1 3 3 3", "output": "6" }, { "input": "3 1 1 3 3", "output": "9" }, { "input": "4 1 5 4 3", "output": "16" }, { "input": "8 8 1 1 1", "output": "8" }, { "input": "15 14 32 65 28", "output": "65" }, { "input": "894 197 325 232 902", "output": "2732" }, { "input": "8581 6058 3019 2151 4140", "output": "10431" }, { "input": "41764 97259 54586 18013 75415", "output": "0" }, { "input": "333625 453145 800800 907251 446081", "output": "0" }, { "input": "4394826 2233224 609367 3364334 898489", "output": "9653757" }, { "input": "13350712 76770926 61331309 8735000 9057368", "output": "0" }, { "input": "142098087 687355301 987788392 75187408 868856364", "output": "0" }, { "input": "1000000000 1 3 1000000000 999999999", "output": "1000000000000000000" }, { "input": "6 6 2 8 2", "output": "12" }, { "input": "500 8 4 4 5", "output": "625" }, { "input": "20 4 6 2 3", "output": "17" }, { "input": "10 3 9 1 2", "output": "4" }, { "input": "120 18 6 3 5", "output": "100" }, { "input": "30 4 6 2 2", "output": "20" }, { "input": "1000000000 7171 2727 191 272", "output": "125391842" }, { "input": "5 2 2 4 1", "output": "8" }, { "input": "1000000000 2 2 3 3", "output": "1500000000" }, { "input": "24 4 6 5 7", "output": "48" }, { "input": "216 6 36 10 100", "output": "900" }, { "input": "100 12 6 1 10", "output": "160" }, { "input": "1000 4 8 3 5", "output": "1000" }, { "input": "10 2 4 3 6", "output": "21" }, { "input": "1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "10 5 10 2 3", "output": "5" }, { "input": "100000 3 9 1 2", "output": "44444" }, { "input": "10 2 4 1 100", "output": "203" }, { "input": "20 6 4 2 3", "output": "19" }, { "input": "1200 4 16 2 3", "output": "675" }, { "input": "7 2 4 7 9", "output": "23" }, { "input": "24 6 4 15 10", "output": "100" }, { "input": "50 2 8 15 13", "output": "375" }, { "input": "100 4 6 12 15", "output": "444" }, { "input": "56756 9 18 56 78", "output": "422502" }, { "input": "10000 4 6 10 12", "output": "36662" }, { "input": "20 2 4 3 5", "output": "40" }, { "input": "24 4 6 10 100", "output": "440" }, { "input": "12 2 4 5 6", "output": "33" }, { "input": "100 2 4 1 100", "output": "2525" }, { "input": "1000 4 6 50 50", "output": "16650" }, { "input": "60 12 6 12 15", "output": "150" }, { "input": "1000 2 4 5 6", "output": "2750" }, { "input": "1000000000 1 1 9999 5555", "output": "9999000000000" }, { "input": "50 2 2 4 5", "output": "125" }, { "input": "14 4 2 2 3", "output": "21" }, { "input": "100 3 9 1 2", "output": "44" }, { "input": "1000000000 4 6 1 1000000000", "output": "166666666166666667" }, { "input": "12 3 3 45 4", "output": "180" }, { "input": "12 2 4 5 9", "output": "42" }, { "input": "1000000000 2 2 1000000000 1000000000", "output": "500000000000000000" }, { "input": "50 4 8 5 6", "output": "66" }, { "input": "32 4 16 6 3", "output": "48" }, { "input": "10000 2 4 1 1", "output": "5000" }, { "input": "8 2 4 100 1", "output": "400" }, { "input": "20 4 2 10 1", "output": "55" }, { "input": "5 2 2 12 15", "output": "30" }, { "input": "20 2 12 5 6", "output": "51" }, { "input": "10 2 4 1 2", "output": "7" }, { "input": "32 4 16 3 6", "output": "30" }, { "input": "50 2 8 13 15", "output": "337" }, { "input": "12 6 4 10 9", "output": "38" }, { "input": "1000000000 999999998 999999999 999999998 999999999", "output": "1999999997" }, { "input": "20 2 4 10 20", "output": "150" }, { "input": "13 4 6 12 15", "output": "54" }, { "input": "30 3 6 5 7", "output": "60" }, { "input": "7 2 4 2 1", "output": "6" }, { "input": "100000 32 16 2 3", "output": "18750" }, { "input": "6 2 6 1 1", "output": "3" }, { "input": "999999999 180 192 46642017 28801397", "output": "399129078526502" }, { "input": "12 4 6 1 1", "output": "4" }, { "input": "10 2 4 10 5", "output": "50" }, { "input": "1000000 4 6 12 14", "output": "4333328" }, { "input": "2000 20 30 3 5", "output": "531" }, { "input": "1000000000 1 2 1 1", "output": "1000000000" }, { "input": "30 3 15 10 3", "output": "100" }, { "input": "1000 2 4 1 100", "output": "25250" }, { "input": "6 3 3 12 15", "output": "30" }, { "input": "24 4 6 1 1", "output": "8" }, { "input": "20 2 12 4 5", "output": "41" }, { "input": "1000000000 9 15 10 10", "output": "1555555550" }, { "input": "16 2 4 1 2", "output": "12" }, { "input": "100000 4 6 12 14", "output": "433328" }, { "input": "24 6 4 1 1", "output": "8" }, { "input": "1000000 4 6 12 15", "output": "4499994" }, { "input": "100 2 4 5 6", "output": "275" }, { "input": "10 3 9 12 15", "output": "39" }, { "input": "1000000000 1 1 999999999 999999999", "output": "999999999000000000" }, { "input": "6 2 4 2 3", "output": "7" }, { "input": "2 2 2 2 2", "output": "2" }, { "input": "6 6 2 1 1", "output": "3" }, { "input": "100 2 4 3 7", "output": "250" }, { "input": "1000000 32 16 2 5", "output": "312500" }, { "input": "100 20 15 50 25", "output": "375" }, { "input": "1000000000 100000007 100000013 10 3", "output": "117" }, { "input": "1000000000 9999999 99999998 3 3", "output": "330" }, { "input": "10077696 24 36 10 100", "output": "30792960" }, { "input": "392852503 148746166 420198270 517065752 906699795", "output": "1034131504" }, { "input": "536870912 60000 72000 271828 314159", "output": "4369119072" }, { "input": "730114139 21550542 204644733 680083361 11353255", "output": "22476810678" }, { "input": "538228881 766493289 791886544 468896052 600136703", "output": "0" }, { "input": "190 20 50 84 172", "output": "1188" }, { "input": "1000 5 10 80 90", "output": "17000" }, { "input": "99999999 999999998 1 271828 314159", "output": "31415899685841" }, { "input": "22 3 6 1243 1", "output": "8701" }, { "input": "15 10 5 2 2", "output": "6" }, { "input": "1000000000 1000000000 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "62 62 42 78 124", "output": "202" }, { "input": "2 2 2 2 1", "output": "2" }, { "input": "864351351 351 313 531 11", "output": "1337898227" }, { "input": "26 3 6 1244 1", "output": "9952" }, { "input": "1000 4 6 7 3", "output": "1999" }, { "input": "134312 3 6 33333 1", "output": "1492318410" }, { "input": "100 4 6 17 18", "output": "577" }, { "input": "6 2 4 5 6", "output": "16" }, { "input": "8 2 4 10 1", "output": "40" }, { "input": "10 2 4 3 3", "output": "15" }, { "input": "1000 1000 1000 1000 1000", "output": "1000" }, { "input": "123123 3 6 34312 2", "output": "1408198792" }, { "input": "1000000000 25 5 999 999", "output": "199800000000" }, { "input": "100 4 2 5 12", "output": "600" }, { "input": "50 2 4 4 5", "output": "112" }, { "input": "24 4 6 100 333", "output": "1732" }, { "input": "216 24 36 10 100", "output": "660" }, { "input": "50 6 4 3 8", "output": "108" }, { "input": "146 76 2 178 192", "output": "14016" }, { "input": "55 8 6 11 20", "output": "224" }, { "input": "5 2 4 6 16", "output": "22" }, { "input": "54 2 52 50 188", "output": "1488" }, { "input": "536870912 60000000 72000000 271828 314159", "output": "4101909" }, { "input": "1000000000 1000000000 1 1 100", "output": "100000000000" }, { "input": "50 4 2 4 5", "output": "125" }, { "input": "198 56 56 122 118", "output": "366" }, { "input": "5 1000000000 1 12 15", "output": "75" }, { "input": "1000 6 12 5 6", "output": "913" }, { "input": "50 3 6 12 15", "output": "216" }, { "input": "333 300 300 300 300", "output": "300" }, { "input": "1 1000000000 1 1 2", "output": "2" }, { "input": "188 110 110 200 78", "output": "200" }, { "input": "100000 20 10 3 2", "output": "25000" }, { "input": "100 2 4 1 10", "output": "275" }, { "input": "1000000000 2 1000000000 1 1000000", "output": "500999999" }, { "input": "20 3 6 5 7", "output": "36" }, { "input": "50 4 6 4 5", "output": "72" }, { "input": "96 46 4 174 156", "output": "3936" }, { "input": "5 2 4 12 15", "output": "27" }, { "input": "12 3 6 100 1", "output": "400" }, { "input": "100 4 2 10 32", "output": "1600" }, { "input": "1232 3 6 30000 3", "output": "12300000" }, { "input": "20 3 6 5 4", "output": "30" }, { "input": "100 6 15 11 29", "output": "317" }, { "input": "10000000 4 8 100 200", "output": "375000000" }, { "input": "1000000000 12 24 2 4", "output": "249999998" }, { "input": "123 3 6 3000 1", "output": "123000" }, { "input": "401523968 1536 2664 271828 314159", "output": "117768531682" }, { "input": "9 2 4 3 5", "output": "16" }, { "input": "999999999 724362018 772432019 46201854 20017479", "output": "66219333" }, { "input": "100 2 4 1 1000", "output": "25025" }, { "input": "50 2 4 1 1000", "output": "12013" }, { "input": "1000000000 2 1 2 1", "output": "1500000000" }, { "input": "1000000000 2005034 2005046 15 12", "output": "13446" }, { "input": "1000000000 999999999 1000000000 1 1", "output": "2" }, { "input": "999999999 500000000 1 100 1000", "output": "999999999000" }, { "input": "50 8 6 3 4", "output": "44" }, { "input": "1000000000 1 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000000 999999862 999999818 15 12", "output": "27" }, { "input": "1000000000 10000019 10000019 21 17", "output": "2079" }, { "input": "20 6 4 8 2", "output": "32" }, { "input": "1000000000 1000000000 1 1 1", "output": "1000000000" }, { "input": "1000000000 12345678 123456789 1000000000 999999999", "output": "88999999992" }, { "input": "1000000000 2 999999937 100000000 100000000", "output": "50000000100000000" }, { "input": "1000000000 1 1 1000000000 999999999", "output": "1000000000000000000" }, { "input": "1000000000 50001 100003 10 10", "output": "299980" }, { "input": "1000000000 1000000000 3 1 1", "output": "333333334" }, { "input": "10000 44 49 114 514", "output": "130278" }, { "input": "30 5 15 2 1", "output": "12" }, { "input": "20 2 4 1 1", "output": "10" }, { "input": "100 8 12 5 6", "output": "88" } ]
1,672,809,168
2,147,483,647
Python 3
OK
TESTS
185
46
0
from math import gcd def lcm(a, b): return a // gcd(a, b) * b n, a, b, p, q = [int(i) for i in input().split()] s3 = n // lcm(a, b) s1 = n // a - s3 s2 = n // b - s3 s = s1 * p + s2 * q + max(p, q) * s3 print(s)
Title: Joty and Chocolate Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get. Input Specification: The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). Output Specification: Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['5 2 3 12 15\n', '20 2 3 3 5\n'] Demo Output: ['39\n', '51\n'] Note: none
```python from math import gcd def lcm(a, b): return a // gcd(a, b) * b n, a, b, p, q = [int(i) for i in input().split()] s3 = n // lcm(a, b) s1 = n // a - s3 s2 = n // b - s3 s = s1 * p + s2 * q + max(p, q) * s3 print(s) ```
3
103
A
Testing Pants for Sadness
PROGRAMMING
1,100
[ "greedy", "implementation", "math" ]
A. Testing Pants for Sadness
2
256
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
500
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "2999999999" }, { "input": "10\n5 7 8 1 10 3 6 4 10 6", "output": "294" }, { "input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8", "output": "24212" }, { "input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62", "output": "261115" }, { "input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644", "output": "2519223" }, { "input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950", "output": "24496504" }, { "input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899", "output": "685659563557" }, { "input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460", "output": "27409624352" }, { "input": "1\n84355694", "output": "84355694" }, { "input": "2\n885992042 510468669", "output": "1906929379" }, { "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\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1", "output": "2686" }, { "input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1", "output": "4667" } ]
1,595,836,810
2,147,483,647
Python 3
OK
TESTS
25
216
6,656,000
n = int(input()) a = list(map(int,input().split())) s = 0 for i in range(len(a)): s += (a[i]-1)*(i+1)+1 print(s)
Title: Testing Pants for Sadness Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case? Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. Output Specification: Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2\n1 1\n', '2\n2 2\n', '1\n10\n'] Demo Output: ['2', '5', '10'] Note: Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
```python n = int(input()) a = list(map(int,input().split())) s = 0 for i in range(len(a)): s += (a[i]-1)*(i+1)+1 print(s) ```
3.933602
841
A
Generous Kefa
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons.
Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.
[ "4 2\naabb\n", "6 3\naacaab\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
500
[ { "input": "4 2\naabb", "output": "YES" }, { "input": "6 3\naacaab", "output": "NO" }, { "input": "2 2\nlu", "output": "YES" }, { "input": "5 3\novvoo", "output": "YES" }, { "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES" }, { "input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "output": "NO" }, { "input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "YES" }, { "input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod", "output": "NO" }, { "input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl", "output": "YES" }, { "input": "18 6\njzwtnkvmscqhmdlsxy", "output": "YES" }, { "input": "21 2\nfscegcqgzesefghhwcexs", "output": "NO" }, { "input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc", "output": "YES" }, { "input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd", "output": "YES" }, { "input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv", "output": "YES" }, { "input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul", "output": "YES" }, { "input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii", "output": "NO" }, { "input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq", "output": "YES" }, { "input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb", "output": "YES" }, { "input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc", "output": "YES" }, { "input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab", "output": "YES" }, { "input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia", "output": "NO" }, { "input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf", "output": "YES" }, { "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb", "output": "YES" }, { "input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa", "output": "NO" }, { "input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo", "output": "YES" }, { "input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib", "output": "YES" }, { "input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf", "output": "YES" }, { "input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci", "output": "YES" }, { "input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn", "output": "YES" }, { "input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev", "output": "YES" }, { "input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss", "output": "YES" }, { "input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs", "output": "NO" }, { "input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc", "output": "NO" }, { "input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi", "output": "NO" }, { "input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah", "output": "NO" }, { "input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka", "output": "YES" }, { "input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq", "output": "YES" }, { "input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb", "output": "YES" }, { "input": "14 5\nfssmmsfffmfmmm", "output": "NO" }, { "input": "2 1\nff", "output": "NO" }, { "input": "2 1\nhw", "output": "YES" }, { "input": "2 2\nss", "output": "YES" }, { "input": "1 1\nl", "output": "YES" }, { "input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp", "output": "YES" }, { "input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj", "output": "YES" }, { "input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj", "output": "YES" }, { "input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "output": "YES" }, { "input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq", "output": "YES" }, { "input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt", "output": "YES" }, { "input": "1 2\na", "output": "YES" }, { "input": "3 1\nabb", "output": "NO" }, { "input": "2 1\naa", "output": "NO" }, { "input": "2 1\nab", "output": "YES" }, { "input": "6 2\naaaaaa", "output": "NO" }, { "input": "8 4\naaaaaaaa", "output": "NO" }, { "input": "4 2\naaaa", "output": "NO" }, { "input": "4 3\naaaa", "output": "NO" }, { "input": "1 3\na", "output": "YES" }, { "input": "4 3\nzzzz", "output": "NO" }, { "input": "4 1\naaaa", "output": "NO" }, { "input": "3 4\nabc", "output": "YES" }, { "input": "2 5\nab", "output": "YES" }, { "input": "2 4\nab", "output": "YES" }, { "input": "1 10\na", "output": "YES" }, { "input": "5 2\nzzzzz", "output": "NO" }, { "input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO" }, { "input": "4 1\nabab", "output": "NO" }, { "input": "4 1\nabcb", "output": "NO" }, { "input": "4 2\nabbb", "output": "NO" }, { "input": "5 2\nabccc", "output": "NO" }, { "input": "2 3\nab", "output": "YES" }, { "input": "4 3\nbbbs", "output": "YES" }, { "input": "10 2\nazzzzzzzzz", "output": "NO" }, { "input": "1 2\nb", "output": "YES" }, { "input": "1 3\nb", "output": "YES" }, { "input": "4 5\nabcd", "output": "YES" }, { "input": "4 6\naabb", "output": "YES" }, { "input": "5 2\naaaab", "output": "NO" }, { "input": "3 5\naaa", "output": "YES" }, { "input": "5 3\nazzzz", "output": "NO" }, { "input": "4 100\naabb", "output": "YES" }, { "input": "3 10\naaa", "output": "YES" }, { "input": "3 4\naaa", "output": "YES" }, { "input": "12 5\naaaaabbbbbbb", "output": "NO" }, { "input": "5 2\naabbb", "output": "NO" }, { "input": "10 5\nzzzzzzzzzz", "output": "NO" }, { "input": "2 4\naa", "output": "YES" }, { "input": "1 5\na", "output": "YES" }, { "input": "10 5\naaaaaaaaaa", "output": "NO" }, { "input": "6 3\naaaaaa", "output": "NO" }, { "input": "7 1\nabcdeee", "output": "NO" }, { "input": "18 3\naaaaaabbbbbbcccccc", "output": "NO" }, { "input": "8 2\naabbccdd", "output": "YES" }, { "input": "4 2\nzzzz", "output": "NO" }, { "input": "4 2\nabaa", "output": "NO" }, { "input": "3 2\naaa", "output": "NO" }, { "input": "3 1\nzzz", "output": "NO" }, { "input": "5 4\nzzzzz", "output": "NO" }, { "input": "6 2\naabbbc", "output": "NO" }, { "input": "3 6\naaa", "output": "YES" }, { "input": "2 1\nzz", "output": "NO" }, { "input": "10 3\naaaeeeeeee", "output": "NO" }, { "input": "4 5\naabb", "output": "YES" }, { "input": "3 1\naaa", "output": "NO" }, { "input": "5 2\naazzz", "output": "NO" }, { "input": "6 2\nabbbbc", "output": "NO" }, { "input": "4 2\nxxxx", "output": "NO" }, { "input": "6 3\nzzzzzz", "output": "NO" }, { "input": "3 2\nabb", "output": "YES" }, { "input": "3 2\nzzz", "output": "NO" }, { "input": "6 5\nzzzzzz", "output": "NO" }, { "input": "6 3\nbcaaaa", "output": "NO" }, { "input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "3 6\nabc", "output": "YES" } ]
1,586,042,559
2,147,483,647
Python 3
OK
TESTS
114
109
0
n, k = map(int, input().split()) s = input() count = [0] * 26 for i in s: nomer = ord(i) - 97 count[nomer] += 1 if max(count) > k: print('NO') else: print('YES')
Title: Generous Kefa Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons. Output Specification: Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary. Demo Input: ['4 2\naabb\n', '6 3\naacaab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
```python n, k = map(int, input().split()) s = input() count = [0] * 26 for i in s: nomer = ord(i) - 97 count[nomer] += 1 if max(count) > k: print('NO') else: print('YES') ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,595,625,344
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
20,172,800
l, r, a = [int(x) for x in input().split()] less = min(l, r) more = max(l, r) if less + a <= more: print(less + a) print(more + (a - (more - less)) // 2)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python l, r, a = [int(x) for x in input().split()] less = min(l, r) more = max(l, r) if less + a <= more: print(less + a) print(more + (a - (more - less)) // 2) ```
0
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin. Help Amr to achieve his goal in minimum number of steps.
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "1" }, { "input": "99125 26876 -21414 14176 17443", "output": "1" }, { "input": "8066 7339 19155 -90534 -60666", "output": "8" }, { "input": "100000 -100000 -100000 100000 100000", "output": "2" }, { "input": "10 20 0 41 0", "output": "2" }, { "input": "25 -64 -6 -56 64", "output": "2" }, { "input": "125 455 450 439 721", "output": "2" }, { "input": "5 6 3 7 2", "output": "1" }, { "input": "24 130 14786 3147 2140", "output": "271" }, { "input": "125 -363 176 93 330", "output": "2" }, { "input": "1 14 30 30 14", "output": "12" }, { "input": "25 96 13 7 2", "output": "2" }, { "input": "4 100000 -100000 100000 -100000", "output": "0" }, { "input": "1 3 4 2 5", "output": "1" }, { "input": "1 -3 3 2 6", "output": "3" }, { "input": "2 7 20 13 -5", "output": "7" }, { "input": "1 1 1 1 4", "output": "2" }, { "input": "249 -54242 -30537 -45023 -89682", "output": "121" }, { "input": "4 100000 -100000 100000 -99999", "output": "1" }, { "input": "97741 23818 78751 97583 26933", "output": "1" }, { "input": "56767 -29030 51625 79823 -56297", "output": "2" }, { "input": "98260 13729 74998 23701 9253", "output": "1" }, { "input": "67377 -80131 -90254 -57320 14102", "output": "1" }, { "input": "1 100000 100000 100000 -100000", "output": "100000" }, { "input": "19312 19470 82059 58064 62231", "output": "2" }, { "input": "67398 -68747 -79056 -34193 29400", "output": "1" }, { "input": "91099 37184 -71137 75650 -3655", "output": "1" }, { "input": "46456 -2621 -23623 -98302 -99305", "output": "2" }, { "input": "100 100000 -100000 100000 -99999", "output": "1" }, { "input": "1 100000 -100000 100000 -100000", "output": "0" }, { "input": "8 0 0 0 32", "output": "2" }, { "input": "100000 100000 1 -100000 0", "output": "2" } ]
1,695,393,013
2,147,483,647
Python 3
OK
TESTS
37
46
0
import math r, x, y, x_, y_ = map(int, input().split()) D = 2*r d = math.sqrt((x-x_)**2 + (y-y_)**2) print(math.ceil(d/D))
Title: Amr and Pins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin. Help Amr to achieve his goal in minimum number of steps. Input Specification: Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. Output Specification: Output a single integer — minimum number of steps required to move the center of the circle to the destination point. Demo Input: ['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n'] Demo Output: ['1\n', '3\n', '0\n'] Note: In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import math r, x, y, x_, y_ = map(int, input().split()) D = 2*r d = math.sqrt((x-x_)**2 + (y-y_)**2) print(math.ceil(d/D)) ```
3
1,000
B
Light It Up
PROGRAMMING
1,500
[ "greedy" ]
null
null
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp. The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 &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,408,415
2,147,483,647
Python 3
OK
TESTS
39
155
12,902,400
n, M = map(int, input().split()) a = [int(x) for x in input().split()] a.append(0) a.append(M) a.sort() on = 0 for i in range(1, len(a), 2): on += a[i] - a[i-1] h = on s = 0 for i in range(2, len(a), 2): s += a[i-1] - a[i-2] t = on - s h = max(h, s + M-a[i-1]-t - 1) print(h)
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 n, M = map(int, input().split()) a = [int(x) for x in input().split()] a.append(0) a.append(M) a.sort() on = 0 for i in range(1, len(a), 2): on += a[i] - a[i-1] h = on s = 0 for i in range(2, len(a), 2): s += a[i-1] - a[i-2] t = on - s h = max(h, s + M-a[i-1]-t - 1) print(h) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "input": "1000\n999", "output": "1" }, { "input": "1000\n1", "output": "250000" }, { "input": "2\n1", "output": "1" }, { "input": "2\n999", "output": "249001" }, { "input": "2\n998", "output": "248502" }, { "input": "999\n2", "output": "249001" }, { "input": "998\n2", "output": "248502" }, { "input": "2\n1000", "output": "249500" }, { "input": "1000\n2", "output": "249500" }, { "input": "1\n999", "output": "249500" }, { "input": "999\n1", "output": "249500" }, { "input": "188\n762", "output": "82656" }, { "input": "596\n777", "output": "8281" }, { "input": "773\n70", "output": "123904" }, { "input": "825\n729", "output": "2352" }, { "input": "944\n348", "output": "89102" }, { "input": "352\n445", "output": "2209" }, { "input": "529\n656", "output": "4096" }, { "input": "19\n315", "output": "22052" }, { "input": "138\n370", "output": "13572" }, { "input": "546\n593", "output": "576" }, { "input": "285\n242", "output": "484" }, { "input": "773\n901", "output": "4160" }, { "input": "892\n520", "output": "34782" }, { "input": "864\n179", "output": "117649" }, { "input": "479\n470", "output": "25" }, { "input": "967\n487", "output": "57840" }, { "input": "648\n106", "output": "73712" }, { "input": "58\n765", "output": "125316" }, { "input": "235\n56", "output": "8100" }, { "input": "285\n153", "output": "4422" }, { "input": "943\n13", "output": "216690" }, { "input": "675\n541", "output": "4556" }, { "input": "4\n912", "output": "206570" } ]
1,576,020,936
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
a = int(input()) b = int(input()) d = abs(a - b) r = d // 2 res = r * (r + 1) // 2 + (r + 1) * (r + 2) //2 print(res)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python a = int(input()) b = int(input()) d = abs(a - b) r = d // 2 res = r * (r + 1) // 2 + (r + 1) * (r + 2) //2 print(res) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,697,985,149
2,147,483,647
PyPy 3
OK
TESTS
71
278
1,536,000
m = 0 c = 0 for i in range(int(input())): a,b = [int(x) for x in input().split()] c += b-a m = max(m,c) print(m)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python m = 0 c = 0 for i in range(int(input())): a,b = [int(x) for x in input().split()] c += b-a m = max(m,c) print(m) ```
3
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1", "output": "1891" }, { "input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2", "output": "1688" }, { "input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12", "output": "1391" }, { "input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32", "output": "368" }, { "input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1", "output": "435" }, { "input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100", "output": "326" }, { "input": "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1", "output": "139" }, { "input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86", "output": "514" }, { "input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1", "output": "586" }, { "input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1", "output": "384" }, { "input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1", "output": "174" }, { "input": "81 4131\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 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "807" }, { "input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96", "output": "490" }, { "input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1", "output": "284" }, { "input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1", "output": "1589" }, { "input": "10 100\n1 1 1 1 1 1 1 1 1 1", "output": "18" }, { "input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99", "output": "1017" }, { "input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 6\n1", "output": "1" }, { "input": "1 5\n1", "output": "0" }, { "input": "1 3\n4", "output": "-1" }, { "input": "3 24\n2 1 2", "output": "-1" } ]
1,605,383,543
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
307,200
def solve(d,t): info1 = d.split() info2 = t.split() a = [int(x) for x in info2] diff = int(info1[1]) - sum(a) - 10*(len(a)-1) if diff >= 0: num = diff // 5 num_plus = diff % 5 number_of_jokes = 5*num + num_plus return number_of_jokes else: return -1 d = input() t = input() print(solve(d,t))
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. Input Specification: The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). Output Specification: If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Demo Input: ['3 30\n2 2 1\n', '3 20\n2 1 1\n'] Demo Output: ['5\n', '-1\n'] Note: Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
```python def solve(d,t): info1 = d.split() info2 = t.split() a = [int(x) for x in info2] diff = int(info1[1]) - sum(a) - 10*(len(a)-1) if diff >= 0: num = diff // 5 num_plus = diff % 5 number_of_jokes = 5*num + num_plus return number_of_jokes else: return -1 d = input() t = input() print(solve(d,t)) ```
0
946
A
Partition
PROGRAMMING
800
[ "greedy" ]
null
null
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n" ]
[ "3\n", "120\n" ]
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
0
[ { "input": "3\n1 -2 0", "output": "3" }, { "input": "6\n16 23 16 15 42 8", "output": "120" }, { "input": "1\n-1", "output": "1" }, { "input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100", "output": "10000" }, { "input": "2\n-1 5", "output": "6" }, { "input": "3\n-2 0 1", "output": "3" }, { "input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3", "output": "94" }, { "input": "4\n1 -1 1 -1", "output": "4" }, { "input": "4\n100 -100 100 -100", "output": "400" }, { "input": "3\n-2 -5 10", "output": "17" }, { "input": "5\n1 -2 3 -4 5", "output": "15" }, { "input": "3\n-100 100 -100", "output": "300" }, { "input": "6\n1 -1 1 -1 1 -1", "output": "6" }, { "input": "6\n2 -2 2 -2 2 -2", "output": "12" }, { "input": "9\n12 93 -2 0 0 0 3 -3 -9", "output": "122" }, { "input": "6\n-1 2 4 -5 -3 55", "output": "70" }, { "input": "6\n-12 8 68 -53 1 -15", "output": "157" }, { "input": "2\n-2 1", "output": "3" }, { "input": "3\n100 -100 100", "output": "300" }, { "input": "5\n100 100 -1 -100 2", "output": "303" }, { "input": "6\n-5 -4 -3 -2 -1 0", "output": "15" }, { "input": "6\n4 4 4 -3 -3 2", "output": "20" }, { "input": "2\n-1 2", "output": "3" }, { "input": "1\n100", "output": "100" }, { "input": "5\n-1 -2 3 1 2", "output": "9" }, { "input": "5\n100 -100 100 -100 100", "output": "500" }, { "input": "5\n1 -1 1 -1 1", "output": "5" }, { "input": "4\n0 0 0 -1", "output": "1" }, { "input": "5\n100 -100 -1 2 100", "output": "303" }, { "input": "2\n75 0", "output": "75" }, { "input": "4\n55 56 -59 -58", "output": "228" }, { "input": "2\n9 71", "output": "80" }, { "input": "2\n9 70", "output": "79" }, { "input": "2\n9 69", "output": "78" }, { "input": "2\n100 -100", "output": "200" }, { "input": "4\n-9 4 -9 5", "output": "27" }, { "input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36", "output": "2348" }, { "input": "7\n-1 2 2 2 -1 2 -1", "output": "11" }, { "input": "6\n-12 8 17 -69 7 -88", "output": "201" }, { "input": "3\n1 -2 5", "output": "8" }, { "input": "6\n-2 3 -4 5 6 -1", "output": "21" }, { "input": "2\n-5 1", "output": "6" }, { "input": "4\n2 2 -2 4", "output": "10" }, { "input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72", "output": "3991" }, { "input": "5\n5 5 -10 -1 1", "output": "22" }, { "input": "3\n-1 2 3", "output": "6" }, { "input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1", "output": "3787" }, { "input": "5\n-1 -2 1 2 3", "output": "9" }, { "input": "4\n2 2 -2 -2", "output": "8" }, { "input": "6\n100 -100 100 -100 100 -100", "output": "600" }, { "input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41", "output": "4362" }, { "input": "2\n-1 1", "output": "2" }, { "input": "3\n1 -2 100", "output": "103" }, { "input": "5\n1 -2 3 1 2", "output": "9" }, { "input": "10\n100 -10 -100 10 10 10 10 10 10 10", "output": "280" }, { "input": "4\n2 0 -2 4", "output": "8" }, { "input": "4\n3 -3 1 -1", "output": "8" }, { "input": "3\n1 -1 1", "output": "3" }, { "input": "4\n2 5 -2 4", "output": "13" }, { "input": "2\n-2 2", "output": "4" }, { "input": "3\n1 -2 1", "output": "4" }, { "input": "5\n-1 -2 1 1 -1", "output": "6" }, { "input": "4\n-2 0 2 4", "output": "8" }, { "input": "8\n-42 7 87 -16 -5 65 -88 1", "output": "311" }, { "input": "3\n1 -3 4", "output": "8" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n-1 2 -1", "output": "4" }, { "input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95", "output": "761" }, { "input": "4\n-1 1 -1 1", "output": "4" }, { "input": "5\n-1 2 1 1 1", "output": "6" }, { "input": "3\n1 1 1", "output": "3" } ]
1,601,196,895
2,147,483,647
Python 3
OK
TESTS
72
109
0
n=int(input()) A=input().split() B,C=[],[] for i in range(n): A[i]=int(A[i]) if A[i]>0: B.append(A[i]) else: C.append(A[i]) print(sum(B)-sum(C))
Title: Partition Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. Output Specification: Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. Demo Input: ['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n'] Demo Output: ['3\n', '120\n'] Note: In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
```python n=int(input()) A=input().split() B,C=[],[] for i in range(n): A[i]=int(A[i]) if A[i]>0: B.append(A[i]) else: C.append(A[i]) print(sum(B)-sum(C)) ```
3
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { "input": "999999999", "output": "Ehab" }, { "input": "123123123", "output": "Ehab" }, { "input": "22222221", "output": "Ehab" }, { "input": "22222220", "output": "Mahmoud" }, { "input": "3", "output": "Ehab" }, { "input": "4", "output": "Mahmoud" }, { "input": "6", "output": "Mahmoud" }, { "input": "7", "output": "Ehab" }, { "input": "8", "output": "Mahmoud" }, { "input": "9", "output": "Ehab" }, { "input": "10", "output": "Mahmoud" }, { "input": "536870912", "output": "Mahmoud" }, { "input": "536870913", "output": "Ehab" }, { "input": "536870911", "output": "Ehab" } ]
1,656,133,288
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
print'Mahmoud'if input()%2==0 else'Ehab'
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. Output Specification: Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. Demo Input: ['1\n', '2\n'] Demo Output: ['Ehab', 'Mahmoud'] Note: In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
```python print'Mahmoud'if input()%2==0 else'Ehab' ```
-1
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,698,143,439
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
san = int(input()) soz = input() count = 0 for i in range(len(soz)): if soz[i] == soz[i-1]: count+=1 print(count)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python san = int(input()) soz = input() count = 0 for i in range(len(soz)): if soz[i] == soz[i-1]: count+=1 print(count) ```
0
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, { "input": "20\n44444444444444444444", "output": "YES" }, { "input": "2\n44", "output": "YES" }, { "input": "10\n4745474547", "output": "NO" }, { "input": "14\n77770004444444", "output": "NO" }, { "input": "10\n4747777744", "output": "YES" }, { "input": "10\n1234567890", "output": "NO" }, { "input": "50\n44444444444444444444444444444444444444444444444444", "output": "YES" }, { "input": "50\n44444444444444444444444444444444444444444444444447", "output": "NO" }, { "input": "50\n74444444444444444444444444444444444444444444444444", "output": "NO" }, { "input": "50\n07777777777777777777777777777777777777777777777770", "output": "NO" }, { "input": "50\n77777777777777777777777777777777777777777777777777", "output": "YES" }, { "input": "50\n44747747774474747747747447777447774747447477444474", "output": "YES" }, { "input": "48\n447474444777444474747747744774447444747474774474", "output": "YES" }, { "input": "32\n74474474777444474444747774474774", "output": "YES" }, { "input": "40\n4747777444447747777447447747447474774777", "output": "YES" }, { "input": "10\n4477477444", "output": "YES" }, { "input": "18\n447747474447744747", "output": "YES" }, { "input": "26\n44747744444774744774474447", "output": "YES" }, { "input": "50\n44707747774474747747747447777447774747447477444474", "output": "NO" }, { "input": "40\n4747777444447737777447447747447474774777", "output": "NO" }, { "input": "36\n764477744747444444447747747474744444", "output": "NO" }, { "input": "22\n4477407474777477744447", "output": "NO" }, { "input": "32\n74274474777444474444747774474774", "output": "NO" }, { "input": "16\n4744447974444747", "output": "NO" }, { "input": "2\n11", "output": "NO" }, { "input": "2\n22", "output": "NO" }, { "input": "2\n33", "output": "NO" }, { "input": "2\n74", "output": "NO" }, { "input": "2\n55", "output": "NO" }, { "input": "2\n66", "output": "NO" }, { "input": "2\n77", "output": "YES" }, { "input": "2\n88", "output": "NO" }, { "input": "2\n99", "output": "NO" }, { "input": "4\n4004", "output": "NO" }, { "input": "14\n00077774444444", "output": "NO" }, { "input": "6\n004444", "output": "NO" }, { "input": "4\n0044", "output": "NO" }, { "input": "14\n77771114444444", "output": "NO" }, { "input": "14\n44444447777000", "output": "NO" }, { "input": "6\n004774", "output": "NO" } ]
1,470,927,759
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
122
4,608,000
n=int(input()) s=input() s1=0 s2=0 for i in range(n//2): if s[i]!=s[n-i-1]: import sys print('NO') sys.exit(0) print ('YES')
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python n=int(input()) s=input() s1=0 s2=0 for i in range(n//2): if s[i]!=s[n-i-1]: import sys print('NO') sys.exit(0) print ('YES') ```
0
784
B
Kids' Riddle
PROGRAMMING
2,000
[ "*special" ]
null
null
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
The input contains a single integer *n* (0<=≤<=*n*<=≤<=2000000000).
Output a single integer.
[ "11\n", "14\n", "61441\n", "571576\n", "2128506\n" ]
[ "2\n", "0\n", "2\n", "10\n", "3\n" ]
none
0
[ { "input": "11", "output": "2" }, { "input": "14", "output": "0" }, { "input": "61441", "output": "2" }, { "input": "571576", "output": "10" }, { "input": "2128506", "output": "3" }, { "input": "0", "output": "1" }, { "input": "2000000000", "output": "4" }, { "input": "143165576", "output": "14" }, { "input": "1741", "output": "2" }, { "input": "1919020031", "output": "3" }, { "input": "1795248373", "output": "5" }, { "input": "1818960378", "output": "5" }, { "input": "1285316221", "output": "3" }, { "input": "1309028227", "output": "5" }, { "input": "1304312649", "output": "8" }, { "input": "1180540990", "output": "5" }, { "input": "1204252996", "output": "3" }, { "input": "1199537418", "output": "4" }, { "input": "1075765759", "output": "2" }, { "input": "724264821", "output": "5" }, { "input": "747976826", "output": "4" }, { "input": "624205168", "output": "4" }, { "input": "619489590", "output": "4" }, { "input": "643201595", "output": "5" }, { "input": "638486017", "output": "6" }, { "input": "514714359", "output": "3" }, { "input": "833393692", "output": "3" }, { "input": "186925426", "output": "4" }, { "input": "210637432", "output": "4" }, { "input": "58438190", "output": "4" } ]
1,522,576,514
2,147,483,647
Python 3
OK
TESTS
30
78
7,065,600
n=int(input()) sumx=0 if(n==0): print(1) else: while(n>0): a=n%16 if(a<10): if(a==0 or a==4 or a==6 or a==9): sumx+=1 elif(a==8): sumx+=2 elif(a==10 or a==13): sumx+=1 elif(a==11): sumx+=2 n=n//16 print(sumx)
Title: Kids' Riddle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? Input Specification: The input contains a single integer *n* (0<=≤<=*n*<=≤<=2000000000). Output Specification: Output a single integer. Demo Input: ['11\n', '14\n', '61441\n', '571576\n', '2128506\n'] Demo Output: ['2\n', '0\n', '2\n', '10\n', '3\n'] Note: none
```python n=int(input()) sumx=0 if(n==0): print(1) else: while(n>0): a=n%16 if(a<10): if(a==0 or a==4 or a==6 or a==9): sumx+=1 elif(a==8): sumx+=2 elif(a==10 or a==13): sumx+=1 elif(a==11): sumx+=2 n=n//16 print(sumx) ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,690,211,499
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
62
0
n, m = list(map(int,input().split())) ans = 0 while n>0: ans += n n//=m print(ans)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python n, m = list(map(int,input().split())) ans = 0 while n>0: ans += n n//=m print(ans) ```
0
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,675,911,870
2,147,483,647
Python 3
OK
TESTS
45
92
0
[n, m] = list(map(int, input().split(" "))) number = n + 1 isNotPrime = True while (isNotPrime): temp = number - 1 isNotPrime = False while (temp > 1): if (number % temp == 0): isNotPrime = True temp -= 1 number += 1 if (number - 1 == m): print("YES") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python [n, m] = list(map(int, input().split(" "))) number = n + 1 isNotPrime = True while (isNotPrime): temp = number - 1 isNotPrime = False while (temp > 1): if (number % temp == 0): isNotPrime = True temp -= 1 number += 1 if (number - 1 == m): print("YES") else: print("NO") ```
3.977
456
B
Fedya and Maths
PROGRAMMING
1,200
[ "math", "number theory" ]
null
null
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language).
The single line contains a single integer *n* (0<=≤<=*n*<=≤<=10105). The number doesn't contain any leading zeroes.
Print the value of the expression without leading zeros.
[ "4\n", "124356983594583453458888889\n" ]
[ "4\n", "0\n" ]
Operation *x* *mod* *y* means taking remainder after division *x* by *y*. Note to the first sample: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/825f244180bb10323db01645118c3cfdb312fa89.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4", "output": "4" }, { "input": "124356983594583453458888889", "output": "0" }, { "input": "2", "output": "0" }, { "input": "7854", "output": "0" }, { "input": "584660", "output": "4" }, { "input": "464", "output": "4" }, { "input": "192329", "output": "0" }, { "input": "85447", "output": "0" }, { "input": "956", "output": "4" }, { "input": "83", "output": "0" }, { "input": "33", "output": "0" }, { "input": "64", "output": "4" }, { "input": "971836", "output": "4" }, { "input": "578487", "output": "0" }, { "input": "71752", "output": "4" }, { "input": "2563", "output": "0" }, { "input": "51494", "output": "0" }, { "input": "247", "output": "0" }, { "input": "52577", "output": "0" }, { "input": "13", "output": "0" }, { "input": "26232", "output": "4" }, { "input": "0", "output": "4" }, { "input": "10", "output": "0" }, { "input": "12", "output": "4" }, { "input": "8", "output": "4" }, { "input": "1", "output": "0" } ]
1,664,532,341
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
a=input() print("4") #111111111111111111111111111111111111111111111111111111111111111111111111
Title: Fedya and Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language). Input Specification: The single line contains a single integer *n* (0<=≤<=*n*<=≤<=10105). The number doesn't contain any leading zeroes. Output Specification: Print the value of the expression without leading zeros. Demo Input: ['4\n', '124356983594583453458888889\n'] Demo Output: ['4\n', '0\n'] Note: Operation *x* *mod* *y* means taking remainder after division *x* by *y*. Note to the first sample: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/825f244180bb10323db01645118c3cfdb312fa89.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a=input() print("4") #111111111111111111111111111111111111111111111111111111111111111111111111 ```
0
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
1,633,235,766
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
102,400
a,b=list(map(int,input().split())) g={} def recr(x,y): if (x,y) in g: return g[x,y] if x<=0 or y<=0: return 0 ans=1+max(recr(x-2,y+1),recr(x+1,y-2)) g[(x,y)]=ans return ans print(recr(a,b))
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. Input Specification: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. Output Specification: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Demo Input: ['3 5\n', '4 4\n'] Demo Output: ['6\n', '5\n'] Note: In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
```python a,b=list(map(int,input().split())) g={} def recr(x,y): if (x,y) in g: return g[x,y] if x<=0 or y<=0: return 0 ans=1+max(recr(x-2,y+1),recr(x+1,y-2)) g[(x,y)]=ans return ans print(recr(a,b)) ```
0
409
C
Magnum Opus
PROGRAMMING
1,700
[ "*special" ]
null
null
Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via. Fac et spera, Vale, Nicolas Flamel
The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100).
Print a single integer.
[ "2 4 6 8 10\n" ]
[ "1\n" ]
none
0
[ { "input": "2 4 6 8 10", "output": "1" }, { "input": "50 27 17 31 89", "output": "4" }, { "input": "50 87 29 81 21", "output": "5" }, { "input": "74 21 36 68 80", "output": "9" }, { "input": "75 82 48 95 12", "output": "3" }, { "input": "41 85 14 43 23", "output": "5" }, { "input": "94 28 3 29 9", "output": "1" }, { "input": "94 21 36 89 20", "output": "5" }, { "input": "60 92 82 71 53", "output": "10" }, { "input": "46 68 3 0 51", "output": "0" }, { "input": "12 39 3 50 84", "output": "1" }, { "input": "12 31 47 31 84", "output": "4" }, { "input": "79 2 93 92 16", "output": "2" }, { "input": "65 46 3 77 81", "output": "1" }, { "input": "31 38 47 26 13", "output": "3" }, { "input": "42 9 59 19 24", "output": "2" }, { "input": "51 19 70 5 78", "output": "0" }, { "input": "51 56 14 99 21", "output": "5" }, { "input": "28 49 58 47 54", "output": "6" }, { "input": "3 26 69 33 18", "output": "3" }, { "input": "14 63 14 25 18", "output": "3" }, { "input": "81 67 58 8 51", "output": "1" }, { "input": "81 26 69 0 84", "output": "0" }, { "input": "32 36 80 54 48", "output": "7" }, { "input": "0 74 25 35 48", "output": "0" }, { "input": "67 66 69 96 92", "output": "13" }, { "input": "52 43 80 14 79", "output": "2" }, { "input": "18 13 91 64 22", "output": "5" }, { "input": "19 84 69 57 55", "output": "8" }, { "input": "71 61 47 9 19", "output": "1" }, { "input": "0 0 0 0 0", "output": "0" }, { "input": "1 1 2 7 4", "output": "1" }, { "input": "1 0 2 7 4", "output": "0" }, { "input": "1 1 2 6 4", "output": "0" }, { "input": "1 1 1 7 4", "output": "0" }, { "input": "1 2 2 7 4", "output": "1" }, { "input": "1 1 3 7 4", "output": "1" }, { "input": "2 2 3 14 8", "output": "1" }, { "input": "100 100 100 100 100", "output": "14" } ]
1,646,284,114
2,147,483,647
Python 3
OK
TESTS
39
46
0
a = [int(i) for i in input().split()] print(min(a[0], a[1], a[2] // 2, a[3] // 7, a[4] // 4))
Title: Magnum Opus Time Limit: None seconds Memory Limit: None megabytes Problem Description: Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via. Fac et spera, Vale, Nicolas Flamel Input Specification: The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100). Output Specification: Print a single integer. Demo Input: ['2 4 6 8 10\n'] Demo Output: ['1\n'] Note: none
```python a = [int(i) for i in input().split()] print(min(a[0], a[1], a[2] // 2, a[3] // 7, a[4] // 4)) ```
3
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", "output": "2" }, { "input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "output": "6" }, { "input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "output": "6" }, { "input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987", "output": "6" }, { "input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222", "output": "6" }, { "input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485", "output": "8" }, { "input": "1\n1000 1000", "output": "1" }, { "input": "1\n500 1000", "output": "1" }, { "input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11", "output": "11" }, { "input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2", "output": "0" }, { "input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330", "output": "30" }, { "input": "2\n7 7\n5 359", "output": "2" }, { "input": "2\n465 706\n706 706", "output": "1" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 1\n1 1\n2 2", "output": "1" }, { "input": "5\n1 1\n1 2\n2 3\n3 4\n4 3", "output": "1" }, { "input": "3\n1 2\n1 2\n1 1", "output": "1" } ]
1,615,454,062
2,147,483,647
PyPy 3
OK
TESTS
34
216
1,228,800
n=int(input()) l=[] for i in range(n): p=[] a,b=map(int,input().split()) p.append(a) p.append(b) l.append(p) ans=0 for i in range(n): for j in range(n): if(i!=j and l[i][0]==l[j][1]): ans=ans+1 break print(n-ans)
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n'] Demo Output: ['4\n', '0\n'] Note: none
```python n=int(input()) l=[] for i in range(n): p=[] a,b=map(int,input().split()) p.append(a) p.append(b) l.append(p) ans=0 for i in range(n): for j in range(n): if(i!=j and l[i][0]==l[j][1]): ans=ans+1 break print(n-ans) ```
3
919
D
Substring
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs" ]
null
null
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
[ "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n" ]
[ "3\n", "-1\n", "4\n" ]
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
1,500
[ { "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "output": "3" }, { "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "output": "-1" }, { "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "output": "4" }, { "input": "1 1\nf\n1 1", "output": "-1" }, { "input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8", "output": "2" }, { "input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6", "output": "3" }, { "input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1", "output": "-1" }, { "input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4", "output": "-1" } ]
1,622,616,502
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
108
102,400
from collections import deque n,m=map(int,input().split()) s=input() graph=[ [] for i in range(n)] dp=[ [0]*26 for i in rnage(n)] degree=[0]*n degree[0]=0 for i in range(m): x,y=map(int,input().split()) graph[x-1].append(y-1) degree[i]+=1 d=deque() for i in range(n): if degree[i]==0: d.append(i) dp[i][ord(s[i])-97]+=1 c=0 m=1 while(d): c+=1 x=d.popleft() for i in graph[x]: for j in range(26): dp[i][j]=max(dp[i][j],dp[x][j]) degree[i]-=1 if degree[i]==0: dp[i][ord(s[i])-97]+=1 for j in range(26): m=max(m,dp[i][j]) d.append(i) if c!=n: print(-1) else: print(m)
Title: Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest. Input Specification: The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected. Output Specification: Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead. Demo Input: ['5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n', '6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n', '10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n'] Demo Output: ['3\n', '-1\n', '4\n'] Note: In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
```python from collections import deque n,m=map(int,input().split()) s=input() graph=[ [] for i in range(n)] dp=[ [0]*26 for i in rnage(n)] degree=[0]*n degree[0]=0 for i in range(m): x,y=map(int,input().split()) graph[x-1].append(y-1) degree[i]+=1 d=deque() for i in range(n): if degree[i]==0: d.append(i) dp[i][ord(s[i])-97]+=1 c=0 m=1 while(d): c+=1 x=d.popleft() for i in graph[x]: for j in range(26): dp[i][j]=max(dp[i][j],dp[x][j]) degree[i]-=1 if degree[i]==0: dp[i][ord(s[i])-97]+=1 for j in range(26): m=max(m,dp[i][j]) d.append(i) if c!=n: print(-1) else: print(m) ```
-1
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem.
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95", "output": "2" }, { "input": "51 52", "output": "2" }, { "input": "47 52", "output": "2" }, { "input": "38 98", "output": "2" }, { "input": "30 37", "output": "2" }, { "input": "56 92", "output": "2" }, { "input": "900000000 1000000000", "output": "2" }, { "input": "37622224 162971117", "output": "2" }, { "input": "760632746 850720703", "output": "2" }, { "input": "908580370 968054552", "output": "2" }, { "input": "951594860 953554446", "output": "2" }, { "input": "347877978 913527175", "output": "2" }, { "input": "620769961 988145114", "output": "2" }, { "input": "820844234 892579936", "output": "2" }, { "input": "741254764 741254768", "output": "2" }, { "input": "80270976 80270977", "output": "2" }, { "input": "392602363 392602367", "output": "2" }, { "input": "519002744 519002744", "output": "519002744" }, { "input": "331900277 331900277", "output": "331900277" }, { "input": "419873015 419873018", "output": "2" }, { "input": "349533413 349533413", "output": "349533413" }, { "input": "28829775 28829776", "output": "2" }, { "input": "568814539 568814539", "output": "568814539" }, { "input": "720270740 720270743", "output": "2" }, { "input": "871232720 871232722", "output": "2" }, { "input": "305693653 305693653", "output": "305693653" }, { "input": "634097178 634097179", "output": "2" }, { "input": "450868287 450868290", "output": "2" }, { "input": "252662256 252662260", "output": "2" }, { "input": "575062045 575062049", "output": "2" }, { "input": "273072892 273072894", "output": "2" }, { "input": "770439256 770439256", "output": "770439256" }, { "input": "2 1000000000", "output": "2" }, { "input": "6 8", "output": "2" }, { "input": "2 879190747", "output": "2" }, { "input": "5 5", "output": "5" }, { "input": "999999937 999999937", "output": "999999937" }, { "input": "3 3", "output": "3" }, { "input": "5 100", "output": "2" }, { "input": "2 2", "output": "2" }, { "input": "3 18", "output": "2" }, { "input": "7 7", "output": "7" }, { "input": "39916801 39916801", "output": "39916801" }, { "input": "3 8", "output": "2" }, { "input": "13 13", "output": "13" }, { "input": "4 8", "output": "2" }, { "input": "3 12", "output": "2" }, { "input": "6 12", "output": "2" }, { "input": "999999103 999999103", "output": "999999103" }, { "input": "100000007 100000007", "output": "100000007" }, { "input": "3 99", "output": "2" }, { "input": "999999733 999999733", "output": "999999733" }, { "input": "5 10", "output": "2" }, { "input": "982451653 982451653", "output": "982451653" }, { "input": "999900001 1000000000", "output": "2" }, { "input": "999727999 999727999", "output": "999727999" }, { "input": "2 999999999", "output": "2" }, { "input": "242 244", "output": "2" }, { "input": "3 10", "output": "2" }, { "input": "15 27", "output": "2" }, { "input": "998244353 998244353", "output": "998244353" }, { "input": "5 15", "output": "2" }, { "input": "999999797 999999797", "output": "999999797" }, { "input": "2 3", "output": "2" }, { "input": "999999929 999999929", "output": "999999929" }, { "input": "3 111111", "output": "2" }, { "input": "12 18", "output": "2" }, { "input": "479001599 479001599", "output": "479001599" }, { "input": "10000019 10000019", "output": "10000019" }, { "input": "715827883 715827883", "output": "715827883" }, { "input": "999992977 999992977", "output": "999992977" }, { "input": "11 11", "output": "11" }, { "input": "29 29", "output": "29" }, { "input": "1000003 1000003", "output": "1000003" }, { "input": "6 15", "output": "2" }, { "input": "1200007 1200007", "output": "1200007" }, { "input": "3 1000000000", "output": "2" }, { "input": "990000023 990000023", "output": "990000023" }, { "input": "1717 1717", "output": "1717" }, { "input": "141650963 141650963", "output": "141650963" }, { "input": "1002523 1002523", "output": "1002523" }, { "input": "900000011 900000011", "output": "900000011" }, { "input": "104729 104729", "output": "104729" }, { "input": "4 12", "output": "2" }, { "input": "100003 100003", "output": "100003" }, { "input": "17 17", "output": "17" }, { "input": "10 100", "output": "2" } ]
1,691,698,167
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
23
93
3,481,600
l, r = map(int, input().split()) if l == r: flag = 1 for i in range(l, int(l ** 0.5 + 1)): if l % i == 0: flag = 0 print(i) break if flag: pritn(l) else: print(2)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. Input Specification: The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). Output Specification: Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Demo Input: ['19 29\n', '3 6\n'] Demo Output: ['2\n', '3\n'] Note: Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
```python l, r = map(int, input().split()) if l == r: flag = 1 for i in range(l, int(l ** 0.5 + 1)): if l % i == 0: flag = 0 print(i) break if flag: pritn(l) else: print(2) ```
-1
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
1,697,410,283
2,147,483,647
PyPy 3-64
OK
TESTS
49
62
0
#https://codeforces.com/problemset/problem/450/A import math (n,m) = (int(x) for x in input().split()) a = [int(x) for x in input().split()] max_value = 0 for index in range(n): curr_value = math.ceil(a[index]/m) if curr_value >= max_value: max_value = curr_value answer = index+1 print(answer)
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output a single integer, representing the number of the last child. Demo Input: ['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n'] Demo Output: ['4\n', '6\n'] Note: Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
```python #https://codeforces.com/problemset/problem/450/A import math (n,m) = (int(x) for x in input().split()) a = [int(x) for x in input().split()] max_value = 0 for index in range(n): curr_value = math.ceil(a[index]/m) if curr_value >= max_value: max_value = curr_value answer = index+1 print(answer) ```
3
615
D
Multipliers
PROGRAMMING
2,000
[ "math", "number theory" ]
null
null
Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the password to the secret data base. Now he wants to calculate this value.
The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of primes in factorization of *n*. The second line contains *m* primes numbers *p**i* (2<=≤<=*p**i*<=≤<=200<=000).
Print one integer — the product of all divisors of *n* modulo 109<=+<=7.
[ "2\n2 3\n", "3\n2 3 2\n" ]
[ "36\n", "1728\n" ]
In the first sample *n* = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36. In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728.
2,000
[ { "input": "2\n2 3", "output": "36" }, { "input": "3\n2 3 2", "output": "1728" }, { "input": "1\n2017", "output": "2017" }, { "input": "2\n63997 63997", "output": "135893224" }, { "input": "5\n11 7 11 7 11", "output": "750455957" }, { "input": "5\n2 2 2 2 2", "output": "32768" }, { "input": "4\n3 3 3 5", "output": "332150625" }, { "input": "6\n101 103 107 109 101 103", "output": "760029909" }, { "input": "10\n3 3 3 3 3 3 3 3 3 3", "output": "555340537" }, { "input": "5\n7 5 2 3 13", "output": "133580280" }, { "input": "23\n190979 191627 93263 72367 52561 188317 198397 24979 70313 105239 86263 78697 6163 7673 84137 199967 14657 84391 101009 16231 175103 24239 123289", "output": "727083628" }, { "input": "7\n34429 104287 171293 101333 104287 34429 104287", "output": "249330396" }, { "input": "27\n151153 29429 91411 91411 194507 194819 91411 91411 194507 181211 194507 131363 9371 194819 181211 194507 151153 91411 91411 192391 192391 151153 151153 194507 192391 192391 194819", "output": "132073405" }, { "input": "47\n9041 60013 53609 82939 160861 123377 74383 74383 184039 19867 123377 101879 74383 193603 123377 115331 101879 53609 74383 115331 51869 51869 184039 193603 91297 160861 160861 115331 184039 51869 123377 74383 160861 74383 115331 115331 51869 74383 19867 193603 193603 115331 184039 9041 53609 53609 193603", "output": "648634399" }, { "input": "67\n98929 19079 160079 181891 17599 91807 19079 98929 182233 92647 77477 98929 98639 182233 181891 182233 160079 98929 19079 98639 114941 98929 161341 91807 160079 22777 132361 92647 98929 77477 182233 103913 160079 77477 55711 77477 77477 182233 114941 91807 98929 19079 104393 182233 182233 131009 132361 16883 161341 103913 16883 98929 182233 114941 92647 92647 104393 132361 181891 114941 19079 91807 114941 132361 98639 161341 182233", "output": "5987226" }, { "input": "44\n73 59 17 41 37 7 71 47 29 83 67 17 53 61 43 43 3 23 29 11 7 83 61 79 31 37 37 83 41 71 11 19 83 2 83 73 7 67 83 13 2 53 31 47", "output": "464170294" }, { "input": "100\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541", "output": "72902143" }, { "input": "130\n2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 17 17 17 17 17 17 17 17 17 17 19 19 19 19 19 19 19 19 19 19 23 23 23 23 23 23 23 23 23 23 29 29 29 29 29 29 29 29 29 29 31 31 31 31 31 31 31 31 31 31 37 37 37 37 37 37 37 37 37 37 41 41 41 41 41 41 41 41 41 41", "output": "869075922" }, { "input": "101\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 2", "output": "918713851" }, { "input": "42\n1657 1871 2423 3037 5023 5099 5449 5701 6361 6619 7393 7489 8179 9743 9791 9907 12289 12457 13063 13933 14947 16141 16829 16943 17191 17863 20161 20947 21661 22727 23197 23201 23813 24023 24181 24223 24391 26479 28619 30529 32441 32611", "output": "468186759" } ]
1,605,258,952
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
import math m = int(input()) n = 1 u = 1 a = list(map(int, input().split())) for i in range(len(a)): n *= a[i] for i in range(1, int(math.sqrt(n)) + 1, 1): if int(n / i) * int(i) == n: u *= i % 1000000007; if int(i) * int(n / i) == n and i * i != n: u *= (n / i) % 1000000007 print(i) u %= 1000000007 print(int(u))
Title: Multipliers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the password to the secret data base. Now he wants to calculate this value. Input Specification: The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of primes in factorization of *n*. The second line contains *m* primes numbers *p**i* (2<=≤<=*p**i*<=≤<=200<=000). Output Specification: Print one integer — the product of all divisors of *n* modulo 109<=+<=7. Demo Input: ['2\n2 3\n', '3\n2 3 2\n'] Demo Output: ['36\n', '1728\n'] Note: In the first sample *n* = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36. In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728.
```python import math m = int(input()) n = 1 u = 1 a = list(map(int, input().split())) for i in range(len(a)): n *= a[i] for i in range(1, int(math.sqrt(n)) + 1, 1): if int(n / i) * int(i) == n: u *= i % 1000000007; if int(i) * int(n / i) == n and i * i != n: u *= (n / i) % 1000000007 print(i) u %= 1000000007 print(int(u)) ```
0
670
D1
Magic Powder - 1
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation" ]
null
null
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients. Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies. Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
[ "3 1\n2 1 4\n11 3 16\n", "4 3\n4 3 5 6\n11 12 14 20\n" ]
[ "4\n", "3\n" ]
In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies. In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
1,000
[ { "input": "3 1\n2 1 4\n11 3 16", "output": "4" }, { "input": "4 3\n4 3 5 6\n11 12 14 20", "output": "3" }, { "input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "output": "137" }, { "input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779", "output": "150" }, { "input": "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 2 2 3 2 2 2 1 1 1\n997 817 767 860 835 809 817 565 630 804 586 953 977 356 905 890 958 916 740 583 902 945 313 956 871 729 976 707 516 788", "output": "164" }, { "input": "40 538\n1 3 3 1 4 1 1 1 1 5 3 3 4 1 4 2 7 1 4 1 1 2 2 1 1 1 1 4 1 4 2 3 3 3 1 3 4 1 3 5\n975 635 795 835 982 965 639 787 688 796 988 779 839 942 491 696 396 995 718 810 796 879 957 783 844 765 968 783 647 214 995 868 318 453 989 889 504 962 945 925", "output": "104" }, { "input": "50 530\n2 3 3 1 1 1 3 4 4 2 4 2 5 1 3 1 2 6 1 1 2 5 3 2 1 5 1 3 3 2 1 1 1 1 2 1 1 2 2 1 4 2 1 3 1 2 1 1 4 2\n959 972 201 990 675 679 972 268 976 886 488 924 795 959 647 994 969 862 898 646 763 797 978 763 995 641 923 856 829 921 934 883 904 986 728 980 1000 775 716 745 833 832 999 651 571 626 827 456 636 795", "output": "133" }, { "input": "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834 948 941 737 649 923 848 950 907 929 865 227 836 956 796 861 801 746 667 539 807 405 355 501 879 994 890 573 848 597 873 130 985 924 426 999 550 586 924 601 807 994 878 410 817 922 898 982 525 611 685 806 847", "output": "103" }, { "input": "1 1\n1\n1", "output": "2" }, { "input": "70 130\n2 1 2 2 3 3 2 5 2 2 3 3 3 1 1 4 3 5 3 2 1 3 7 1 2 7 5 2 1 6 3 4 1 2 1 1 1 1 3 6 4 2 2 8 2 2 4 1 4 2 1 4 4 3 5 1 1 1 1 1 2 3 1 5 1 3 3 4 2 2\n473 311 758 768 797 572 656 898 991 534 989 702 934 767 777 799 1000 655 806 727 718 948 834 965 832 778 706 861 799 874 745 970 772 967 984 886 835 795 832 837 950 952 475 891 947 952 903 929 689 478 725 945 585 943 771 631 729 887 557 738 824 758 999 786 669 992 918 762 964 941", "output": "119" }, { "input": "80 979\n2 1 1 1 2 1 1 1 3 1 4 4 2 1 1 3 1 1 2 1 4 1 1 2 5 4 8 1 3 6 5 7 2 3 4 1 2 2 6 1 2 2 4 1 1 2 3 2 8 1 1 3 3 4 1 1 2 1 4 4 1 4 3 2 6 5 2 1 4 1 2 3 2 1 3 3 1 2 1 3\n498 976 513 869 917 914 664 656 957 893 981 947 985 693 576 958 987 822 981 718 884 729 295 683 485 998 730 894 731 975 739 854 906 740 987 976 606 689 990 775 522 994 920 893 529 651 989 799 643 215 946 987 297 868 425 810 694 908 736 903 970 751 625 904 955 945 839 777 977 974 905 900 666 680 799 873 565 919 536 686", "output": "128" }, { "input": "1 1000\n1000\n1000", "output": "2" }, { "input": "1 1000\n1\n1000", "output": "2000" }, { "input": "1 1\n4\n6", "output": "1" }, { "input": "1 1\n10\n2", "output": "0" }, { "input": "2 1\n2 2\n1 1", "output": "0" }, { "input": "2 6\n1 3\n6 2", "output": "2" } ]
1,670,255,958
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
124
2,150,400
n,k = map(int,input().split()) lis1 = list(map(int,input().split())) lis2 = list(map(int,input().split())) lis = sorted(list(map(list,zip(lis1,lis2))),key = lambda x:x[1]//x[0]) #print(lis) while(k>0): val = lis[0][0]*((lis[0][1]//lis[0][0])+1) if k>=val-lis[0][1]: k-=val-lis[0][1] else: break lis[0][1]+=val-lis[0][1] #print(lis) i = 1 while(lis[0][1]//lis[0][0]!=lis[i][1]//lis[i][0]): i+=1 lis.insert(i,lis[0]) #print(lis) lis.pop(0) minn = float('inf') for i,j in lis: minn= min(j//i,minn) print(minn)
Title: Magic Powder - 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only. Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients. Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies. Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder. Input Specification: The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has. Output Specification: Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. Demo Input: ['3 1\n2 1 4\n11 3 16\n', '4 3\n4 3 5 6\n11 12 14 20\n'] Demo Output: ['4\n', '3\n'] Note: In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies. In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
```python n,k = map(int,input().split()) lis1 = list(map(int,input().split())) lis2 = list(map(int,input().split())) lis = sorted(list(map(list,zip(lis1,lis2))),key = lambda x:x[1]//x[0]) #print(lis) while(k>0): val = lis[0][0]*((lis[0][1]//lis[0][0])+1) if k>=val-lis[0][1]: k-=val-lis[0][1] else: break lis[0][1]+=val-lis[0][1] #print(lis) i = 1 while(lis[0][1]//lis[0][0]!=lis[i][1]//lis[i][0]): i+=1 lis.insert(i,lis[0]) #print(lis) lis.pop(0) minn = float('inf') for i,j in lis: minn= min(j//i,minn) print(minn) ```
-1
920
A
Water The Garden
PROGRAMMING
1,000
[ "implementation" ]
null
null
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200). Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively. Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=&lt;<=*x**i* holds. It is guaranteed that the sum of *n* over all test cases doesn't exceed 200. Note that in hacks you have to set *t*<==<=1.
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
[ "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n" ]
[ "3\n1\n4\n" ]
The first example consists of 3 tests: 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
0
[ { "input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1", "output": "3\n1\n4" }, { "input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4", "output": "1\n2\n2\n1\n3\n2\n2\n3\n2\n2\n1\n4\n3\n3\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1" }, { "input": "31\n5 1\n5\n5 1\n4\n5 2\n4 5\n5 1\n3\n5 2\n3 5\n5 2\n3 4\n5 3\n3 4 5\n5 1\n2\n5 2\n2 5\n5 2\n2 4\n5 3\n2 4 5\n5 2\n2 3\n5 3\n2 3 5\n5 3\n2 3 4\n5 4\n2 3 4 5\n5 1\n1\n5 2\n1 5\n5 2\n1 4\n5 3\n1 4 5\n5 2\n1 3\n5 3\n1 3 5\n5 3\n1 3 4\n5 4\n1 3 4 5\n5 2\n1 2\n5 3\n1 2 5\n5 3\n1 2 4\n5 4\n1 2 4 5\n5 3\n1 2 3\n5 4\n1 2 3 5\n5 4\n1 2 3 4\n5 5\n1 2 3 4 5", "output": "5\n4\n4\n3\n3\n3\n3\n4\n2\n2\n2\n3\n2\n2\n2\n5\n3\n2\n2\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1" }, { "input": "1\n200 1\n200", "output": "200" }, { "input": "1\n5 1\n5", "output": "5" }, { "input": "1\n177 99\n1 4 7 10 11 13 14 15 16 17 19 21 22 24 25 26 27 28 32 34 35 38 39 40 42 45 46 52 54 55 57 58 59 60 62 64 65 67 70 71 74 77 78 79 80 81 83 84 88 92 93 94 95 100 101 102 104 106 107 108 109 110 112 113 114 115 116 118 122 123 124 125 127 128 129 130 134 135 137 138 139 140 142 146 148 149 154 158 160 161 162 165 166 167 169 171 172 173 176", "output": "4" }, { "input": "1\n69 12\n5 7 10 11 12 18 20 27 28 31 47 67", "output": "11" }, { "input": "1\n74 7\n19 39 40 47 55 57 61", "output": "19" }, { "input": "1\n170 11\n14 18 37 39 80 83 103 112 124 127 131", "output": "40" }, { "input": "1\n200 1\n8", "output": "193" }, { "input": "1\n155 53\n2 3 7 9 10 11 12 20 24 26 28 31 38 39 40 51 53 56 58 63 65 66 69 70 72 74 79 81 83 88 90 92 100 103 104 106 111 113 114 115 116 121 124 126 127 128 133 136 142 143 145 148 150", "output": "6" }, { "input": "1\n161 69\n2 5 8 11 12 13 17 18 23 25 28 29 30 33 34 35 36 38 39 44 45 49 52 53 56 57 58 60 62 70 71 74 76 77 82 83 86 90 94 95 97 104 105 108 109 112 113 118 120 123 126 127 132 135 137 139 140 141 142 143 144 146 147 148 151 152 153 154 161", "output": "5" }, { "input": "1\n8 4\n1 2 3 7", "output": "3" }, { "input": "1\n12 2\n5 12", "output": "5" }, { "input": "1\n13 2\n6 12", "output": "6" }, { "input": "1\n13 2\n8 13", "output": "8" }, { "input": "1\n10 4\n1 2 3 5", "output": "6" }, { "input": "1\n200 2\n50 150", "output": "51" }, { "input": "1\n110 2\n1 110", "output": "55" } ]
1,517,704,362
2,147,483,647
Python 3
OK
TESTS
21
77
5,632,000
import math t = int(input()) for i in range(t): n, k = input().split(" ") n = int(n) k = int(k) arr = input().split(" ") if n == k: print(1, '\n') continue for j in range(len(arr)): arr[j] = int(arr[j]) maxi = 0 for j in range(1, k): if arr[j] - arr[j - 1] - 1 > maxi: maxi = arr[j] - arr[j - 1] - 1 maxi = math.ceil(maxi / 2.0) + 1 if arr[0] > maxi: maxi = arr[0] if n - arr[len(arr) - 1] + 1 > maxi: maxi = n - arr[len(arr) - 1] + 1 print(maxi)
Title: Water The Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer! Input Specification: The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200). Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively. Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=&lt;<=*x**i* holds. It is guaranteed that the sum of *n* over all test cases doesn't exceed 200. Note that in hacks you have to set *t*<==<=1. Output Specification: For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. Demo Input: ['3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n'] Demo Output: ['3\n1\n4\n'] Note: The first example consists of 3 tests: 1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
```python import math t = int(input()) for i in range(t): n, k = input().split(" ") n = int(n) k = int(k) arr = input().split(" ") if n == k: print(1, '\n') continue for j in range(len(arr)): arr[j] = int(arr[j]) maxi = 0 for j in range(1, k): if arr[j] - arr[j - 1] - 1 > maxi: maxi = arr[j] - arr[j - 1] - 1 maxi = math.ceil(maxi / 2.0) + 1 if arr[0] > maxi: maxi = arr[0] if n - arr[len(arr) - 1] + 1 > maxi: maxi = n - arr[len(arr) - 1] + 1 print(maxi) ```
3
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, { "input": "7\n3 2 1 6 5 7 4", "output": "8" }, { "input": "8\n2 8 3 7 6 9 1 5", "output": "4" }, { "input": "9\n10 5 9 3 8 7 1 2 4", "output": "6" }, { "input": "10\n7 2 3 8 9 6 5 4 1 10", "output": "11" }, { "input": "1\n1", "output": "2" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 4 1", "output": "3" }, { "input": "4\n4 2 3 1", "output": "5" }, { "input": "5\n3 1 4 2 5", "output": "6" }, { "input": "6\n1 3 6 7 2 4", "output": "5" }, { "input": "7\n1 5 4 7 2 3 6", "output": "8" }, { "input": "8\n12 1 6 5 2 8 3 4", "output": "7" }, { "input": "9\n3 2 7 5 6 4 1 9 10", "output": "8" }, { "input": "10\n1 7 13 6 5 10 3 8 2 4", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n3000", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3000 1", "output": "2" } ]
1,695,353,405
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
1,740,800
# Read input n = int(input()) arr = list(map(int, input().split())) arr.sort() if arr[0] != 1: print(1) else: f = 0 for i in range(len(arr)-1): if arr[i+1] - arr[i] > 1: f= 1 break if f: print(arr[i]+1) else: print(arr[-1]+1)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. Output Specification: Output the required default value for the next test index. Demo Input: ['3\n1 7 2\n'] Demo Output: ['3\n'] Note: none
```python # Read input n = int(input()) arr = list(map(int, input().split())) arr.sort() if arr[0] != 1: print(1) else: f = 0 for i in range(len(arr)-1): if arr[i+1] - arr[i] > 1: f= 1 break if f: print(arr[i]+1) else: print(arr[-1]+1) ```
3.965758
771
C
Bear and Tree Jumps
PROGRAMMING
2,100
[ "dfs and similar", "dp", "trees" ]
null
null
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of *n* vertices, numbered 1 through *n*. Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most *k*. For a pair of vertices (*s*,<=*t*) we define *f*(*s*,<=*t*) as the minimum number of jumps Limak needs to get from *s* to *t*. Your task is to find the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*.
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=5) — the number of vertices in the tree and the maximum allowed jump distance respectively. The next *n*<=-<=1 lines describe edges in the tree. The *i*-th of those lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*) — the indices on vertices connected with *i*-th edge. It's guaranteed that the given edges form a tree.
Print one integer, denoting the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*.
[ "6 2\n1 2\n1 3\n2 4\n2 5\n4 6\n", "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12\n", "3 5\n2 1\n3 1\n" ]
[ "20\n", "114\n", "3\n" ]
In the first sample, the given tree has 6 vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most 2. For example, from the vertex 5 he can jump to any of vertices: 1, 2 and 4 (well, he can also jump to the vertex 5 itself). There are <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c0295201207e28a36e641d8cf599f45986059e71.png" style="max-width: 100.0%;max-height: 100.0%;"/> pairs of vertices (*s*, *t*) such that *s* &lt; *t*. For 5 of those pairs Limak would need two jumps: (1, 6), (3, 4), (3, 5), (3, 6), (5, 6). For other 10 pairs one jump is enough. So, the answer is 5·2 + 10·1 = 20. In the third sample, Limak can jump between every two vertices directly. There are 3 pairs of vertices (*s* &lt; *t*), so the answer is 3·1 = 3.
1,000
[ { "input": "6 2\n1 2\n1 3\n2 4\n2 5\n4 6", "output": "20" }, { "input": "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12", "output": "114" }, { "input": "3 5\n2 1\n3 1", "output": "3" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "2 5\n2 1", "output": "1" }, { "input": "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2", "output": "346" }, { "input": "4 2\n3 4\n2 4\n3 1", "output": "7" }, { "input": "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n2 12\n9 4\n9 10", "output": "88" } ]
1,689,251,174
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689251171.5054982")# 1689251171.505547
Title: Bear and Tree Jumps Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of *n* vertices, numbered 1 through *n*. Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most *k*. For a pair of vertices (*s*,<=*t*) we define *f*(*s*,<=*t*) as the minimum number of jumps Limak needs to get from *s* to *t*. Your task is to find the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=5) — the number of vertices in the tree and the maximum allowed jump distance respectively. The next *n*<=-<=1 lines describe edges in the tree. The *i*-th of those lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*) — the indices on vertices connected with *i*-th edge. It's guaranteed that the given edges form a tree. Output Specification: Print one integer, denoting the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*. Demo Input: ['6 2\n1 2\n1 3\n2 4\n2 5\n4 6\n', '13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12\n', '3 5\n2 1\n3 1\n'] Demo Output: ['20\n', '114\n', '3\n'] Note: In the first sample, the given tree has 6 vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most 2. For example, from the vertex 5 he can jump to any of vertices: 1, 2 and 4 (well, he can also jump to the vertex 5 itself). There are <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c0295201207e28a36e641d8cf599f45986059e71.png" style="max-width: 100.0%;max-height: 100.0%;"/> pairs of vertices (*s*, *t*) such that *s* &lt; *t*. For 5 of those pairs Limak would need two jumps: (1, 6), (3, 4), (3, 5), (3, 6), (5, 6). For other 10 pairs one jump is enough. So, the answer is 5·2 + 10·1 = 20. In the third sample, Limak can jump between every two vertices directly. There are 3 pairs of vertices (*s* &lt; *t*), so the answer is 3·1 = 3.
```python print("_RANDOM_GUESS_1689251171.5054982")# 1689251171.505547 ```
0
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
1,691,184,473
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
122
0
n = int(input()) a = [int(i) for i in input().split()] if sum(a) > n: sm = 0 for i in range(7): if sm >= n: print(i + 1) break elif sum(a) == n: print(7) else: n_new = n / sum(a) for i in range(7): if sm >= n: print(i + 1) break
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python n = int(input()) a = [int(i) for i in input().split()] if sum(a) > n: sm = 0 for i in range(7): if sm >= n: print(i + 1) break elif sum(a) == n: print(7) else: n_new = n / sum(a) for i in range(7): if sm >= n: print(i + 1) break ```
0
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,633,178,894
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
6,758,400
n,k = map(int,input().split()) if n>k*3 or n<=k: print("YES") else: print("NO")
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python n,k = map(int,input().split()) if n>k*3 or n<=k: print("YES") else: print("NO") ```
0
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same. The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 5 6 11", "output": "TRIANGLE" }, { "input": "1 1 1 1", "output": "TRIANGLE" }, { "input": "10 20 30 40", "output": "TRIANGLE" }, { "input": "45 25 5 15", "output": "IMPOSSIBLE" }, { "input": "20 5 8 13", "output": "TRIANGLE" }, { "input": "10 30 7 20", "output": "SEGMENT" }, { "input": "3 2 3 2", "output": "TRIANGLE" }, { "input": "70 10 100 30", "output": "SEGMENT" }, { "input": "4 8 16 2", "output": "IMPOSSIBLE" }, { "input": "3 3 3 10", "output": "TRIANGLE" }, { "input": "1 5 5 5", "output": "TRIANGLE" }, { "input": "13 25 12 1", "output": "SEGMENT" }, { "input": "10 100 7 3", "output": "SEGMENT" }, { "input": "50 1 50 100", "output": "TRIANGLE" }, { "input": "50 1 100 49", "output": "SEGMENT" }, { "input": "49 51 100 1", "output": "SEGMENT" }, { "input": "5 11 2 25", "output": "IMPOSSIBLE" }, { "input": "91 50 9 40", "output": "IMPOSSIBLE" }, { "input": "27 53 7 97", "output": "IMPOSSIBLE" }, { "input": "51 90 24 8", "output": "IMPOSSIBLE" }, { "input": "3 5 1 1", "output": "IMPOSSIBLE" }, { "input": "13 49 69 15", "output": "IMPOSSIBLE" }, { "input": "16 99 9 35", "output": "IMPOSSIBLE" }, { "input": "27 6 18 53", "output": "IMPOSSIBLE" }, { "input": "57 88 17 8", "output": "IMPOSSIBLE" }, { "input": "95 20 21 43", "output": "IMPOSSIBLE" }, { "input": "6 19 32 61", "output": "IMPOSSIBLE" }, { "input": "100 21 30 65", "output": "IMPOSSIBLE" }, { "input": "85 16 61 9", "output": "IMPOSSIBLE" }, { "input": "5 6 19 82", "output": "IMPOSSIBLE" }, { "input": "1 5 1 3", "output": "IMPOSSIBLE" }, { "input": "65 10 36 17", "output": "IMPOSSIBLE" }, { "input": "81 64 9 7", "output": "IMPOSSIBLE" }, { "input": "11 30 79 43", "output": "IMPOSSIBLE" }, { "input": "1 1 5 3", "output": "IMPOSSIBLE" }, { "input": "21 94 61 31", "output": "IMPOSSIBLE" }, { "input": "49 24 9 74", "output": "IMPOSSIBLE" }, { "input": "11 19 5 77", "output": "IMPOSSIBLE" }, { "input": "52 10 19 71", "output": "SEGMENT" }, { "input": "2 3 7 10", "output": "SEGMENT" }, { "input": "1 2 6 3", "output": "SEGMENT" }, { "input": "2 6 1 8", "output": "SEGMENT" }, { "input": "1 2 4 1", "output": "SEGMENT" }, { "input": "4 10 6 2", "output": "SEGMENT" }, { "input": "2 10 7 3", "output": "SEGMENT" }, { "input": "5 2 3 9", "output": "SEGMENT" }, { "input": "6 1 4 10", "output": "SEGMENT" }, { "input": "10 6 4 1", "output": "SEGMENT" }, { "input": "3 2 9 1", "output": "SEGMENT" }, { "input": "22 80 29 7", "output": "SEGMENT" }, { "input": "2 6 3 9", "output": "SEGMENT" }, { "input": "3 1 2 1", "output": "SEGMENT" }, { "input": "3 4 7 1", "output": "SEGMENT" }, { "input": "8 4 3 1", "output": "SEGMENT" }, { "input": "2 8 3 5", "output": "SEGMENT" }, { "input": "4 1 2 1", "output": "SEGMENT" }, { "input": "8 1 3 2", "output": "SEGMENT" }, { "input": "6 2 1 8", "output": "SEGMENT" }, { "input": "3 3 3 6", "output": "TRIANGLE" }, { "input": "3 6 3 3", "output": "TRIANGLE" }, { "input": "4 10 4 4", "output": "TRIANGLE" }, { "input": "1 1 2 1", "output": "TRIANGLE" }, { "input": "3 3 3 6", "output": "TRIANGLE" }, { "input": "5 4 5 5", "output": "TRIANGLE" }, { "input": "8 7 8 8", "output": "TRIANGLE" }, { "input": "3 3 3 1", "output": "TRIANGLE" }, { "input": "1 1 6 6", "output": "TRIANGLE" }, { "input": "1 9 1 9", "output": "TRIANGLE" }, { "input": "7 2 2 7", "output": "TRIANGLE" }, { "input": "7 2 3 2", "output": "TRIANGLE" }, { "input": "4 4 10 10", "output": "TRIANGLE" }, { "input": "7 7 10 7", "output": "TRIANGLE" }, { "input": "4 4 4 5", "output": "TRIANGLE" }, { "input": "1 10 9 2", "output": "TRIANGLE" }, { "input": "1 8 2 7", "output": "TRIANGLE" }, { "input": "4 3 2 8", "output": "TRIANGLE" }, { "input": "5 9 5 3", "output": "TRIANGLE" }, { "input": "4 10 3 5", "output": "TRIANGLE" } ]
1,685,080,381
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
# LUOGU_RID: 111258892 array = [] j = 0 while j <= 3: a = input() array.append(a) j += 1 array.sort() print(array) if array[1]+array[2] > array[3]: print('TRIANGLE') if array[1]+array[2] == array[3]: print('SEGMENT') else: print('IMPOSSIBLE')
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same. The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. Input Specification: The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. Output Specification: Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. Demo Input: ['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n'] Demo Output: ['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n'] Note: none
```python # LUOGU_RID: 111258892 array = [] j = 0 while j <= 3: a = input() array.append(a) j += 1 array.sort() print(array) if array[1]+array[2] > array[3]: print('TRIANGLE') if array[1]+array[2] == array[3]: print('SEGMENT') else: print('IMPOSSIBLE') ```
-1
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server" }, { "input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;", "output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm" }, { "input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;", "output": "zygoumbmx 185.32.99.2; #ervbfot" }, { "input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;", "output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y" }, { "input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;", "output": "zbtjzzue 203.115.124.110; #tdwmshz" }, { "input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;", "output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t" }, { "input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;", "output": "command 11.1.1.1; #get" }, { "input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;", "output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn" }, { "input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;", "output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica" }, { "input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;", "output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica" }, { "input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;", "output": "block 255.255.255.255; #server" }, { "input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;", "output": "block 22.222.30.10; #alp" } ]
1,550,827,974
2,147,483,647
PyPy 3
OK
TESTS
28
218
2,764,800
n,m=map(int,input().split()) alfa,betta=[],[] for i in range(n): x,y=map(str,input().split()) x="#"+x alfa.append(x) betta.append(y) for j in range(m): x1,y1=map(str,input().split()) for j in range(n): if y1[0:len(y1)-1]==betta[j]: print(x1,y1,alfa[j])
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. Output Specification: Print *m* lines, the commands in the configuration file after Dustin did his task. Demo Input: ['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n'] Demo Output: ['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n'] Note: none
```python n,m=map(int,input().split()) alfa,betta=[],[] for i in range(n): x,y=map(str,input().split()) x="#"+x alfa.append(x) betta.append(y) for j in range(m): x1,y1=map(str,input().split()) for j in range(n): if y1[0:len(y1)-1]==betta[j]: print(x1,y1,alfa[j]) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,580,495,102
2,147,483,647
Python 3
OK
TESTS
32
218
0
# _ = int(input()) # child = [int(a) for a in input().split()] # total=sum(child) # print(total//4+1 if total%4>0 else total//4) # print(' '.join(input().replace("WUB",' ').split())) _=int(input()) x=[int(a) for a in input().split()] odd_odd=False if len(list(filter(lambda x: x%2==0,x)))>len(list(filter(lambda x: x%2!=0,x))): for number in x: if number%2>0: print(x.index(number)+1) break else: for number in x: if number %2==0: print(x.index(number)+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python # _ = int(input()) # child = [int(a) for a in input().split()] # total=sum(child) # print(total//4+1 if total%4>0 else total//4) # print(' '.join(input().replace("WUB",' ').split())) _=int(input()) x=[int(a) for a in input().split()] odd_odd=False if len(list(filter(lambda x: x%2==0,x)))>len(list(filter(lambda x: x%2!=0,x))): for number in x: if number%2>0: print(x.index(number)+1) break else: for number in x: if number %2==0: print(x.index(number)+1) ```
3.9455
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428", "output": "25720377\n661369649" }, { "input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482", "output": "819602309\n796067435" }, { "input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780", "output": "374054998\n902899520" }, { "input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990", "output": "939116221\n323703261" }, { "input": "3\n77 77 77\n77 77\n77", "output": "77\n77" }, { "input": "3\n84 30 9\n9 84\n9", "output": "30\n84" }, { "input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3", "output": "5\n5" }, { "input": "4\n1 5 7 8\n1 5 7\n1 5", "output": "8\n7" } ]
1,626,210,543
2,147,483,647
Python 3
OK
TESTS
33
217
18,739,200
n = int(input()) t1 = 0 for i in range(3): s = str(input()).split() t = 0 for a in s: t += int(a) if i!=0: print(t1 - t) t1 = t
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected? Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. Output Specification: Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. Demo Input: ['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n'] Demo Output: ['8\n123\n', '1\n3\n'] Note: In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
```python n = int(input()) t1 = 0 for i in range(3): s = str(input()).split() t = 0 for a in s: t += int(a) if i!=0: print(t1 - t) t1 = t ```
3
828
B
Black Square
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet. The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
[ "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "1 2\nBB\n", "3 3\nWWW\nWWW\nWWW\n" ]
[ "5\n", "-1\n", "1\n" ]
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
750
[ { "input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5" }, { "input": "1 2\nBB", "output": "-1" }, { "input": "3 3\nWWW\nWWW\nWWW", "output": "1" }, { "input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB", "output": "-1" }, { "input": "1 1\nW", "output": "1" }, { "input": "2 4\nWWWW\nWBWW", "output": "0" }, { "input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW", "output": "0" }, { "input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW", "output": "0" }, { "input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW", "output": "12" }, { "input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW", "output": "11" }, { "input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW", "output": "9" }, { "input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW", "output": "2" }, { "input": "1 1\nW", "output": "1" }, { "input": "1 1\nB", "output": "0" }, { "input": "2 2\nWW\nWW", "output": "1" }, { "input": "2 2\nWW\nWB", "output": "0" }, { "input": "2 2\nWW\nBW", "output": "0" }, { "input": "2 2\nWW\nBB", "output": "2" }, { "input": "2 2\nWB\nWW", "output": "0" }, { "input": "2 2\nWB\nWB", "output": "2" }, { "input": "2 2\nWB\nBW", "output": "2" }, { "input": "2 2\nWB\nBB", "output": "1" }, { "input": "2 2\nBW\nWW", "output": "0" }, { "input": "2 2\nBW\nWB", "output": "2" }, { "input": "2 2\nBW\nBW", "output": "2" }, { "input": "2 2\nBW\nBB", "output": "1" }, { "input": "2 2\nBB\nWW", "output": "2" }, { "input": "2 2\nBB\nWB", "output": "1" }, { "input": "2 2\nBB\nBW", "output": "1" }, { "input": "2 2\nBB\nBB", "output": "0" }, { "input": "1 2\nWW", "output": "1" }, { "input": "1 2\nWB", "output": "0" }, { "input": "1 2\nBW", "output": "0" }, { "input": "2 1\nW\nW", "output": "1" }, { "input": "2 1\nW\nB", "output": "0" }, { "input": "2 1\nB\nW", "output": "0" }, { "input": "2 1\nB\nB", "output": "-1" }, { "input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW", "output": "-1" }, { "input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB", "output": "-1" }, { "input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB", "output": "0" }, { "input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "-1" }, { "input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB", "output": "-1" }, { "input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB", "output": "0" }, { "input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW", "output": "0" }, { "input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW", "output": "0" }, { "input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW", "output": "-1" }, { "input": "1 5\nWBBWW", "output": "-1" }, { "input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB", "output": "-1" }, { "input": "3 3\nWBW\nWBB\nWWW", "output": "1" }, { "input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW", "output": "7" }, { "input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW", "output": "7" }, { "input": "3 3\nBBB\nBBB\nBBB", "output": "0" }, { "input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW", "output": "23" }, { "input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW", "output": "13" }, { "input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW", "output": "12" }, { "input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW", "output": "34" }, { "input": "3 3\nBBW\nWWW\nBWW", "output": "6" }, { "input": "3 3\nBWB\nWWW\nBWW", "output": "6" }, { "input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW", "output": "21" }, { "input": "3 3\nWWW\nWBW\nWWW", "output": "0" }, { "input": "3 3\nBBB\nWWW\nWWW", "output": "6" }, { "input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW", "output": "18" }, { "input": "5 2\nWB\nWB\nWB\nWW\nWW", "output": "-1" }, { "input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW", "output": "-1" }, { "input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW", "output": "6" }, { "input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW", "output": "0" }, { "input": "2 5\nWWWWW\nBBBWW", "output": "-1" }, { "input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW", "output": "33" }, { "input": "3 3\nWBW\nWBW\nWBW", "output": "6" }, { "input": "3 5\nWWBBB\nBWBBB\nWWBBB", "output": "-1" }, { "input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW", "output": "22" }, { "input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW", "output": "22" }, { "input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW", "output": "5" }, { "input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW", "output": "12" }, { "input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB", "output": "-1" }, { "input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW", "output": "6" }, { "input": "5 2\nWW\nBW\nBW\nBB\nWW", "output": "-1" }, { "input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW", "output": "20" }, { "input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW", "output": "14" }, { "input": "1 5\nWWBWW", "output": "0" }, { "input": "1 3\nBBB", "output": "-1" }, { "input": "2 4\nWWBW\nBWBW", "output": "-1" }, { "input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW", "output": "30" }, { "input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW", "output": "1" }, { "input": "3 3\nWWW\nWWW\nWWB", "output": "0" }, { "input": "5 1\nB\nB\nW\nW\nW", "output": "-1" }, { "input": "2 3\nWBW\nWBW", "output": "2" }, { "input": "5 2\nWW\nWB\nWB\nWB\nWW", "output": "-1" }, { "input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW", "output": "23" } ]
1,502,916,661
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
91
62
0
n, m = map(int, input().split()) g = [input() for i in range(n)] b, r1, r2, c1, c2 = 0, n, -1, m, -1 for i in range(n): for j in range(m): if g[i][j] == 'B': b += 1 r1 = min(r1, i) r2 = max(r2, i) c1 = min(c1, j) c2 = max(c2, j) s = max(r2 - r1 + 1, c2 - c1 + 1) if b == 0: print(1) elif r1 > n - s and r2 < s - 1 or c1 > m - s and c2 < s - 1: print(-1) else: print(s ** 2 - b)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet. The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. Output Specification: Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. Demo Input: ['5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n', '1 2\nBB\n', '3 3\nWWW\nWWW\nWWW\n'] Demo Output: ['5\n', '-1\n', '1\n'] Note: In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black.
```python n, m = map(int, input().split()) g = [input() for i in range(n)] b, r1, r2, c1, c2 = 0, n, -1, m, -1 for i in range(n): for j in range(m): if g[i][j] == 'B': b += 1 r1 = min(r1, i) r2 = max(r2, i) c1 = min(c1, j) c2 = max(c2, j) s = max(r2 - r1 + 1, c2 - c1 + 1) if b == 0: print(1) elif r1 > n - s and r2 < s - 1 or c1 > m - s and c2 < s - 1: print(-1) else: print(s ** 2 - b) ```
0
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", "output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000 2000000000\n2000000000 2000000000" }, { "input": "10\n1 10 12 15 59 68 130 912 1239 9123", "output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122" }, { "input": "5\n-2 -1 0 1 2", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "5\n-2 -1 0 1 3", "output": "1 5\n1 4\n1 3\n1 3\n2 5" }, { "input": "3\n-10000 1 10000", "output": "10001 20000\n9999 10001\n9999 20000" }, { "input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "output": "1 4\n1 3\n1 2\n1 3\n1 4" }, { "input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706", "output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010" }, { "input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124", "output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524" }, { "input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292", "output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307" }, { "input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986", "output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14" }, { "input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886", "output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..." }, { "input": "3\n-1000000000 999999999 1000000000", "output": "1999999999 2000000000\n1 1999999999\n1 2000000000" } ]
1,648,202,417
2,147,483,647
Python 3
OK
TESTS
54
514
8,089,600
n = int(input()) a = [int(i) for i in input().split()] for i in range(n): if i == 0: print(abs(a[i] - a[i + 1]) , abs(a[i] - a[n - 1])) elif i == (n - 1): print(abs(a[i] - a[i - 1]) , abs(a[i] - a[0])) else: print(min(abs(a[i] - a[i + 1]) , abs(a[i] - a[i - 1])) , max(abs(a[i] - a[0]) , abs(a[i] - a[n - 1])))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. Output Specification: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Demo Input: ['4\n-5 -2 2 7\n', '2\n-1 1\n'] Demo Output: ['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n'] Note: none
```python n = int(input()) a = [int(i) for i in input().split()] for i in range(n): if i == 0: print(abs(a[i] - a[i + 1]) , abs(a[i] - a[n - 1])) elif i == (n - 1): print(abs(a[i] - a[i - 1]) , abs(a[i] - a[0])) else: print(min(abs(a[i] - a[i + 1]) , abs(a[i] - a[i - 1])) , max(abs(a[i] - a[0]) , abs(a[i] - a[n - 1]))) ```
3
621
B
Wet Shark and Bishops
PROGRAMMING
1,300
[ "combinatorics", "implementation" ]
null
null
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.
The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position.
Output one integer — the number of pairs of bishops which attack each other.
[ "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "3\n1 1\n2 3\n3 5\n" ]
[ "6\n", "0\n" ]
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
1,000
[ { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5", "output": "6" }, { "input": "3\n1 1\n2 3\n3 5", "output": "0" }, { "input": "3\n859 96\n634 248\n808 72", "output": "0" }, { "input": "3\n987 237\n891 429\n358 145", "output": "0" }, { "input": "3\n411 81\n149 907\n611 114", "output": "0" }, { "input": "3\n539 221\n895 89\n673 890", "output": "0" }, { "input": "3\n259 770\n448 54\n926 667", "output": "0" }, { "input": "3\n387 422\n898 532\n988 636", "output": "0" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 42\n788 639\n710 709", "output": "0" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n510 389\n729 950", "output": "0" }, { "input": "10\n518 518\n71 971\n121 862\n967 607\n138 754\n513 337\n499 873\n337 387\n647 917\n76 417", "output": "0" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657", "output": "0" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n284 929\n816 602", "output": "0" }, { "input": "2\n1 1\n1 1000", "output": "0" }, { "input": "2\n1 1\n1000 1", "output": "0" }, { "input": "2\n1 1\n1000 1000", "output": "1" }, { "input": "2\n1000 1\n1 1000", "output": "1" }, { "input": "2\n1000 1\n1000 1000", "output": "0" }, { "input": "2\n1 1000\n1000 1000", "output": "0" }, { "input": "1\n6 3", "output": "0" }, { "input": "1\n1 1", "output": "0" }, { "input": "1\n1 1000", "output": "0" }, { "input": "1\n1000 1", "output": "0" }, { "input": "1\n1000 1000", "output": "0" }, { "input": "2\n1 1\n3 1", "output": "0" }, { "input": "2\n999 1\n1000 2", "output": "1" }, { "input": "5\n1 1000\n2 999\n3 998\n4 997\n5 996", "output": "10" } ]
1,591,381,625
2,147,483,647
PyPy 3
OK
TESTS
68
1,497
9,420,800
sum=[0]*2000;mi=[0]*2000;ans=0 for i in range(int(input())): x,y=map(int,input().split()) sum[x+y-1]+=1 mi[x-y]+=1 for i in range(2000): if sum[i] > 1: ans+=(sum[i]*(sum[i]+1)//2)-sum[i] if mi[i] > 1: ans+=(mi[i]*(mi[i]+1)//2)-mi[i] print(ans)
Title: Wet Shark and Bishops Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. Input Specification: The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position. Output Specification: Output one integer — the number of pairs of bishops which attack each other. Demo Input: ['5\n1 1\n1 5\n3 3\n5 1\n5 5\n', '3\n1 1\n2 3\n3 5\n'] Demo Output: ['6\n', '0\n'] Note: In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
```python sum=[0]*2000;mi=[0]*2000;ans=0 for i in range(int(input())): x,y=map(int,input().split()) sum[x+y-1]+=1 mi[x-y]+=1 for i in range(2000): if sum[i] > 1: ans+=(sum[i]*(sum[i]+1)//2)-sum[i] if mi[i] > 1: ans+=(mi[i]*(mi[i]+1)//2)-mi[i] print(ans) ```
3
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, { "input": "2 7\n1 1", "output": "1" }, { "input": "3 3\n18 1 9", "output": "10" }, { "input": "3 3\n15 17 9", "output": "3" }, { "input": "3 3\n10 9 12", "output": "2" }, { "input": "10 3\n2 1 17 10 5 16 8 4 15 17", "output": "31" }, { "input": "10 3\n6 11 4 12 22 15 23 26 24 26", "output": "13" }, { "input": "10 3\n10 24 13 15 18 14 15 26 33 35", "output": "29" }, { "input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580", "output": "15717" }, { "input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327", "output": "16133" } ]
1,675,678,678
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
0
# LUOGU_RID: 101582314 n,d=map(int,input().split()) a=list(map(int,input().split())) b=0 for i in range(0,n-1): while a[i]>=a[i+1]: a[i+1]+=d b+=1 print(b)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? Input Specification: The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). Output Specification: Output the minimal number of moves needed to make the sequence increasing. Demo Input: ['4 2\n1 3 3 2\n'] Demo Output: ['3\n'] Note: none
```python # LUOGU_RID: 101582314 n,d=map(int,input().split()) a=list(map(int,input().split())) b=0 for i in range(0,n-1): while a[i]>=a[i+1]: a[i+1]+=d b+=1 print(b) ```
0
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo" }, { "input": "805", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1000", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1", "output": "O" }, { "input": "2", "output": "OO" }, { "input": "3", "output": "OOO" }, { "input": "5", "output": "OOOoO" }, { "input": "17", "output": "OOOoOooOooooOoooo" }, { "input": "49", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo" }, { "input": "256", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo" }, { "input": "512", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "933", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "61", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo" }, { "input": "781", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "999", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." } ]
1,548,867,462
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
109
409,600
n=int(input()) A=[] A.append(0) A.append(1) for i in range(2,n+1): A.append(A[i-2]+A[i-1]) for i in range(1,n+1): if i in A: print('O',end="") else: print('o',end="")
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. Input Specification: The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: Print Eleven's new name on the first and only line of output. Demo Input: ['8\n', '15\n'] Demo Output: ['OOOoOooO\n', 'OOOoOooOooooOoo\n'] Note: none
```python n=int(input()) A=[] A.append(0) A.append(1) for i in range(2,n+1): A.append(A[i-2]+A[i-1]) for i in range(1,n+1): if i in A: print('O',end="") else: print('o',end="") ```
0
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*. Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", "output": "1" }, { "input": "10 7\n1101111011", "output": "2" }, { "input": "10 9\n1110000101", "output": "1" }, { "input": "10 9\n1100000001", "output": "1" }, { "input": "20 5\n11111111110111101001", "output": "4" }, { "input": "20 11\n11100000111000011011", "output": "2" }, { "input": "20 19\n10100000000000000001", "output": "1" }, { "input": "50 13\n10011010100010100111010000010000000000010100000101", "output": "5" }, { "input": "50 8\n11010100000011001100001100010001110000101100110011", "output": "8" }, { "input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111", "output": "25" }, { "input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "1" }, { "input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "20" }, { "input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111", "output": "25" }, { "input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111", "output": "25" }, { "input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111", "output": "34" }, { "input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111", "output": "13" }, { "input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111", "output": "15" }, { "input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111", "output": "12" }, { "input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111", "output": "18" }, { "input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001", "output": "16" }, { "input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101", "output": "10" }, { "input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111", "output": "13" }, { "input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001", "output": "18" }, { "input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011", "output": "12" }, { "input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001", "output": "9" }, { "input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101", "output": "12" }, { "input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001", "output": "7" }, { "input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001", "output": "3" }, { "input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001", "output": "3" }, { "input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001", "output": "3" }, { "input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "1" }, { "input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "99" }, { "input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111", "output": "-1" }, { "input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111", "output": "33" }, { "input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111", "output": "-1" }, { "input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111", "output": "17" }, { "input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111", "output": "-1" }, { "input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011", "output": "14" }, { "input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101", "output": "11" }, { "input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001", "output": "-1" }, { "input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111", "output": "-1" }, { "input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101", "output": "13" }, { "input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101", "output": "9" }, { "input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001", "output": "-1" }, { "input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001", "output": "-1" }, { "input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001", "output": "-1" }, { "input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001", "output": "3" }, { "input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "2" }, { "input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "-1" }, { "input": "43 30\n1001000001111111010100100100110101011101101", "output": "2" }, { "input": "7 1\n1111111", "output": "6" }, { "input": "9 3\n101000001", "output": "-1" }, { "input": "10 3\n1100000001", "output": "-1" }, { "input": "8 2\n10000101", "output": "-1" }, { "input": "2 1\n11", "output": "1" } ]
1,696,696,511
2,147,483,647
PyPy 3-64
OK
TESTS
63
62
0
n, d = map(int, input().split()) line = input() zeros_streak = 0 count = 0 for i in line: if i == '0': count += 1 if count > zeros_streak: zeros_streak = count else: count = 0 if zeros_streak >= d: print(-1) else: tps = 0 i = 0 while i < n - 1: if line[i] == '1': i += d tps += 1 else: i -= 1 print(tps)
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*. Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. Input Specification: The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. Output Specification: If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. Demo Input: ['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n'] Demo Output: ['2\n', '-1\n', '3\n', '4\n'] Note: In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
```python n, d = map(int, input().split()) line = input() zeros_streak = 0 count = 0 for i in line: if i == '0': count += 1 if count > zeros_streak: zeros_streak = count else: count = 0 if zeros_streak >= d: print(-1) else: tps = 0 i = 0 while i < n - 1: if line[i] == '1': i += d tps += 1 else: i -= 1 print(tps) ```
3
797
B
Odd sum
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
[ "4\n-2 2 -3 1\n", "3\n2 -5 -3\n" ]
[ "3\n", "-1\n" ]
In the first example sum of the second and the fourth elements is 3.
0
[ { "input": "4\n-2 2 -3 1", "output": "3" }, { "input": "3\n2 -5 -3", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "output": "53507" }, { "input": "2\n-5439 -6705", "output": "-5439" }, { "input": "2\n2850 6843", "output": "9693" }, { "input": "2\n144 9001", "output": "9145" }, { "input": "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "output": "38951" }, { "input": "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "output": "18005" }, { "input": "10\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097", "output": "28605" }, { "input": "10\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504", "output": "8463" }, { "input": "10\n1184 5136 1654 3254 6576 6900 6468 327 179 7114", "output": "38613" }, { "input": "10\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812", "output": "-787" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "5\n5 5 5 3 -1", "output": "17" }, { "input": "5\n-1 -2 5 3 0", "output": "7" }, { "input": "5\n-3 -2 5 -1 3", "output": "7" }, { "input": "3\n-2 2 -1", "output": "1" }, { "input": "5\n5 0 7 -2 3", "output": "15" }, { "input": "2\n-2 -5", "output": "-5" }, { "input": "3\n-1 -3 0", "output": "-1" }, { "input": "5\n2 -1 0 -3 -2", "output": "1" }, { "input": "4\n2 3 0 5", "output": "7" }, { "input": "5\n-5 3 -2 2 5", "output": "7" }, { "input": "59\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244", "output": "129433" }, { "input": "17\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565", "output": "43749" }, { "input": "26\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146", "output": "60757" }, { "input": "51\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313", "output": "73781" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n-2 1", "output": "1" }, { "input": "2\n3 2", "output": "5" }, { "input": "2\n1 2", "output": "3" }, { "input": "2\n-1 1", "output": "1" }, { "input": "2\n0 -1", "output": "-1" }, { "input": "2\n2 1", "output": "3" }, { "input": "2\n3 0", "output": "3" }, { "input": "2\n0 -1", "output": "-1" }, { "input": "3\n-3 1 -1", "output": "1" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n1 3 1", "output": "5" }, { "input": "3\n-1 0 1", "output": "1" }, { "input": "3\n-3 -3 -2", "output": "-3" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n-2 -2 1", "output": "1" }, { "input": "4\n0 -1 -3 -4", "output": "-1" }, { "input": "4\n5 3 2 1", "output": "11" }, { "input": "4\n-1 -2 4 -2", "output": "3" }, { "input": "4\n-1 -3 0 -3", "output": "-1" }, { "input": "4\n1 -4 -3 -4", "output": "1" }, { "input": "4\n5 3 3 4", "output": "15" }, { "input": "4\n-1 -3 -1 2", "output": "1" }, { "input": "4\n3 2 -1 -4", "output": "5" }, { "input": "5\n-5 -4 -3 -5 2", "output": "-1" }, { "input": "5\n5 5 1 2 -2", "output": "13" }, { "input": "5\n-2 -1 -5 -1 4", "output": "3" }, { "input": "5\n-5 -5 -4 4 0", "output": "-1" }, { "input": "5\n2 -3 -1 -4 -5", "output": "1" }, { "input": "5\n4 3 4 2 3", "output": "13" }, { "input": "5\n0 -2 -5 3 3", "output": "3" }, { "input": "5\n4 -2 -2 -3 0", "output": "1" }, { "input": "6\n6 7 -1 1 5 -1", "output": "19" }, { "input": "6\n-1 7 2 -3 -4 -5", "output": "9" }, { "input": "6\n0 -1 -3 -5 2 -6", "output": "1" }, { "input": "6\n4 -1 0 3 6 1", "output": "13" }, { "input": "6\n5 3 3 4 4 -3", "output": "19" }, { "input": "6\n0 -3 5 -4 5 -4", "output": "7" }, { "input": "6\n-5 -3 1 -1 -5 -3", "output": "1" }, { "input": "6\n-2 1 3 -2 7 4", "output": "15" }, { "input": "7\n0 7 6 2 7 0 6", "output": "21" }, { "input": "7\n6 -6 -1 -5 7 1 7", "output": "21" }, { "input": "7\n2 3 -5 0 -4 0 -4", "output": "5" }, { "input": "7\n-6 3 -3 -1 -6 -6 -5", "output": "3" }, { "input": "7\n7 6 3 2 4 2 0", "output": "21" }, { "input": "7\n-2 3 -3 4 4 0 -1", "output": "11" }, { "input": "7\n-5 -7 4 0 5 -3 -5", "output": "9" }, { "input": "7\n-3 -5 -4 1 3 -4 -7", "output": "3" }, { "input": "8\n5 2 4 5 7 -2 7 3", "output": "33" }, { "input": "8\n-8 -3 -1 3 -8 -4 -4 4", "output": "7" }, { "input": "8\n-6 -7 -7 -5 -4 -9 -2 -7", "output": "-5" }, { "input": "8\n8 7 6 8 3 4 8 -2", "output": "41" }, { "input": "8\n6 7 0 -6 6 5 4 7", "output": "35" }, { "input": "8\n0 -7 -5 -5 5 -1 -8 -7", "output": "5" }, { "input": "8\n1 -6 -5 7 -3 -4 2 -2", "output": "9" }, { "input": "8\n1 -8 -6 -6 -6 -7 -5 -1", "output": "1" }, { "input": "9\n-3 -1 4 4 8 -8 -5 9 -2", "output": "25" }, { "input": "9\n-9 -1 3 -2 -7 2 -9 -1 -4", "output": "5" }, { "input": "9\n-6 -9 -3 -8 -5 2 -6 0 -5", "output": "-1" }, { "input": "9\n5 4 3 3 6 7 8 5 9", "output": "47" }, { "input": "9\n5 3 9 1 5 2 -3 7 0", "output": "31" }, { "input": "9\n-3 -9 -1 -7 5 6 -4 -6 -6", "output": "11" }, { "input": "9\n-6 -5 6 -5 -2 0 1 2 -9", "output": "9" }, { "input": "9\n8 3 6 1 -3 5 2 9 1", "output": "35" }, { "input": "10\n-6 -4 -7 -1 -9 -10 -10 1 0 -3", "output": "1" }, { "input": "10\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8", "output": "-3" }, { "input": "10\n8 5 9 2 3 3 -6 1 -1 8", "output": "39" }, { "input": "10\n2 10 -7 6 -1 -1 7 -9 -4 -6", "output": "25" }, { "input": "10\n-10 -2 -2 -1 -10 -7 1 0 -4 -5", "output": "1" }, { "input": "10\n4 3 10 -2 -1 0 10 6 7 0", "output": "39" }, { "input": "10\n-2 6 6 5 0 10 6 7 -1 1", "output": "41" }, { "input": "10\n-10 2 8 -6 -1 -5 1 -10 -10 -1", "output": "11" } ]
1,587,640,533
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
124
409,600
from collections import Counter,defaultdict,deque import heapq as hq from itertools import count, islice #alph = 'abcdefghijklmnopqrstuvwxyz' #from math import factorial as fact import math import sys input=sys.stdin.readline #print=sys.stdout.write #tt = int(input()) #total=0 #n = int(input()) #n,m,k = [int(x) for x in input().split()] #n = int(input()) #l,r = [int(x) for x in input().split()] n = int(input()) arr = [int(x) for x in input().split()] pos = [] neg = [] s = 0 for i in range(n): if arr[i]>0: pos.append(arr[i]) s+=arr[i] else: neg.append(arr[i]) if s%2: print(s) else: pos.sort() neg.sort(reverse=True) lp = len(pos) ln = len(neg) if lp>ln: neg.extend([0]*(lp-ln)) else: pos.extend([0]*(ln-lp)) for i in range(max(ln,lp)): if neg[i]%2: if pos[i]%2: print(s-min(pos[i],-neg[i])) break else: print(s+neg[i]) break elif pos[i]%2: print(s-pos[i]) break
Title: Odd sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum. Output Specification: Print sum of resulting subseqeuence. Demo Input: ['4\n-2 2 -3 1\n', '3\n2 -5 -3\n'] Demo Output: ['3\n', '-1\n'] Note: In the first example sum of the second and the fourth elements is 3.
```python from collections import Counter,defaultdict,deque import heapq as hq from itertools import count, islice #alph = 'abcdefghijklmnopqrstuvwxyz' #from math import factorial as fact import math import sys input=sys.stdin.readline #print=sys.stdout.write #tt = int(input()) #total=0 #n = int(input()) #n,m,k = [int(x) for x in input().split()] #n = int(input()) #l,r = [int(x) for x in input().split()] n = int(input()) arr = [int(x) for x in input().split()] pos = [] neg = [] s = 0 for i in range(n): if arr[i]>0: pos.append(arr[i]) s+=arr[i] else: neg.append(arr[i]) if s%2: print(s) else: pos.sort() neg.sort(reverse=True) lp = len(pos) ln = len(neg) if lp>ln: neg.extend([0]*(lp-ln)) else: pos.extend([0]*(ln-lp)) for i in range(max(ln,lp)): if neg[i]%2: if pos[i]%2: print(s-min(pos[i],-neg[i])) break else: print(s+neg[i]) break elif pos[i]%2: print(s-pos[i]) break ```
0
626
C
Block Towers
PROGRAMMING
1,600
[ "brute force", "greedy", "math", "number theory" ]
null
null
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Print a single integer, denoting the minimum possible height of the tallest tower.
[ "1 3\n", "3 2\n", "5 0\n" ]
[ "9\n", "8\n", "10\n" ]
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
1,000
[ { "input": "1 3", "output": "9" }, { "input": "3 2", "output": "8" }, { "input": "5 0", "output": "10" }, { "input": "4 2", "output": "9" }, { "input": "0 1000000", "output": "3000000" }, { "input": "1000000 1", "output": "2000000" }, { "input": "1083 724", "output": "2710" }, { "input": "1184 868", "output": "3078" }, { "input": "1285 877", "output": "3243" }, { "input": "820189 548173", "output": "2052543" }, { "input": "968867 651952", "output": "2431228" }, { "input": "817544 553980", "output": "2057286" }, { "input": "813242 543613", "output": "2035282" }, { "input": "961920 647392", "output": "2413968" }, { "input": "825496 807050", "output": "2448819" }, { "input": "974174 827926", "output": "2703150" }, { "input": "969872 899794", "output": "2804499" }, { "input": "818549 720669", "output": "2308827" }, { "input": "967227 894524", "output": "2792626" }, { "input": "185253 152723", "output": "506964" }, { "input": "195173 150801", "output": "518961" }, { "input": "129439 98443", "output": "341823" }, { "input": "163706 157895", "output": "482402" }, { "input": "197973 140806", "output": "508168" }, { "input": "1000000 1000000", "output": "3000000" }, { "input": "1000000 999999", "output": "2999998" }, { "input": "999999 1000000", "output": "3000000" }, { "input": "500000 500100", "output": "1500300" }, { "input": "500000 166000", "output": "1000000" }, { "input": "500000 499000", "output": "1498500" }, { "input": "500000 167000", "output": "1000500" }, { "input": "1 1000000", "output": "3000000" }, { "input": "2 999123", "output": "2997369" }, { "input": "10 988723", "output": "2966169" }, { "input": "234 298374", "output": "895122" }, { "input": "2365 981235", "output": "2943705" }, { "input": "12345 981732", "output": "2945196" }, { "input": "108752 129872", "output": "389616" }, { "input": "984327 24352", "output": "1968654" }, { "input": "928375 1253", "output": "1856750" }, { "input": "918273 219", "output": "1836546" }, { "input": "987521 53", "output": "1975042" }, { "input": "123456 1", "output": "246912" }, { "input": "789123 0", "output": "1578246" }, { "input": "143568 628524", "output": "1885572" }, { "input": "175983 870607", "output": "2611821" }, { "input": "6 4", "output": "15" }, { "input": "6 3", "output": "14" }, { "input": "7 3", "output": "15" }, { "input": "5 4", "output": "14" }, { "input": "5 3", "output": "12" }, { "input": "8 5", "output": "20" }, { "input": "1 0", "output": "2" }, { "input": "19170 15725", "output": "52342" }, { "input": "3000 2000", "output": "7500" }, { "input": "7 4", "output": "16" }, { "input": "50 30", "output": "120" }, { "input": "300 200", "output": "750" }, { "input": "9 4", "output": "20" }, { "input": "4 3", "output": "10" }, { "input": "1 1", "output": "3" }, { "input": "8 6", "output": "21" }, { "input": "10 6", "output": "24" }, { "input": "65 56", "output": "182" }, { "input": "13 10", "output": "34" }, { "input": "14 42", "output": "126" }, { "input": "651 420", "output": "1606" }, { "input": "8 9", "output": "27" }, { "input": "15 10", "output": "38" }, { "input": "999999 888888", "output": "2833330" }, { "input": "192056 131545", "output": "485402" }, { "input": "32 16", "output": "72" }, { "input": "18 12", "output": "45" }, { "input": "1000000 666667", "output": "2500000" }, { "input": "0 1", "output": "3" }, { "input": "9 5", "output": "21" }, { "input": "1515 1415", "output": "4395" }, { "input": "300000 200000", "output": "750000" } ]
1,455,831,042
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
a, b = map(int, input().split(' ')) print(max(a*2, b*3))
Title: Block Towers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers. Input Specification: The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. Output Specification: Print a single integer, denoting the minimum possible height of the tallest tower. Demo Input: ['1 3\n', '3 2\n', '5 0\n'] Demo Output: ['9\n', '8\n', '10\n'] Note: In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
```python a, b = map(int, input().split(' ')) print(max(a*2, b*3)) ```
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,668,668,628
2,147,483,647
PyPy 3-64
OK
TESTS
55
62
0
s = input() names = ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita'] count = 0 for n in names: count += s.count(n) print('YES' if count ==1 else '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 s = input() names = ['Danil', 'Olya', 'Slava', 'Ann', 'Nikita'] count = 0 for n in names: count += s.count(n) print('YES' if count ==1 else 'NO') ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,685,465,596
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
2,150,400
k=int(input()) l=int(input()) m=int(input()) n=int(input()) d=int(input()) #d_list=[] #not_in_list=[] #c=0 '''print(d//k + d//l + d//m + d//n - d//(k*l) - d//(k*m) - d//(k*n) - d//(l*m) - d//(l*n) - d//(m*n) + d//(k*l*m) + d//(l*m*n) + d//(m*n*k) + d//(k*l*n) - 2*d//(k*l*m*n))''' '''for i in range(1,d+1): d_list.append(i) for i in range(k,d+1,k): d_list.remove(i) for i in range(l,d+1,l): if i in d_list: d_list.remove(i) for i in range(m,d+1,m): if i in d_list: d_list.remove(i) for i in range(n,d+1,n): if i in d_list: d_list.remove(i) print(d-len(d_list))''' '''for i in range(k,d+1,k): c+=1 not_in_list.append(i) for i in range(l,d+1,l): if i not in not_in_list: not_in_list.append(i) c+=1 for i in range(m,d+1,m): if i not in not_in_list: not_in_list.append(i) c+=1 for i in range(n,d+1,n): if i not in not_in_list: #not_in_list.append(i) c+=1 print(c)''' if k==1 or l==1 or m==1 or n==1: print(d) else: count=d//k+d//l+d//m+d//n for i in range(l,d+1,l): if i%k==0: count-=1 for i in range(m,d+1,m): if i%k==0 or i%l==0: count-=1 for i in range(n,d+1,n): if i%k==0 or i%l==0 or i%m==0: count-=1 print(count)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python k=int(input()) l=int(input()) m=int(input()) n=int(input()) d=int(input()) #d_list=[] #not_in_list=[] #c=0 '''print(d//k + d//l + d//m + d//n - d//(k*l) - d//(k*m) - d//(k*n) - d//(l*m) - d//(l*n) - d//(m*n) + d//(k*l*m) + d//(l*m*n) + d//(m*n*k) + d//(k*l*n) - 2*d//(k*l*m*n))''' '''for i in range(1,d+1): d_list.append(i) for i in range(k,d+1,k): d_list.remove(i) for i in range(l,d+1,l): if i in d_list: d_list.remove(i) for i in range(m,d+1,m): if i in d_list: d_list.remove(i) for i in range(n,d+1,n): if i in d_list: d_list.remove(i) print(d-len(d_list))''' '''for i in range(k,d+1,k): c+=1 not_in_list.append(i) for i in range(l,d+1,l): if i not in not_in_list: not_in_list.append(i) c+=1 for i in range(m,d+1,m): if i not in not_in_list: not_in_list.append(i) c+=1 for i in range(n,d+1,n): if i not in not_in_list: #not_in_list.append(i) c+=1 print(c)''' if k==1 or l==1 or m==1 or n==1: print(d) else: count=d//k+d//l+d//m+d//n for i in range(l,d+1,l): if i%k==0: count-=1 for i in range(m,d+1,m): if i%k==0 or i%l==0: count-=1 for i in range(n,d+1,n): if i%k==0 or i%l==0 or i%m==0: count-=1 print(count) ```
3
0
none
none
none
0
[ "none" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns.
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
0
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "-1" }, { "input": "2 1\n1 2", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "20 0", "output": "-1" }, { "input": "381 0", "output": "-1" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "-1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 3", "output": "2" }, { "input": "3 2\n2 3\n3 1", "output": "-1" }, { "input": "4 1\n1 4", "output": "2" }, { "input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "output": "2" }, { "input": "20 1\n20 1", "output": "2" }, { "input": "21 1\n21 1", "output": "2" }, { "input": "100 1\n100 1", "output": "2" }, { "input": "400 1\n1 400", "output": "2" }, { "input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2", "output": "2" } ]
1,448,388,070
5,170
PyPy 3
OK
TESTS
59
763
6,144,000
n,m = map(int, input().split()) x = [0] * n for i in range(n): x[i] = [0] * n for i in range(m): a,b = map(int, input().split()) x[a-1][b-1] = 1 x[b-1][a-1] = 1 visited = set() visited |= set([0]) stack = [] stack.append((0,0)) while stack != []: cur = stack.pop(0) #print( "%d %d" % cur) t = 0 for i in range(n): if i not in visited: if x[cur[0]][i] == 1: stack.append(( i,cur[1]+1)) visited |= set ( [ i ] ) #print( "add %d" % i) t += 1 if (n-1) in visited: break first = -1 for i in range(len(stack)): if ( stack[i][0] == (n-1) ): first = stack[i][1] #print(first) visited = set() visited |= set([0]) stack = [] stack.append((0,0)) while stack != []: cur = stack.pop(0) #print( "%d %d" % cur) t = 0 for i in range(n): if i not in visited: if x[cur[0]][i] == 0: stack.append(( i,cur[1]+1)) visited |= set ( [ i ] ) #print( "add %d" % i) t += 1 if (n-1) in visited: break second = -1 for i in range(len(stack)): if ( stack[i][0] == (n-1) ): second = stack[i][1] #print(second) if ( first == -1 or second == -1 ): print("-1") else: print ( max ( first, second) )
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns. Output Specification: Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. Demo Input: ['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n'] Demo Output: ['2\n', '-1\n', '3\n'] Note: In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
```python n,m = map(int, input().split()) x = [0] * n for i in range(n): x[i] = [0] * n for i in range(m): a,b = map(int, input().split()) x[a-1][b-1] = 1 x[b-1][a-1] = 1 visited = set() visited |= set([0]) stack = [] stack.append((0,0)) while stack != []: cur = stack.pop(0) #print( "%d %d" % cur) t = 0 for i in range(n): if i not in visited: if x[cur[0]][i] == 1: stack.append(( i,cur[1]+1)) visited |= set ( [ i ] ) #print( "add %d" % i) t += 1 if (n-1) in visited: break first = -1 for i in range(len(stack)): if ( stack[i][0] == (n-1) ): first = stack[i][1] #print(first) visited = set() visited |= set([0]) stack = [] stack.append((0,0)) while stack != []: cur = stack.pop(0) #print( "%d %d" % cur) t = 0 for i in range(n): if i not in visited: if x[cur[0]][i] == 0: stack.append(( i,cur[1]+1)) visited |= set ( [ i ] ) #print( "add %d" % i) t += 1 if (n-1) in visited: break second = -1 for i in range(len(stack)): if ( stack[i][0] == (n-1) ): second = stack[i][1] #print(second) if ( first == -1 or second == -1 ): print("-1") else: print ( max ( first, second) ) ```
3
903
C
Boxes Packing
PROGRAMMING
1,200
[ "greedy" ]
null
null
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Print the minimum possible number of visible boxes.
[ "3\n1 2 3\n", "4\n4 2 4 3\n" ]
[ "1\n", "2\n" ]
In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
0
[ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n4 2 4 3", "output": "2" }, { "input": "10\n58 58 58 58 58 58 58 58 58 58", "output": "10" }, { "input": "10\n86 89 89 86 86 89 86 86 89 89", "output": "5" }, { "input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360", "output": "14" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "1" }, { "input": "1\n5", "output": "1" }, { "input": "1\n2", "output": "1" }, { "input": "1\n131", "output": "1" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "8" }, { "input": "5\n1 1 1 1 1", "output": "5" } ]
1,571,297,476
2,147,483,647
Python 3
OK
TESTS
24
124
512,000
n=int(input()) lst=list(map(int,input().split())) d={} for i,x in enumerate(lst): if d.get(x)==None:d[x]=0 d[x]+=1 print(max(d.values()))
Title: Boxes Packing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. Output Specification: Print the minimum possible number of visible boxes. Demo Input: ['3\n1 2 3\n', '4\n4 2 4 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
```python n=int(input()) lst=list(map(int,input().split())) d={} for i,x in enumerate(lst): if d.get(x)==None:d[x]=0 d[x]+=1 print(max(d.values())) ```
3
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,530,812,882
4,382
Python 3
RUNTIME_ERROR
PRETESTS
0
78
0
import numpy n = [int(s) for s in input().split(" ")] numbers = [int(s) for s in input().split(" ")] # lol = np.z[[-1,-1]]*10001 lol = numpy.full((10001,2),-1) for i in range(0,len(numbers)): if lol[numbers[i]][0]>-1: continue else: lol[numbers[i]][0]=i for i in range(len(numbers)-1,0,-1): if lol[numbers[i]][1]>-1: continue else: lol[numbers[i]][1]=i print(lol)
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. Input Specification: The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. Output Specification: Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. Demo Input: ['5\n1 5 4 1 3\n', '7\n1 2 1 1 1 3 2\n'] Demo Output: ['9\n', '7\n'] Note: In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
```python import numpy n = [int(s) for s in input().split(" ")] numbers = [int(s) for s in input().split(" ")] # lol = np.z[[-1,-1]]*10001 lol = numpy.full((10001,2),-1) for i in range(0,len(numbers)): if lol[numbers[i]][0]>-1: continue else: lol[numbers[i]][0]=i for i in range(len(numbers)-1,0,-1): if lol[numbers[i]][1]>-1: continue else: lol[numbers[i]][1]=i print(lol) ```
-1
134
A
Average Numbers
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers.
Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.
[ "5\n1 2 3 4 5\n", "4\n50 50 50 50\n" ]
[ "1\n3 ", "4\n1 2 3 4 " ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "1\n3 " }, { "input": "4\n50 50 50 50", "output": "4\n1 2 3 4 " }, { "input": "3\n2 3 1", "output": "1\n1 " }, { "input": "2\n4 2", "output": "0" }, { "input": "2\n1 1", "output": "2\n1 2 " }, { "input": "10\n3 3 3 3 3 4 3 3 3 2", "output": "8\n1 2 3 4 5 7 8 9 " }, { "input": "10\n15 7 10 7 7 7 4 4 7 2", "output": "5\n2 4 5 6 9 " }, { "input": "6\n2 2 2 2 2 2", "output": "6\n1 2 3 4 5 6 " }, { "input": "6\n3 3 3 3 3 3", "output": "6\n1 2 3 4 5 6 " }, { "input": "4\n6 6 6 7", "output": "0" }, { "input": "2\n1 2", "output": "0" }, { "input": "3\n3 3 4", "output": "0" }, { "input": "5\n7 6 6 6 6", "output": "0" }, { "input": "4\n3 5 5 9", "output": "0" }, { "input": "3\n99 100 99", "output": "0" }, { "input": "4\n5 6 5 5", "output": "0" }, { "input": "6\n1 1 2 1 1 1", "output": "0" }, { "input": "2\n4 5", "output": "0" }, { "input": "4\n1 1 1 2", "output": "0" }, { "input": "3\n1 2 4", "output": "0" }, { "input": "6\n1 1 2 3 3 3", "output": "0" }, { "input": "4\n4 5 5 4", "output": "0" }, { "input": "3\n2 3 5", "output": "0" }, { "input": "3\n2 1 1", "output": "0" }, { "input": "3\n1 1 2", "output": "0" }, { "input": "4\n1 2 3 4", "output": "0" }, { "input": "5\n1 2 3 4 6", "output": "0" }, { "input": "3\n2 2 3", "output": "0" }, { "input": "4\n3 4 5 1", "output": "0" }, { "input": "3\n2 3 2", "output": "0" }, { "input": "3\n3 4 4", "output": "0" }, { "input": "3\n10 5 7", "output": "0" }, { "input": "3\n5 6 5", "output": "0" }, { "input": "4\n1 2 3 7", "output": "0" }, { "input": "5\n2 2 3 3 3", "output": "0" }, { "input": "3\n4 3 6", "output": "0" }, { "input": "3\n1 1 3", "output": "0" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 " } ]
1,656,681,090
2,147,483,647
PyPy 3-64
OK
TESTS
58
186
20,275,200
from math import gcd,lcm,sqrt,factorial def solve(): s=sum(a) AVG=s//n if s%n:print(0);return li,ans=[],0 for i in range(n): if AVG==a[i]: li.append(i+1) ans+=1 print(ans) print(*li) if __name__ == '__main__': n=int(input()) a=[int(x) for x in input().split()] solve()
Title: Average Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). Input Specification: The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers. Output Specification: Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line. Demo Input: ['5\n1 2 3 4 5\n', '4\n50 50 50 50\n'] Demo Output: ['1\n3 ', '4\n1 2 3 4 '] Note: none
```python from math import gcd,lcm,sqrt,factorial def solve(): s=sum(a) AVG=s//n if s%n:print(0);return li,ans=[],0 for i in range(n): if AVG==a[i]: li.append(i+1) ans+=1 print(ans) print(*li) if __name__ == '__main__': n=int(input()) a=[int(x) for x in input().split()] solve() ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,488,529,526
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,608,000
Str=input() check=False if 'h' in Str : Str=Str[Str.index('h')+1:] if 'e' in Str : Str=Str[Str.index('e')+1:] if 'l' in Str : Str=Str[Str.index('l')+1:] if 'l' in Str : Str = Str[Str.index('l') + 1:] if 'o' in Str : check=True print('YES' if check else '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 Str=input() check=False if 'h' in Str : Str=Str[Str.index('h')+1:] if 'e' in Str : Str=Str[Str.index('e')+1:] if 'l' in Str : Str=Str[Str.index('l')+1:] if 'l' in Str : Str = Str[Str.index('l') + 1:] if 'o' in Str : check=True print('YES' if check else 'No') ```
0
846
A
Curriculum Vitae
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one.
Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
[ "4\n1 1 0 1\n", "6\n0 1 0 0 1 0\n", "1\n0\n" ]
[ "3\n", "4\n", "1\n" ]
none
0
[ { "input": "4\n1 1 0 1", "output": "3" }, { "input": "6\n0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "1" }, { "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": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "80" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1", "output": "53" }, { "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": "3\n1 0 0", "output": "2" }, { "input": "10\n1 1 0 0 0 1 1 0 0 0", "output": "6" }, { "input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0", "output": "52" }, { "input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0", "output": "42" }, { "input": "4\n1 0 0 1", "output": "3" }, { "input": "2\n0 1", "output": "2" }, { "input": "5\n0 1 0 0 1", "output": "4" }, { "input": "3\n1 0 1", "output": "2" }, { "input": "3\n1 1 0", "output": "2" }, { "input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1", "output": "9" } ]
1,511,672,993
593
Python 3
WRONG_ANSWER
TESTS
1
46
5,529,600
n = int(input()) g = list(map(int, input().split())) ans = [g[0]] for i in range(1, len(g)): if ans[-1] == 1 and g[i] == 0: do = 'nothing' else: ans.append(g[i]) # print(ans) # print(i) print(len(ans))
Title: Curriculum Vitae Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. Output Specification: Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. Demo Input: ['4\n1 1 0 1\n', '6\n0 1 0 0 1 0\n', '1\n0\n'] Demo Output: ['3\n', '4\n', '1\n'] Note: none
```python n = int(input()) g = list(map(int, input().split())) ans = [g[0]] for i in range(1, len(g)): if ans[-1] == 1 and g[i] == 0: do = 'nothing' else: ans.append(g[i]) # print(ans) # print(i) print(len(ans)) ```
0
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding.
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Print one integer number — the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16", "output": "50" }, { "input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75", "output": "7" }, { "input": "8 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "3 8\n4 3 2", "output": "2" }, { "input": "3 8\n2 4 2", "output": "2" }, { "input": "3 6\n1 3 2", "output": "2" }, { "input": "3 6\n3 2 5", "output": "2" }, { "input": "3 8\n4 2 1", "output": "2" }, { "input": "5 6\n2 3 5 1 2", "output": "2" }, { "input": "2 6\n5 3", "output": "2" }, { "input": "4 12\n6 4 3 1", "output": "2" }, { "input": "3 18\n1 9 6", "output": "2" }, { "input": "3 9\n3 2 1", "output": "3" }, { "input": "3 6\n5 3 2", "output": "2" }, { "input": "2 10\n5 2", "output": "2" }, { "input": "2 18\n6 3", "output": "3" }, { "input": "4 12\n1 2 12 3", "output": "1" }, { "input": "3 7\n3 2 1", "output": "7" }, { "input": "3 6\n3 2 1", "output": "2" }, { "input": "5 10\n5 4 3 2 1", "output": "2" }, { "input": "5 16\n8 4 2 1 7", "output": "2" }, { "input": "6 7\n6 5 4 3 7 1", "output": "1" }, { "input": "2 6\n3 2", "output": "2" }, { "input": "2 4\n4 1", "output": "1" }, { "input": "6 8\n2 4 1 3 5 7", "output": "2" }, { "input": "6 8\n6 5 4 3 2 1", "output": "2" }, { "input": "6 15\n5 2 3 6 4 3", "output": "3" }, { "input": "4 8\n2 4 8 1", "output": "1" }, { "input": "2 5\n5 1", "output": "1" }, { "input": "4 18\n3 1 1 2", "output": "6" }, { "input": "2 1\n2 1", "output": "1" }, { "input": "3 10\n2 10 5", "output": "1" }, { "input": "5 12\n12 4 4 4 3", "output": "1" }, { "input": "3 6\n6 3 2", "output": "1" }, { "input": "2 2\n2 1", "output": "1" }, { "input": "3 18\n1 9 3", "output": "2" }, { "input": "3 8\n7 2 4", "output": "2" }, { "input": "2 100\n99 1", "output": "100" }, { "input": "4 12\n1 3 4 2", "output": "3" }, { "input": "3 6\n2 3 1", "output": "2" }, { "input": "4 6\n3 2 5 12", "output": "2" }, { "input": "4 97\n97 1 50 10", "output": "1" }, { "input": "3 12\n1 12 2", "output": "1" }, { "input": "4 12\n1 4 3 2", "output": "3" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 19\n7 1 1", "output": "19" }, { "input": "5 12\n12 4 3 4 4", "output": "1" }, { "input": "3 8\n8 4 2", "output": "1" }, { "input": "3 3\n3 2 1", "output": "1" }, { "input": "5 6\n3 2 4 2 2", "output": "2" }, { "input": "2 16\n8 4", "output": "2" }, { "input": "3 6\n10 2 3", "output": "2" }, { "input": "5 3\n2 4 5 3 6", "output": "1" }, { "input": "11 99\n1 2 3 6 5 4 7 8 99 33 66", "output": "1" }, { "input": "3 12\n3 12 2", "output": "1" }, { "input": "5 25\n24 5 15 25 23", "output": "1" }, { "input": "2 4\n8 1", "output": "4" }, { "input": "4 100\n2 50 4 1", "output": "2" }, { "input": "3 28\n7 14 1", "output": "2" }, { "input": "4 8\n2 8 4 1", "output": "1" }, { "input": "4 6\n6 1 2 3", "output": "1" }, { "input": "2 12\n4 3", "output": "3" }, { "input": "4 12\n1 2 4 3", "output": "3" }, { "input": "5 12\n2 3 12 6 4", "output": "1" }, { "input": "4 4\n1 2 2 4", "output": "1" }, { "input": "3 6\n2 3 2", "output": "2" }, { "input": "4 21\n21 20 21 2", "output": "1" }, { "input": "3 8\n3 4 2", "output": "2" }, { "input": "1 25\n25", "output": "1" }, { "input": "99 12\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", "output": "1" }, { "input": "98 12\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", "output": "1" }, { "input": "79 12\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", "output": "1" }, { "input": "4 32\n1 1 1 1", "output": "32" }, { "input": "1 100\n1", "output": "100" }, { "input": "2 100\n7 1", "output": "100" }, { "input": "7 24\n1 3 6 4 5 2 7", "output": "4" }, { "input": "6 87\n1 2 8 4 5 7", "output": "87" }, { "input": "1 88\n1", "output": "88" }, { "input": "1 89\n1", "output": "89" } ]
1,622,625,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
temp = [int(x) for x in input().split()] n = temp[0] k = temp[1] a = [int(x) for x in input().split()] for i in range(n-1, -1, -1): if k % a[i] == 0: print(i+1) break
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input Specification: The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Specification: Print one integer number — the minimum number of hours required to water the garden. Demo Input: ['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n'] Demo Output: ['2\n', '7\n'] Note: In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
```python temp = [int(x) for x in input().split()] n = temp[0] k = temp[1] a = [int(x) for x in input().split()] for i in range(n-1, -1, -1): if k % a[i] == 0: print(i+1) break ```
0
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 1000000000", "output": "0" }, { "input": "100000 1000000000", "output": "16" }, { "input": "100000 362880", "output": "154" }, { "input": "1 4", "output": "0" }, { "input": "9 12", "output": "4" }, { "input": "10 123", "output": "0" }, { "input": "9551 975275379", "output": "0" }, { "input": "17286 948615687", "output": "0" }, { "input": "58942 936593001", "output": "0" }, { "input": "50000 989460910", "output": "4" }, { "input": "22741 989460910", "output": "0" }, { "input": "22740 989460910", "output": "0" }, { "input": "100000 989460910", "output": "4" }, { "input": "100000 98280", "output": "128" }, { "input": "100000 997920", "output": "222" }, { "input": "100000 720720", "output": "226" }, { "input": "100000 2162160", "output": "282" }, { "input": "100000 4324320", "output": "320" }, { "input": "100000 8648640", "output": "348" }, { "input": "100000 183783600", "output": "438" }, { "input": "100000 551350800", "output": "392" }, { "input": "40000 551350800", "output": "150" }, { "input": "20000 400000000", "output": "1" }, { "input": "19999 400000000", "output": "0" }, { "input": "19999 399960001", "output": "1" }, { "input": "31621 999887641", "output": "1" }, { "input": "31622 999887641", "output": "1" }, { "input": "31620 999887641", "output": "0" }, { "input": "100000 999887641", "output": "3" }, { "input": "100000 25", "output": "3" }, { "input": "100000 1", "output": "1" }, { "input": "100000 3628800", "output": "220" }, { "input": "100000 39916800", "output": "328" }, { "input": "100000 479001600", "output": "254" }, { "input": "4 9", "output": "1" }, { "input": "2 6", "output": "0" }, { "input": "20 100", "output": "3" }, { "input": "10 3", "output": "2" }, { "input": "4 4", "output": "3" }, { "input": "2 4", "output": "1" }, { "input": "89874 1", "output": "1" } ]
1,662,112,932
2,147,483,647
PyPy 3-64
OK
TESTS
47
62
1,843,200
n,x=map(int,input().split()) dem=0 if x==1: print("1") exit() for i in range(1,n+1): if x%i==0 and int(x/i)<=n : dem=dem+1 print(dem)
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. Input Specification: The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. Output Specification: Print a single number: the number of times *x* occurs in the table. Demo Input: ['10 5\n', '6 12\n', '5 13\n'] Demo Output: ['2\n', '4\n', '0\n'] Note: A table for the second sample test is given below. The occurrences of number 12 are marked bold.
```python n,x=map(int,input().split()) dem=0 if x==1: print("1") exit() for i in range(1,n+1): if x%i==0 and int(x/i)<=n : dem=dem+1 print(dem) ```
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input": "18 8", "output": "888888888888888888" }, { "input": "1 5", "output": "5" }, { "input": "1 10", "output": "-1" }, { "input": "100 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "10 2", "output": "2222222222" }, { "input": "18 10", "output": "111111111111111110" }, { "input": "1 9", "output": "9" }, { "input": "7 6", "output": "6666666" }, { "input": "4 4", "output": "4444" }, { "input": "14 7", "output": "77777777777777" }, { "input": "3 8", "output": "888" }, { "input": "1 3", "output": "3" }, { "input": "2 8", "output": "88" }, { "input": "3 8", "output": "888" }, { "input": "4 3", "output": "3333" }, { "input": "5 9", "output": "99999" }, { "input": "4 8", "output": "8888" }, { "input": "3 4", "output": "444" }, { "input": "9 4", "output": "444444444" }, { "input": "8 10", "output": "11111110" }, { "input": "1 6", "output": "6" }, { "input": "20 3", "output": "33333333333333333333" }, { "input": "15 10", "output": "111111111111110" }, { "input": "31 4", "output": "4444444444444444444444444444444" }, { "input": "18 9", "output": "999999999999999999" }, { "input": "72 4", "output": "444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "76 8", "output": "8888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "12 5", "output": "555555555555" }, { "input": "54 5", "output": "555555555555555555555555555555555555555555555555555555" }, { "input": "96 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "15 9", "output": "999999999999999" }, { "input": "100 2", "output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "99 3", "output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "98 4", "output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "97 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "100 6", "output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "98 8", "output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "97 9", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "3 10", "output": "110" }, { "input": "2 4", "output": "44" }, { "input": "2 10", "output": "10" }, { "input": "10 10", "output": "1111111110" }, { "input": "4 10", "output": "1110" }, { "input": "25 10", "output": "1111111111111111111111110" }, { "input": "50 10", "output": "11111111111111111111111111111111111111111111111110" }, { "input": "5 10", "output": "11110" }, { "input": "99 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 2", "output": "2" }, { "input": "20 10", "output": "11111111111111111110" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "89 5", "output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "6 10", "output": "111110" }, { "input": "3 8", "output": "888" }, { "input": "1 9", "output": "9" }, { "input": "1 4", "output": "4" }, { "input": "100 7", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" } ]
1,665,848,600
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
46
0
n, t = [int(_) for _ in input().split()] if len(str(t)) > len(str(n)): print(-1) exit(0) while len(str(t)) != n: t *= 10 print(t)
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. Input Specification: The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. Output Specification: Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. Demo Input: ['3 2\n'] Demo Output: ['712'] Note: none
```python n, t = [int(_) for _ in input().split()] if len(str(t)) > len(str(n)): print(-1) exit(0) while len(str(t)) != n: t *= 10 print(t) ```
0
817
D
Imbalanced Array
PROGRAMMING
1,900
[ "data structures", "divide and conquer", "dsu", "sortings" ]
null
null
You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array. For example, the imbalance value of array [1,<=4,<=1] is 9, because there are 6 different subsegments of this array: - [1] (from index 1 to index 1), imbalance value is 0; - [1,<=4] (from index 1 to index 2), imbalance value is 3; - [1,<=4,<=1] (from index 1 to index 3), imbalance value is 3; - [4] (from index 2 to index 2), imbalance value is 0; - [4,<=1] (from index 2 to index 3), imbalance value is 3; - [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array *a*.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*. The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array.
Print one integer — the imbalance value of *a*.
[ "3\n1 4 1\n" ]
[ "9\n" ]
none
0
[ { "input": "3\n1 4 1", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10\n1 4 4 3 5 2 4 2 4 5", "output": "123" }, { "input": "10\n9 6 8 5 5 2 8 9 2 2", "output": "245" }, { "input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5 2 3 5 4 5 4 4 3 5 2", "output": "1480" }, { "input": "30\n2 2 9 1 10 8 3 3 1 4 6 10 2 2 1 4 1 1 1 1 1 2 4 7 6 7 5 10 8 9", "output": "3147" }, { "input": "30\n6 19 12 6 25 24 12 2 24 14 10 10 24 19 11 29 10 22 7 1 9 1 2 27 7 24 20 25 20 28", "output": "10203" }, { "input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14", "output": "426927" } ]
1,497,544,869
5,769
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
614,400
n=int(input()) a=[int(i) for i in input().split()] s=0 for i in range(n): ma=a[i] mi=a[i] for j in range(i,n): if a[j]>ma: ma=a[j] elif a[j]<mi: mi=a[j] s+=ma-mi print(s)
Title: Imbalanced Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array. For example, the imbalance value of array [1,<=4,<=1] is 9, because there are 6 different subsegments of this array: - [1] (from index 1 to index 1), imbalance value is 0; - [1,<=4] (from index 1 to index 2), imbalance value is 3; - [1,<=4,<=1] (from index 1 to index 3), imbalance value is 3; - [4] (from index 2 to index 2), imbalance value is 0; - [4,<=1] (from index 2 to index 3), imbalance value is 3; - [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array *a*. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*. The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. Output Specification: Print one integer — the imbalance value of *a*. Demo Input: ['3\n1 4 1\n'] Demo Output: ['9\n'] Note: none
```python n=int(input()) a=[int(i) for i in input().split()] s=0 for i in range(n): ma=a[i] mi=a[i] for j in range(i,n): if a[j]>ma: ma=a[j] elif a[j]<mi: mi=a[j] s+=ma-mi print(s) ```
0
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron", "output": "256" }, { "input": "1\nTetrahedron", "output": "4" }, { "input": "1\nCube", "output": "6" }, { "input": "1\nOctahedron", "output": "8" }, { "input": "1\nDodecahedron", "output": "12" }, { "input": "1\nIcosahedron", "output": "20" }, { "input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron", "output": "340" } ]
1,675,329,636
2,147,483,647
PyPy 3-64
OK
TESTS
30
1,169
12,185,600
import sys from math import ceil,floor,sqrt,log,dist from collections import defaultdict from operator import itemgetter rmi=lambda:map(int,input().split()) rs=lambda:input() ri=lambda:int(rs()) inf=float('inf') def f(): b=[] for _ in range(ri()): s=input() if s=="Tetrahedron": b.append(4) elif s=="Cube": b.append(6) elif s=="Octahedron": b.append(8) elif s=="Dodecahedron": b.append(12) else: b.append(20) print(sum(b)) f()
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. Output Specification: Output one number — the total number of faces in all the polyhedrons in Anton's collection. Demo Input: ['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n'] Demo Output: ['42\n', '28\n'] Note: In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
```python import sys from math import ceil,floor,sqrt,log,dist from collections import defaultdict from operator import itemgetter rmi=lambda:map(int,input().split()) rs=lambda:input() ri=lambda:int(rs()) inf=float('inf') def f(): b=[] for _ in range(ri()): s=input() if s=="Tetrahedron": b.append(4) elif s=="Cube": b.append(6) elif s=="Octahedron": b.append(8) elif s=="Dodecahedron": b.append(12) else: b.append(20) print(sum(b)) f() ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, { "input": "1022 584 112", "output": "380" }, { "input": "66 174 319", "output": "184" }, { "input": "912 276 1748", "output": "444" }, { "input": "65 156 60", "output": "120" }, { "input": "1 10000 10000", "output": "40008" }, { "input": "1485 55 27", "output": "332" }, { "input": "152 108 4104", "output": "528" }, { "input": "1656 6900 1350", "output": "740" }, { "input": "12 14 42", "output": "60" }, { "input": "615 18 1230", "output": "856" }, { "input": "680 60 408", "output": "336" }, { "input": "644 966 6", "output": "1308" }, { "input": "1 432 432", "output": "1736" }, { "input": "2239 2239 1", "output": "8964" }, { "input": "4106 8212 2", "output": "16436" }, { "input": "10000 10000 10000", "output": "1200" }, { "input": "3623 3623 1", "output": "14500" }, { "input": "9801 9801 9801", "output": "1188" }, { "input": "10000 1 10000", "output": "40008" }, { "input": "9 9 9", "output": "36" }, { "input": "9801 9702 9702", "output": "1184" } ]
1,587,761,643
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
186
0
import math a,b,c=sorted([*map(int,input().split())]) if b!=c: l=math.gcd(b,c) w=b/l h=a/w else: l=math.gcd(a,b) w=a/l h=c/l print(int(4*(l+w+h)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input Specification: The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. Output Specification: Print a single number — the sum of all edges of the parallelepiped. Demo Input: ['1 1 1\n', '4 6 6\n'] Demo Output: ['12\n', '28\n'] Note: In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
```python import math a,b,c=sorted([*map(int,input().split())]) if b!=c: l=math.gcd(b,c) w=b/l h=a/w else: l=math.gcd(a,b) w=a/l h=c/l print(int(4*(l+w+h))) ```
0
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,592,401,799
299
PyPy 3
OK
TESTS
37
156
0
import collections n = int(input()) a = list(map(int, input().split())) C = collections.Counter(a).most_common() print(C[0][1])
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 import collections n = int(input()) a = list(map(int, input().split())) C = collections.Counter(a).most_common() print(C[0][1]) ```
3
474
B
Worms
PROGRAMMING
1,200
[ "binary search", "implementation" ]
null
null
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
[ "5\n2 7 3 4 9\n3\n1 25 11\n" ]
[ "1\n5\n3\n" ]
For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
1,000
[ { "input": "5\n2 7 3 4 9\n3\n1 25 11", "output": "1\n5\n3" } ]
1,695,398,497
2,147,483,647
Python 3
OK
TESTS
38
499
115,097,600
n=int(input())#numero de montones a=[int(x) for x in input().split(' ')]#cantidad por monton m=int(input())#gusanos sabrosos q=[int(x) for x in input().split(' ')]#etiquetas de los gusanos sabrosos monton={} contador=1 for i in range(n): for j in range(a[i]): monton[contador]=i+1 contador+=1 for x in q: print(monton[x])
Title: Worms Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. Output Specification: Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. Demo Input: ['5\n2 7 3 4 9\n3\n1 25 11\n'] Demo Output: ['1\n5\n3\n'] Note: For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
```python n=int(input())#numero de montones a=[int(x) for x in input().split(' ')]#cantidad por monton m=int(input())#gusanos sabrosos q=[int(x) for x in input().split(' ')]#etiquetas de los gusanos sabrosos monton={} contador=1 for i in range(n): for j in range(a[i]): monton[contador]=i+1 contador+=1 for x in q: print(monton[x]) ```
3
535
A
Tavas and Nafas
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type.
The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score.
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
[ "6\n", "99\n", "20\n" ]
[ "six\n", "ninety-nine\n", "twenty\n" ]
You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) .
500
[ { "input": "6", "output": "six" }, { "input": "99", "output": "ninety-nine" }, { "input": "20", "output": "twenty" }, { "input": "10", "output": "ten" }, { "input": "15", "output": "fifteen" }, { "input": "27", "output": "twenty-seven" }, { "input": "40", "output": "forty" }, { "input": "63", "output": "sixty-three" }, { "input": "0", "output": "zero" }, { "input": "1", "output": "one" }, { "input": "2", "output": "two" }, { "input": "8", "output": "eight" }, { "input": "9", "output": "nine" }, { "input": "11", "output": "eleven" }, { "input": "12", "output": "twelve" }, { "input": "13", "output": "thirteen" }, { "input": "14", "output": "fourteen" }, { "input": "16", "output": "sixteen" }, { "input": "17", "output": "seventeen" }, { "input": "18", "output": "eighteen" }, { "input": "19", "output": "nineteen" }, { "input": "21", "output": "twenty-one" }, { "input": "29", "output": "twenty-nine" }, { "input": "30", "output": "thirty" }, { "input": "32", "output": "thirty-two" }, { "input": "38", "output": "thirty-eight" }, { "input": "43", "output": "forty-three" }, { "input": "47", "output": "forty-seven" }, { "input": "50", "output": "fifty" }, { "input": "54", "output": "fifty-four" }, { "input": "56", "output": "fifty-six" }, { "input": "60", "output": "sixty" }, { "input": "66", "output": "sixty-six" }, { "input": "70", "output": "seventy" }, { "input": "76", "output": "seventy-six" }, { "input": "80", "output": "eighty" }, { "input": "82", "output": "eighty-two" }, { "input": "90", "output": "ninety" }, { "input": "91", "output": "ninety-one" }, { "input": "95", "output": "ninety-five" }, { "input": "71", "output": "seventy-one" }, { "input": "46", "output": "forty-six" }, { "input": "84", "output": "eighty-four" }, { "input": "22", "output": "twenty-two" }, { "input": "23", "output": "twenty-three" }, { "input": "24", "output": "twenty-four" }, { "input": "25", "output": "twenty-five" }, { "input": "26", "output": "twenty-six" }, { "input": "28", "output": "twenty-eight" }, { "input": "31", "output": "thirty-one" }, { "input": "33", "output": "thirty-three" }, { "input": "34", "output": "thirty-four" }, { "input": "35", "output": "thirty-five" }, { "input": "36", "output": "thirty-six" }, { "input": "37", "output": "thirty-seven" }, { "input": "39", "output": "thirty-nine" }, { "input": "65", "output": "sixty-five" }, { "input": "68", "output": "sixty-eight" }, { "input": "41", "output": "forty-one" }, { "input": "42", "output": "forty-two" }, { "input": "44", "output": "forty-four" }, { "input": "45", "output": "forty-five" }, { "input": "48", "output": "forty-eight" }, { "input": "49", "output": "forty-nine" }, { "input": "51", "output": "fifty-one" }, { "input": "52", "output": "fifty-two" }, { "input": "53", "output": "fifty-three" }, { "input": "55", "output": "fifty-five" }, { "input": "57", "output": "fifty-seven" }, { "input": "58", "output": "fifty-eight" }, { "input": "59", "output": "fifty-nine" }, { "input": "61", "output": "sixty-one" }, { "input": "62", "output": "sixty-two" }, { "input": "64", "output": "sixty-four" }, { "input": "67", "output": "sixty-seven" }, { "input": "69", "output": "sixty-nine" }, { "input": "72", "output": "seventy-two" }, { "input": "73", "output": "seventy-three" }, { "input": "74", "output": "seventy-four" }, { "input": "75", "output": "seventy-five" }, { "input": "77", "output": "seventy-seven" }, { "input": "78", "output": "seventy-eight" }, { "input": "79", "output": "seventy-nine" }, { "input": "81", "output": "eighty-one" }, { "input": "83", "output": "eighty-three" }, { "input": "85", "output": "eighty-five" }, { "input": "86", "output": "eighty-six" }, { "input": "87", "output": "eighty-seven" }, { "input": "88", "output": "eighty-eight" }, { "input": "89", "output": "eighty-nine" }, { "input": "92", "output": "ninety-two" }, { "input": "93", "output": "ninety-three" }, { "input": "94", "output": "ninety-four" }, { "input": "96", "output": "ninety-six" }, { "input": "7", "output": "seven" }, { "input": "97", "output": "ninety-seven" }, { "input": "98", "output": "ninety-eight" }, { "input": "3", "output": "three" }, { "input": "4", "output": "four" }, { "input": "5", "output": "five" } ]
1,492,500,386
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def handel_upto_99(number): predef={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"fourty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety",100:"hundred",100000:"lakh",10000000:"crore",1000000:"million",1000000000:"billion"} if number in predef.keys(): return predef[number] else: return predef[(number/10)*10]+' '+predef[number%10]
Title: Tavas and Nafas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input Specification: The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. Output Specification: In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Demo Input: ['6\n', '99\n', '20\n'] Demo Output: ['six\n', 'ninety-nine\n', 'twenty\n'] Note: You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) .
```python def handel_upto_99(number): predef={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"fourty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety",100:"hundred",100000:"lakh",10000000:"crore",1000000:"million",1000000000:"billion"} if number in predef.keys(): return predef[number] else: return predef[(number/10)*10]+' '+predef[number%10] ```
-1
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integer — the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { "input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600", "output": "94" }, { "input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600", "output": "1" }, { "input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12", "output": "13" }, { "input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391", "output": "33" }, { "input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3", "output": "3" }, { "input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55", "output": "93" }, { "input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13", "output": "13" }, { "input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1", "output": "1" }, { "input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37", "output": "61" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 600", "output": "1" }, { "input": "4\n1 1 1 2", "output": "2" }, { "input": "4\n0 0 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "2\n0 5", "output": "1" }, { "input": "5\n1 0 0 1 2", "output": "2" } ]
1,596,289,631
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) l=list(map(int,input().split())) s=list(set(l)) for i in s: if i==0; s.remove (i) print(len(s))
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. Output Specification: Print a single integer — the desired number of ways. Demo Input: ['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n'] Demo Output: ['3\n', '1\n', '1\n'] Note: There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
```python n=int(input()) l=list(map(int,input().split())) s=list(set(l)) for i in s: if i==0; s.remove (i) print(len(s)) ```
-1
583
A
Asphalting Roads
PROGRAMMING
1,000
[ "implementation" ]
null
null
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
[ "2\n1 1\n1 2\n2 1\n2 2\n", "1\n1 1\n" ]
[ "1 4 \n", "1 \n" ]
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
500
[ { "input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4 " }, { "input": "1\n1 1", "output": "1 " }, { "input": "2\n1 1\n2 2\n1 2\n2 1", "output": "1 2 " }, { "input": "2\n1 2\n2 2\n2 1\n1 1", "output": "1 3 " }, { "input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1", "output": "1 4 5 " }, { "input": "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3", "output": "1 2 6 " }, { "input": "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3", "output": "1 3 5 14 " }, { "input": "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\n2 2\n1 4\n3 1\n4 1\n2 1\n1 3\n1 1\n4 3\n2 4", "output": "1 2 9 12 " }, { "input": "9\n4 5\n2 3\n8 3\n5 6\n9 3\n4 4\n5 4\n4 7\n1 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n9 9\n8 7\n7 5\n3 7\n6 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n1 1\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 2\n3 9\n2 9\n7 7\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n3 3\n3 8\n5 5\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n8 8\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 4 9 10 14 16 32 56 " }, { "input": "8\n1 1\n1 2\n1 3\n1 4\n1 5\n8 6\n1 7\n1 8\n2 1\n8 5\n2 3\n2 4\n2 5\n2 6\n4 3\n2 2\n3 1\n3 2\n3 3\n3 4\n3 5\n3 6\n5 6\n3 8\n4 1\n4 2\n2 7\n4 4\n8 8\n4 6\n4 7\n4 8\n5 1\n5 2\n5 3\n6 5\n5 5\n3 7\n5 7\n5 8\n6 1\n6 2\n6 3\n6 4\n5 4\n6 6\n6 7\n6 8\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n7 8\n8 1\n8 2\n8 3\n8 4\n2 8\n1 6\n8 7\n4 5", "output": "1 6 11 18 28 36 39 56 " }, { "input": "9\n9 9\n5 5\n8 8\n3 3\n2 2\n6 6\n4 4\n1 1\n7 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n1 7\n8 7\n7 5\n3 7\n5 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n4 5\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 3\n3 9\n2 9\n5 4\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n8 3\n3 8\n9 3\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n4 7\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 3 4 5 6 7 8 9 " } ]
1,588,631,346
2,147,483,647
Python 3
OK
TESTS
39
109
0
n = int(input()) h = [False]*n v = [False]*n day_numbers = [] for day in range(1, n**2 + 1): hi, vi = [int(x)-1 for x in input().split()] if not h[hi] and not v[vi]: h[hi] = v[vi] = True day_numbers.append(day) print(*day_numbers)
Title: Asphalting Roads Time Limit: None seconds Memory Limit: None megabytes Problem Description: City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct. Output Specification: In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. Demo Input: ['2\n1 1\n1 2\n2 1\n2 2\n', '1\n1 1\n'] Demo Output: ['1 4 \n', '1 \n'] Note: In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
```python n = int(input()) h = [False]*n v = [False]*n day_numbers = [] for day in range(1, n**2 + 1): hi, vi = [int(x)-1 for x in input().split()] if not h[hi] and not v[vi]: h[hi] = v[vi] = True day_numbers.append(day) print(*day_numbers) ```
3
417
B
Crash
PROGRAMMING
1,400
[ "implementation" ]
null
null
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive integer *k*, and each sent solution *A* is characterized by two numbers: *x* — the number of different solutions that are sent before the first solution identical to *A*, and *k* — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same *x*. It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number *x* (*x*<=&gt;<=0) of the participant with number *k*, then the testing system has a solution with number *x*<=-<=1 of the same participant stored somewhere before. During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of solutions. Each of the following *n* lines contains two integers separated by space *x* and *k* (0<=≤<=*x*<=≤<=105; 1<=≤<=*k*<=≤<=105) — the number of previous unique solutions and the identifier of the participant.
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
[ "2\n0 1\n1 1\n", "4\n0 1\n1 2\n1 1\n0 2\n", "4\n0 1\n1 1\n0 1\n0 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
1,000
[ { "input": "2\n0 1\n1 1", "output": "YES" }, { "input": "4\n0 1\n1 2\n1 1\n0 2", "output": "NO" }, { "input": "4\n0 1\n1 1\n0 1\n0 2", "output": "YES" }, { "input": "4\n7 1\n4 2\n8 2\n1 8", "output": "NO" }, { "input": "2\n0 8\n0 5", "output": "YES" }, { "input": "3\n7 9\n5 8\n8 2", "output": "NO" }, { "input": "1\n0 8", "output": "YES" }, { "input": "5\n8 10\n7 9\n5 6\n5 2\n10 7", "output": "NO" }, { "input": "7\n0 2\n0 3\n0 2\n0 1\n0 10\n1 10\n0 5", "output": "YES" }, { "input": "6\n0 1\n1 1\n2 1\n1 1\n2 1\n4 1", "output": "NO" }, { "input": "4\n0 1\n1 1\n0 1\n2 1", "output": "YES" }, { "input": "6\n0 1\n1 1\n2 1\n3 1\n4 1\n2 1", "output": "YES" }, { "input": "3\n0 1\n0 1\n2 1", "output": "NO" }, { "input": "1\n1 100000", "output": "NO" }, { "input": "2\n99 1\n99 1", "output": "NO" }, { "input": "4\n0 1\n0 2\n1 1\n1 2", "output": "YES" }, { "input": "4\n0 1\n0 2\n1 1\n2 1", "output": "YES" }, { "input": "5\n0 1\n1 1\n2 1\n1 1\n3 1", "output": "YES" }, { "input": "4\n0 1\n1 100000\n1 1\n0 100000", "output": "NO" }, { "input": "5\n0 1\n1 1\n2 1\n3 1\n1 1", "output": "YES" }, { "input": "3\n0 1\n0 2\n1 1", "output": "YES" }, { "input": "5\n0 1\n1 1\n2 1\n0 1\n4 1", "output": "NO" }, { "input": "1\n2 1", "output": "NO" }, { "input": "6\n0 1\n1 1\n2 1\n0 1\n3 1\n4 1", "output": "YES" } ]
1,397,769,219
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
# -*- coding: utf-8 -*- """ @author: Ilych """ def input_row(): return list( map(int, input().strip().split(' '))) if __name__=='__main__': #print proc2() n = input_row()[0] dct={} for _ in range(n): x,k = input_row() if k not in dct: if x!=0: print('NO') break dct[k]=x continue if x>0 and x != dct[k]+1: print('NO') break dct[k]=x print ('YES')
Title: Crash Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive integer *k*, and each sent solution *A* is characterized by two numbers: *x* — the number of different solutions that are sent before the first solution identical to *A*, and *k* — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same *x*. It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number *x* (*x*<=&gt;<=0) of the participant with number *k*, then the testing system has a solution with number *x*<=-<=1 of the same participant stored somewhere before. During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of solutions. Each of the following *n* lines contains two integers separated by space *x* and *k* (0<=≤<=*x*<=≤<=105; 1<=≤<=*k*<=≤<=105) — the number of previous unique solutions and the identifier of the participant. Output Specification: A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise. Demo Input: ['2\n0 1\n1 1\n', '4\n0 1\n1 2\n1 1\n0 2\n', '4\n0 1\n1 1\n0 1\n0 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python # -*- coding: utf-8 -*- """ @author: Ilych """ def input_row(): return list( map(int, input().strip().split(' '))) if __name__=='__main__': #print proc2() n = input_row()[0] dct={} for _ in range(n): x,k = input_row() if k not in dct: if x!=0: print('NO') break dct[k]=x continue if x>0 and x != dct[k]+1: print('NO') break dct[k]=x print ('YES') ```
0
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,598,418,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
108
307,200
n,m=map(int, input().split()) a=sorted(list(map(int,input().split()))) neg=0 pos=0 for i in range(n): if a[i]==-1: neg=i else: pos=i pos=pos-neg neg=neg+1 for i in range(m): l, r=map(int,input().split()) d=r-(l-1) if not d%2: if d//2<=neg and d//2<=pos: print(1) else: print(0) if d%2: 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()) a=sorted(list(map(int,input().split()))) neg=0 pos=0 for i in range(n): if a[i]==-1: neg=i else: pos=i pos=pos-neg neg=neg+1 for i in range(m): l, r=map(int,input().split()) d=r-(l-1) if not d%2: if d//2<=neg and d//2<=pos: print(1) else: print(0) if d%2: print(0) ```
0
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,624,093,772
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
0
n=int(input()) l=list(map(int,input().split())) l.sort() c=0 while True: if l[-1]<=0: print(c) exit() for i in range(1,n): l[i]=l[i]-1 c+=1 l.sort()
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 n=int(input()) l=list(map(int,input().split())) l.sort() c=0 while True: if l[-1]<=0: print(c) exit() for i in range(1,n): l[i]=l[i]-1 c+=1 l.sort() ```
0
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10", "output": "0" }, { "input": "8 20", "output": "0" }, { "input": "2 8", "output": "0" }, { "input": "20 11", "output": "0" }, { "input": "57 447", "output": "1" }, { "input": "1 1", "output": "2" }, { "input": "66 296", "output": "1" }, { "input": "75 683", "output": "1" }, { "input": "227 975", "output": "1" }, { "input": "247 499", "output": "1" }, { "input": "266 116", "output": "1" }, { "input": "286 916", "output": "1" }, { "input": "307 341", "output": "1" }, { "input": "451 121", "output": "1" }, { "input": "471 921", "output": "1" }, { "input": "502 346", "output": "1" }, { "input": "535 59", "output": "1" }, { "input": "555 699", "output": "1" }, { "input": "747 351", "output": "1" }, { "input": "790 64", "output": "1" }, { "input": "810 704", "output": "1" }, { "input": "855 225", "output": "1" }, { "input": "902 34", "output": "1" }, { "input": "922 514", "output": "1" }, { "input": "971 131", "output": "1" }, { "input": "991 931", "output": "1" }, { "input": "840 780", "output": "0" }, { "input": "102 595", "output": "0" }, { "input": "139 433", "output": "0" }, { "input": "968 288", "output": "0" }, { "input": "563 354", "output": "0" }, { "input": "994 975", "output": "0" }, { "input": "456 221", "output": "0" }, { "input": "205 210", "output": "0" }, { "input": "1 11", "output": "0" }, { "input": "1000 1000", "output": "0" }, { "input": "3 3", "output": "0" }, { "input": "11 99", "output": "0" }, { "input": "2 2", "output": "1" }, { "input": "11 1", "output": "0" }, { "input": "6 6", "output": "1" }, { "input": "100 452", "output": "0" }, { "input": "420 380", "output": "0" }, { "input": "31 31", "output": "0" }, { "input": "2 6", "output": "0" }, { "input": "112 134", "output": "0" }, { "input": "13 13", "output": "0" }, { "input": "1 571", "output": "0" } ]
1,661,953,509
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
92
0
n,m = map(int,input().split()) count = 0 if m>n: x = m else: x = n for a in range(x): b = n-(a*a) if a+(b*b)==m: count += 1 print(count)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
```python n,m = map(int,input().split()) count = 0 if m>n: x = m else: x = n for a in range(x): b = n-(a*a) if a+(b*b)==m: count += 1 print(count) ```
0
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,694,570,853
2,147,483,647
PyPy 3-64
OK
TESTS
30
108
20,275,200
import sys input = sys.stdin.readline def main() -> None : array:list[int] = [] queries:list[int] = [] _, QUERY_LEN = map(int, input().split()) array = list(map(int, input().split())) queries = [int(input()) for _ in range(QUERY_LEN)] answers:list[int] = [] answerTable:list[int] = [0]*len(array) elementSet:set[int] = set() for index in range(len(array)-1, 0-1, -1) : elementSet.add(array[index]) answerTable[index] = len(elementSet) answers = [answerTable[query-1] for query in queries] print("\n".join(map(str, answers))) main()
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python import sys input = sys.stdin.readline def main() -> None : array:list[int] = [] queries:list[int] = [] _, QUERY_LEN = map(int, input().split()) array = list(map(int, input().split())) queries = [int(input()) for _ in range(QUERY_LEN)] answers:list[int] = [] answerTable:list[int] = [0]*len(array) elementSet:set[int] = set() for index in range(len(array)-1, 0-1, -1) : elementSet.add(array[index]) answerTable[index] = len(elementSet) answers = [answerTable[query-1] for query in queries] print("\n".join(map(str, answers))) main() ```
3
712
B
Memory and Trident
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.
The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given.
If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
[ "RRU\n", "UDUR\n", "RUUR\n" ]
[ "-1\n", "1\n", "2\n" ]
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
1,000
[ { "input": "RRU", "output": "-1" }, { "input": "UDUR", "output": "1" }, { "input": "RUUR", "output": "2" }, { "input": "DDDD", "output": "2" }, { "input": "RRRR", "output": "2" }, { "input": "RRRUUD", "output": "2" }, { "input": "UDURLRDURLRD", "output": "1" }, { "input": "RLRU", "output": "1" }, { "input": "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDLUURURDLDRLRDUDDDLDDDURURLUULRDUUULRURUDUDRRUDULLLUUUDRLLDRRDDLRUDRDRDLLRURURRRULURURRRLUUULRRRUURUUDURUDDLLDLDRLRDLDRLLDLDRDRRLRRRURUUUDRDLRLRUDRLULUUULUDDLULDLRLLRDUULLRLRURLRURULLLUDUDDLRULRDUURURLDLUURRRDURRLLDRUUDRDLLDUUDLURUDDUUUULRLLURLUDDRLRRDRURLRUDRLDDRLLL", "output": "-1" }, { "input": "LDLDLDLDLDRULD", "output": "5" }, { "input": "LULULURULLLU", "output": "5" }, { "input": "DRDRDDRR", "output": "4" }, { "input": "LR", "output": "0" }, { "input": "UL", "output": "1" }, { "input": "UD", "output": "0" }, { "input": "R", "output": "-1" }, { "input": "LU", "output": "1" }, { "input": "RR", "output": "1" }, { "input": "UDLR", "output": "0" }, { "input": "RRRRRLLUUUUDD", "output": "-1" }, { "input": "UUUUDLLLLR", "output": "3" }, { "input": "LLRUD", "output": "-1" }, { "input": "LLRDDU", "output": "1" } ]
1,479,483,007
2,147,483,647
Python 3
OK
TESTS
75
108
307,200
if __name__ == '__main__': h = v = 0 line = str(input()) for it in line: if it == 'R': h += 1 elif it == 'L': h -= 1 elif it == 'U': v += 1 elif it == 'D': v -= 1 distance = abs(abs(h) - abs(v)) if distance % 2 > 0: print(-1) else: print(distance // 2 + min(abs(h), abs(v)))
Title: Memory and Trident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in *s* with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. Input Specification: The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. Output Specification: If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. Demo Input: ['RRU\n', 'UDUR\n', 'RUUR\n'] Demo Output: ['-1\n', '1\n', '2\n'] Note: In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
```python if __name__ == '__main__': h = v = 0 line = str(input()) for it in line: if it == 'R': h += 1 elif it == 'L': h -= 1 elif it == 'U': v += 1 elif it == 'D': v -= 1 distance = abs(abs(h) - abs(v)) if distance % 2 > 0: print(-1) else: print(distance // 2 + min(abs(h), abs(v))) ```
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
1,698,427,886
2,147,483,647
PyPy 3-64
OK
TESTS
29
77
0
a=int(input()) b=int(input()) c=int(input()) z=[] z.append(a+b+c) z.append(a*b*c) z.append((a+b)*c) z.append(a*(b+c)) z.append(a+b*c) z.append(a*b+c) z.sort() print(z[-1])
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python a=int(input()) b=int(input()) c=int(input()) z=[] z.append(a+b+c) z.append(a*b*c) z.append((a+b)*c) z.append(a*(b+c)) z.append(a+b*c) z.append(a*b+c) z.sort() print(z[-1]) ```
3
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,518,771,706
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
61
5,632,000
n,m=input().split(' ') a=sorted([int(i) for i in input().split(' ')]) b=sorted([int(i) for i in input().split(' ')]) if(b[-1]>0): print(max(b[-1]*a[-2],b[0]*a[1])) else: print(max(b[-1]*a[1],b[0]*a[-2]))
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python n,m=input().split(' ') a=sorted([int(i) for i in input().split(' ')]) b=sorted([int(i) for i in input().split(' ')]) if(b[-1]>0): print(max(b[-1]*a[-2],b[0]*a[1])) else: print(max(b[-1]*a[1],b[0]*a[-2])) ```
0
446
A
DZY Loves Sequences
PROGRAMMING
1,600
[ "dp", "implementation", "two pointers" ]
null
null
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
[ "6\n7 2 3 1 5 6\n" ]
[ "5\n" ]
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
500
[ { "input": "6\n7 2 3 1 5 6", "output": "5" }, { "input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "output": "9" }, { "input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371", "output": "19" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "2" }, { "input": "5\n1 2 3 4 1", "output": "5" }, { "input": "10\n1 2 3 4 5 5 6 7 8 9", "output": "6" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "5\n1 1 2 3 4", "output": "5" }, { "input": "5\n1 2 3 1 6", "output": "5" }, { "input": "1\n42", "output": "1" }, { "input": "5\n1 2 42 3 4", "output": "4" }, { "input": "5\n1 5 9 6 10", "output": "4" }, { "input": "5\n5 2 3 4 5", "output": "5" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "5\n1 2 3 3 4", "output": "4" }, { "input": "8\n1 2 3 4 1 5 6 7", "output": "5" }, { "input": "1\n3", "output": "1" }, { "input": "3\n5 1 2", "output": "3" }, { "input": "4\n1 4 3 4", "output": "4" }, { "input": "6\n7 2 12 4 5 6", "output": "5" }, { "input": "6\n7 2 3 1 4 5", "output": "4" }, { "input": "6\n2 3 5 5 6 7", "output": "6" }, { "input": "5\n2 4 7 6 8", "output": "5" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 2", "output": "2" }, { "input": "5\n4 1 2 3 4", "output": "5" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6", "output": "7" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "6\n1 2 2 3 4 5", "output": "5" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n5 1 2 3", "output": "4" }, { "input": "5\n9 1 2 3 4", "output": "5" }, { "input": "2\n1 1", "output": "2" }, { "input": "5\n1 3 2 4 5", "output": "4" }, { "input": "6\n1 2 1 2 4 5", "output": "5" }, { "input": "10\n1 1 5 3 2 9 9 7 7 6", "output": "3" }, { "input": "6\n1 2 3 100000 100 101", "output": "6" }, { "input": "4\n3 3 3 4", "output": "3" }, { "input": "3\n4 3 5", "output": "3" }, { "input": "5\n1 3 2 3 4", "output": "4" }, { "input": "10\n1 2 3 4 5 10 10 11 12 13", "output": "10" }, { "input": "7\n11 2 1 2 13 4 14", "output": "5" }, { "input": "3\n5 1 3", "output": "3" }, { "input": "4\n1 5 3 4", "output": "4" }, { "input": "10\n1 2 3 4 100 6 7 8 9 10", "output": "10" }, { "input": "3\n5 3 5", "output": "3" }, { "input": "5\n100 100 7 8 9", "output": "4" }, { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "5\n1 2 4 4 5", "output": "5" }, { "input": "6\n7 4 5 6 7 8", "output": "6" }, { "input": "9\n3 4 1 6 3 4 5 6 7", "output": "7" }, { "input": "3\n1000 1 2", "output": "3" }, { "input": "3\n20 1 9", "output": "3" }, { "input": "6\n7 2 3 1 4 6", "output": "4" }, { "input": "3\n100 5 10", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "6\n4 2 8 1 2 5", "output": "4" }, { "input": "3\n25 1 6", "output": "3" }, { "input": "10\n17 99 23 72 78 36 5 43 95 9", "output": "5" }, { "input": "7\n21 16 22 21 11 13 19", "output": "4" }, { "input": "5\n1 2 5 3 4", "output": "4" }, { "input": "6\n2 2 2 3 4 5", "output": "5" }, { "input": "5\n1 3 1 2 3", "output": "4" }, { "input": "3\n81 33 64", "output": "3" }, { "input": "7\n14 3 3 19 13 19 15", "output": "4" }, { "input": "9\n1 2 3 4 5 42 7 8 9", "output": "9" }, { "input": "5\n2 3 7 5 6", "output": "5" }, { "input": "5\n1 3 3 4 5", "output": "5" }, { "input": "6\n1 5 4 3 4 5", "output": "4" } ]
1,490,391,711
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,608,000
from sys import stdin N = int(stdin.readline().rstrip()) seq = [int(x) for x in stdin.readline().rstrip().split()] start_index = 0 change_index = -1 max_count = 1 for n in range(1, N): if seq[n] <= seq[n - 1]: if change_index == -1: change_index = n else: diff = n - start_index if max_count < diff: max_count = diff start_index = change_index change_index = n diff = n - start_index if max_count < diff: max_count = diff print(max_count + 1)
Title: DZY Loves Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: In a single line print the answer to the problem — the maximum length of the required subsegment. Demo Input: ['6\n7 2 3 1 5 6\n'] Demo Output: ['5\n'] Note: You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
```python from sys import stdin N = int(stdin.readline().rstrip()) seq = [int(x) for x in stdin.readline().rstrip().split()] start_index = 0 change_index = -1 max_count = 1 for n in range(1, N): if seq[n] <= seq[n - 1]: if change_index == -1: change_index = n else: diff = n - start_index if max_count < diff: max_count = diff start_index = change_index change_index = n diff = n - start_index if max_count < diff: max_count = diff print(max_count + 1) ```
0