contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
699
B
One Bomb
PROGRAMMING
1,400
[ "implementation" ]
null
null
You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls in the column *y*. You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field. The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
[ "3 4\n.*..\n....\n.*..\n", "3 3\n..*\n.*.\n*..\n", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n" ]
[ "YES\n1 2\n", "NO\n", "YES\n3 3\n" ]
none
1,000
[ { "input": "3 4\n.*..\n....\n.*..", "output": "YES\n1 2" }, { "input": "3 3\n..*\n.*.\n*..", "output": "NO" }, { "input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..", "output": "YES\n3 3" }, { "input": "1 10\n**********", "output": "YES\n1 1" }, { "input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*", "output": "YES\n1 1" }, { "input": "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*", "output": "YES\n3 10" }, { "input": "10 10\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*", "output": "YES\n1 10" }, { "input": "2 2\n.*\n*.", "output": "YES\n2 2" }, { "input": "4 4\n....\n...*\n....\n*..*", "output": "YES\n4 4" }, { "input": "4 4\n*...\n*...\n....\n****", "output": "YES\n4 1" }, { "input": "1 1\n*", "output": "YES\n1 1" }, { "input": "1 1\n.", "output": "YES\n1 1" }, { "input": "1 2\n.*", "output": "YES\n1 2" }, { "input": "2 1\n.\n*", "output": "YES\n1 1" }, { "input": "2 2\n**\n**", "output": "NO" }, { "input": "3 1\n*\n*\n*", "output": "YES\n1 1" }, { "input": "3 2\n*.\n.*\n.*", "output": "YES\n1 2" }, { "input": "3 3\n***\n***\n***", "output": "NO" }, { "input": "2 2\n..\n.*", "output": "YES\n1 2" }, { "input": "6 5\n..*..\n..*..\n**.**\n..*..\n..*..\n..*..", "output": "YES\n3 3" }, { "input": "3 3\n.*.\n*.*\n.*.", "output": "YES\n2 2" }, { "input": "4 4\n*...\n....\n....\n...*", "output": "YES\n4 1" }, { "input": "2 4\n...*\n...*", "output": "YES\n1 4" }, { "input": "2 2\n..\n..", "output": "YES\n1 1" }, { "input": "3 3\n..*\n.*.\n..*", "output": "YES\n2 3" }, { "input": "2 2\n*.\n.*", "output": "YES\n2 1" }, { "input": "3 2\n.*\n*.\n.*", "output": "YES\n2 2" }, { "input": "3 3\n***\n.*.\n.*.", "output": "YES\n1 2" }, { "input": "4 4\n*.*.\n..*.\n.***\n..*.", "output": "NO" }, { "input": "2 3\n..*\n**.", "output": "YES\n2 3" }, { "input": "3 2\n*.\n.*\n*.", "output": "YES\n2 1" }, { "input": "4 4\n..*.\n**.*\n..*.\n..*.", "output": "YES\n2 3" }, { "input": "3 3\n*..\n*..\n***", "output": "YES\n3 1" }, { "input": "3 3\n...\n*.*\n.*.", "output": "YES\n2 2" }, { "input": "3 2\n..\n..\n**", "output": "YES\n3 1" }, { "input": "3 4\n...*\n...*\n...*", "output": "YES\n1 4" }, { "input": "5 5\n..*..\n..*..\n**.**\n..*..\n..*..", "output": "YES\n3 3" }, { "input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.*", "output": "NO" }, { "input": "3 3\n...\n.*.\n..*", "output": "YES\n3 2" }, { "input": "3 5\n....*\n....*\n....*", "output": "YES\n1 5" }, { "input": "3 3\n...\n...\n.*.", "output": "YES\n1 2" }, { "input": "3 3\n*..\n...\n..*", "output": "YES\n3 1" }, { "input": "2 3\n..*\n..*", "output": "YES\n1 3" }, { "input": "2 2\n**\n.*", "output": "YES\n1 2" }, { "input": "3 3\n..*\n*..\n*..", "output": "YES\n1 1" }, { "input": "5 4\n.*..\n*.**\n.*..\n.*..\n.*..", "output": "YES\n2 2" }, { "input": "6 5\n*.*..\n..*..\n*****\n..*..\n..*..\n..*..", "output": "NO" }, { "input": "4 4\n.*..\n*.**\n....\n.*..", "output": "YES\n2 2" }, { "input": "3 5\n....*\n....*\n*****", "output": "YES\n3 5" }, { "input": "3 3\n..*\n*..\n..*", "output": "YES\n2 3" }, { "input": "6 6\n..*...\n......\n......\n......\n......\n*....*", "output": "YES\n6 3" }, { "input": "4 4\n.*..\n*...\n.*..\n.*..", "output": "YES\n2 2" }, { "input": "3 3\n...\n..*\n.*.", "output": "YES\n3 3" }, { "input": "3 2\n.*\n*.\n*.", "output": "YES\n1 1" }, { "input": "4 2\n**\n.*\n.*\n.*", "output": "YES\n1 2" }, { "input": "5 5\n*...*\n.....\n.....\n.....\n..*..", "output": "YES\n1 3" }, { "input": "3 3\n**.\n...\n..*", "output": "YES\n1 3" }, { "input": "3 3\n*.*\n*..\n*.*", "output": "NO" }, { "input": "5 4\n....\n....\n*..*\n....\n.*..", "output": "YES\n3 2" }, { "input": "5 5\n...*.\n...*.\n...*.\n...*.\n***.*", "output": "YES\n5 4" }, { "input": "5 5\n*****\n*****\n*****\n*****\n*****", "output": "NO" }, { "input": "3 3\n.*.\n..*\n.*.", "output": "YES\n2 2" }, { "input": "3 3\n*.*\n...\n*.*", "output": "NO" }, { "input": "2 3\n.*.\n*.*", "output": "YES\n2 2" }, { "input": "3 10\n.......*..\n........*.\n.........*", "output": "NO" }, { "input": "3 3\n.*.\n.*.\n.**", "output": "YES\n3 2" }, { "input": "4 4\n*...\n....\n....\n..**", "output": "YES\n4 1" }, { "input": "4 4\n****\n****\n****\n****", "output": "NO" }, { "input": "3 2\n.*\n.*\n*.", "output": "YES\n3 2" }, { "input": "3 3\n..*\n..*\n**.", "output": "YES\n3 3" }, { "input": "6 3\n...\n...\n...\n...\n**.\n.*.", "output": "YES\n5 2" }, { "input": "3 4\n****\n..*.\n..*.", "output": "YES\n1 3" }, { "input": "5 5\n*..*.\n.....\n.....\n.....\n...*.", "output": "YES\n1 4" }, { "input": "6 5\n..*..\n..*..\n.*...\n..*..\n..*..\n..*..", "output": "YES\n3 3" } ]
1,557,574,189
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
10,854,400
s=[int(n) for n in input().split()] z=[] m=0 for n in range(s[0]): z.append([n for n in input()]) m+=z[n].count('*') t=[] for n in range(len(z[0])): t.append([]) for k in range(len(z)): t[n].append(z[k][n]) a=0 l=1 #print(t) for n in range(len(z)): for k in range(len(z[n])): a=z[n].count('*') b=t[k].count('*') if (a+b-1)==m: l=0 print('YES') print(n+1,k+1) break if l==0: break else: l=1 continue if l==1: print('NO')
Title: One Bomb Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls in the column *y*. You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. Input Specification: The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field. The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. Output Specification: If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. Demo Input: ['3 4\n.*..\n....\n.*..\n', '3 3\n..*\n.*.\n*..\n', '6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n'] Demo Output: ['YES\n1 2\n', 'NO\n', 'YES\n3 3\n'] Note: none
```python s=[int(n) for n in input().split()] z=[] m=0 for n in range(s[0]): z.append([n for n in input()]) m+=z[n].count('*') t=[] for n in range(len(z[0])): t.append([]) for k in range(len(z)): t[n].append(z[k][n]) a=0 l=1 #print(t) for n in range(len(z)): for k in range(len(z[n])): a=z[n].count('*') b=t[k].count('*') if (a+b-1)==m: l=0 print('YES') print(n+1,k+1) break if l==0: break else: l=1 continue if l==1: print('NO') ```
0
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68" }, { "input": "1000000000", "output": "666666667" }, { "input": "5", "output": "3" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "666666666" }, { "input": "999999998", "output": "666666665" }, { "input": "999999997", "output": "666666665" }, { "input": "999999996", "output": "666666664" }, { "input": "999999995", "output": "666666663" }, { "input": "999999994", "output": "666666663" }, { "input": "999999993", "output": "666666662" }, { "input": "999999992", "output": "666666661" }, { "input": "999999991", "output": "666666661" }, { "input": "1000", "output": "667" }, { "input": "10000", "output": "6667" }, { "input": "100000", "output": "66667" }, { "input": "1000000", "output": "666667" }, { "input": "10000000", "output": "6666667" }, { "input": "100000000", "output": "66666667" }, { "input": "7", "output": "5" } ]
1,566,237,816
2,147,483,647
Python 3
OK
TESTS
26
124
0
n=int(input()) n=2*n n=n+1 print(n//3)
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. Output Specification: Print the maximum possible number of times Artem can give presents to Masha. Demo Input: ['1\n', '2\n', '3\n', '4\n'] Demo Output: ['1\n', '1\n', '2\n', '3\n'] Note: In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
```python n=int(input()) n=2*n n=n+1 print(n//3) ```
3
0
none
none
none
0
[ "none" ]
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.
0
[ { "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,512,589,300
2,147,483,647
Python 3
OK
TESTS
53
62
5,529,600
n = [int(i) for i in input().split()] p = ['012','013','014','015','123','124','125','234','235','345','023','024','025','034','035','045','134','135','145','245'] try: for i in p: if sum([n[int(j)] for j in i]) == sum(n)/2: print('YES') 3/0 print('NO') except ZeroDivisionError: pass
Title: none 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 n = [int(i) for i in input().split()] p = ['012','013','014','015','123','124','125','234','235','345','023','024','025','034','035','045','134','135','145','245'] try: for i in p: if sum([n[int(j)] for j in i]) == sum(n)/2: print('YES') 3/0 print('NO') except ZeroDivisionError: pass ```
3
915
C
Permute Digits
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
0
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" }, { "input": "123456789123456789\n276193619183618162", "output": "276193618987554432" }, { "input": "1000000000000000000\n1000000000000000000", "output": "1000000000000000000" }, { "input": "1\n1000000000000000000", "output": "1" }, { "input": "999999999999999999\n1000000000000000000", "output": "999999999999999999" }, { "input": "2475345634895\n3455834583479", "output": "3455834579642" }, { "input": "15778899\n98715689", "output": "98598771" }, { "input": "4555\n5454", "output": "4555" }, { "input": "122112\n221112", "output": "221112" }, { "input": "199999999999991\n191000000000000", "output": "119999999999999" }, { "input": "13\n31", "output": "31" }, { "input": "212\n211", "output": "122" }, { "input": "222234\n322223", "output": "243222" }, { "input": "123456789\n987654311", "output": "987654231" }, { "input": "20123\n21022", "output": "20321" }, { "input": "10101\n11000", "output": "10110" }, { "input": "592\n924", "output": "592" }, { "input": "5654456\n5634565", "output": "5566544" }, { "input": "655432\n421631", "output": "365542" }, { "input": "200\n200", "output": "200" }, { "input": "123456789987654321\n121111111111111111", "output": "119988776655443322" }, { "input": "12345\n21344", "output": "15432" }, { "input": "120\n200", "output": "120" }, { "input": "123\n212", "output": "132" }, { "input": "2184645\n5213118", "output": "5186442" }, { "input": "9912346\n9912345", "output": "9694321" }, { "input": "5003\n5000", "output": "3500" }, { "input": "12345\n31234", "output": "25431" }, { "input": "5001\n5000", "output": "1500" }, { "input": "53436\n53425", "output": "53364" }, { "input": "9329\n3268", "output": "2993" }, { "input": "1234567890\n9000000001", "output": "8976543210" }, { "input": "321\n212", "output": "132" }, { "input": "109823464\n901234467", "output": "896443210" }, { "input": "6543\n6542", "output": "6534" }, { "input": "555441\n555100", "output": "554541" }, { "input": "472389479\n327489423", "output": "327487994" }, { "input": "45645643756464352\n53465475637456247", "output": "53465475636654442" }, { "input": "254\n599", "output": "542" }, { "input": "5232222345652321\n5000000000000000", "output": "4655533322222221" }, { "input": "201\n200", "output": "120" }, { "input": "14362799391220361\n45160821596433661", "output": "43999766332221110" }, { "input": "3453\n5304", "output": "4533" }, { "input": "989\n998", "output": "998" }, { "input": "5200000000234\n5200000000311", "output": "5200000000243" }, { "input": "5555132\n1325442", "output": "1255553" }, { "input": "123\n211", "output": "132" }, { "input": "65689\n66123", "output": "65986" }, { "input": "123451234567890\n123456789012345", "output": "123456789012345" }, { "input": "22115\n22015", "output": "21521" }, { "input": "123\n311", "output": "231" }, { "input": "12222\n21111", "output": "12222" }, { "input": "765\n567", "output": "567" }, { "input": "9087645\n9087640", "output": "9087564" }, { "input": "1111111122222333\n2220000000000000", "output": "2213332221111111" }, { "input": "7901\n7108", "output": "7091" }, { "input": "215489\n215488", "output": "214985" }, { "input": "102\n200", "output": "120" }, { "input": "19260817\n20011213", "output": "19876210" }, { "input": "12345\n53200", "output": "53142" }, { "input": "1040003001\n1040003000", "output": "1040001300" }, { "input": "295\n924", "output": "592" }, { "input": "20000000000000001\n20000000000000000", "output": "12000000000000000" }, { "input": "99988877\n99887766", "output": "99879887" }, { "input": "12\n12", "output": "12" }, { "input": "199999999999999999\n900000000000000000", "output": "199999999999999999" }, { "input": "1234\n4310", "output": "4231" }, { "input": "100011\n100100", "output": "100011" }, { "input": "328899\n328811", "output": "299883" }, { "input": "646722972346\n397619201220", "output": "397476664222" }, { "input": "1203\n1200", "output": "1032" }, { "input": "1\n2", "output": "1" }, { "input": "1112\n2110", "output": "1211" }, { "input": "4545\n5540", "output": "5454" }, { "input": "3053\n5004", "output": "3530" }, { "input": "3503\n5004", "output": "3530" }, { "input": "351731653766064847\n501550303749042658", "output": "501548777666643331" }, { "input": "10123456789013451\n26666666666666666", "output": "26598754433111100" }, { "input": "1110111\n1100000", "output": "1011111" }, { "input": "30478\n32265", "output": "30874" }, { "input": "456546546549874615\n441554543131214545", "output": "441554498766665554" }, { "input": "214\n213", "output": "142" }, { "input": "415335582799619283\n133117803602859310", "output": "132999887655543321" }, { "input": "787\n887", "output": "877" }, { "input": "3333222288889999\n3333222288881111", "output": "3332999988883222" }, { "input": "495779862481416791\n836241745208800994", "output": "829998777665444111" }, { "input": "139\n193", "output": "193" }, { "input": "9568\n6500", "output": "5986" }, { "input": "3208899\n3228811", "output": "3209988" }, { "input": "27778\n28710", "output": "27877" }, { "input": "62345\n46415", "output": "46352" }, { "input": "405739873179209\n596793907108871", "output": "594998777332100" }, { "input": "365\n690", "output": "653" }, { "input": "8388731334391\n4710766672578", "output": "4398887333311" }, { "input": "1230\n1200", "output": "1032" }, { "input": "1025\n5000", "output": "2510" }, { "input": "4207799\n4027711", "output": "2997740" }, { "input": "4444222277779999\n4444222277771111", "output": "4442999977774222" }, { "input": "7430\n3047", "output": "3047" }, { "input": "649675735\n540577056", "output": "539776654" }, { "input": "26\n82", "output": "62" }, { "input": "241285\n207420", "output": "185422" }, { "input": "3\n3", "output": "3" }, { "input": "12\n21", "output": "21" }, { "input": "481287\n826607", "output": "824871" }, { "input": "40572351\n59676984", "output": "57543210" }, { "input": "268135787269\n561193454469", "output": "539887766221" }, { "input": "4\n9", "output": "4" }, { "input": "5\n6", "output": "5" }, { "input": "60579839\n33370073", "output": "30998765" }, { "input": "49939\n39200", "output": "34999" }, { "input": "2224\n4220", "output": "2422" }, { "input": "427799\n427711", "output": "299774" }, { "input": "49\n90", "output": "49" }, { "input": "93875\n82210", "output": "79853" }, { "input": "78831\n7319682", "output": "88731" }, { "input": "937177\n7143444", "output": "977731" }, { "input": "499380628\n391990337", "output": "390988642" }, { "input": "2090909\n2900000", "output": "2099900" }, { "input": "112233445566778890\n987654321987654320", "output": "987654321876543210" }, { "input": "48257086\n80903384", "output": "80876542" }, { "input": "112233445566778890\n900654321987654320", "output": "898776655443322110" }, { "input": "112233445566778890\n123456789123456788", "output": "123456789123456780" }, { "input": "5207799\n5027711", "output": "2997750" }, { "input": "200000000000000001\n200000000000000000", "output": "120000000000000000" }, { "input": "597402457\n797455420", "output": "797455420" }, { "input": "90\n94", "output": "90" }, { "input": "86888\n88683", "output": "86888" }, { "input": "419155888\n588151913", "output": "588151894" }, { "input": "408919130\n191830070", "output": "191830049" }, { "input": "524975\n554924", "output": "554792" }, { "input": "53029\n30524", "output": "30295" }, { "input": "5549\n5542", "output": "5495" }, { "input": "6\n9", "output": "6" }, { "input": "87\n810", "output": "87" }, { "input": "920491855\n281495062", "output": "281495059" }, { "input": "6691\n6910", "output": "6691" }, { "input": "533\n335", "output": "335" }, { "input": "999999999999999998\n999999999999999997", "output": "999999999999999989" }, { "input": "21111111111111111\n21111111111111110", "output": "12111111111111111" }, { "input": "2\n12", "output": "2" }, { "input": "76544\n45744", "output": "45674" }, { "input": "2000000000000001\n2000000000000000", "output": "1200000000000000" }, { "input": "740867\n467701", "output": "467087" }, { "input": "2\n6", "output": "2" }, { "input": "103\n130", "output": "130" }, { "input": "2423712\n8466235", "output": "7432221" }, { "input": "84\n48", "output": "48" }, { "input": "1210\n12113", "output": "2110" }, { "input": "2430\n20786", "output": "4320" }, { "input": "100\n999", "output": "100" }, { "input": "19325\n21903", "output": "21593" }, { "input": "1969\n23251", "output": "9961" } ]
1,687,777,051
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
0
import sys def solve(a,b): return a a = input() b = input() print(solve(a,b))
Title: Permute Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is. Input Specification: The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. Output Specification: Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. Demo Input: ['123\n222\n', '3921\n10000\n', '4940\n5000\n'] Demo Output: ['213\n', '9321\n', '4940\n'] Note: none
```python import sys def solve(a,b): return a a = input() b = input() print(solve(a,b)) ```
0
23
B
Party
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "math" ]
B. Party
2
256
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end?
The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
[ "1\n3\n" ]
[ "1\n" ]
none
0
[ { "input": "1\n3", "output": "1" } ]
1,625,663,348
2,147,483,647
Python 3
OK
TESTS
2
1,526
0
test_case = int(input()); while test_case > 0: people = int(input()); if people>2: people=people-2; else: people=0; print(people); test_case -= 1
Title: Party Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end? Input Specification: The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105). Output Specification: For each test output in a separate line one number — the maximum amount of people that could stay in the end. Demo Input: ['1\n3\n'] Demo Output: ['1\n'] Note: none
```python test_case = int(input()); while test_case > 0: people = int(input()); if people>2: people=people-2; else: people=0; print(people); test_case -= 1 ```
3.6185
748
C
Santa Claus and Robot
PROGRAMMING
1,400
[ "constructive algorithms", "math" ]
null
null
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches *p*1, it'll move to *p*2, again, choosing one of the shortest ways, then to *p*3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order. While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robot traveled the *k*-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.
The only line of input should contain the minimum possible length of the sequence.
[ "4\nRURD\n", "6\nRRULDD\n", "26\nRRRULURURUULULLLDLDDRDRDLD\n", "3\nRLL\n", "4\nLRLR\n" ]
[ "2\n", "2\n", "7\n", "2\n", "4\n" ]
The illustrations to the first three tests are given below. <img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1f.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/c7b4534f24cbad48148bcba24bc44f37bf7a2dbf.png" style="max-width: 100.0%;max-height: 100.0%;"/> The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
1,500
[ { "input": "4\nRURD", "output": "2" }, { "input": "6\nRRULDD", "output": "2" }, { "input": "26\nRRRULURURUULULLLDLDDRDRDLD", "output": "7" }, { "input": "3\nRLL", "output": "2" }, { "input": "4\nLRLR", "output": "4" }, { "input": "5\nLRDLR", "output": "4" }, { "input": "10\nDDRDUULUDD", "output": "3" }, { "input": "1\nD", "output": "1" } ]
1,482,660,900
4,200
Python 3
OK
TESTS
32
826
5,222,400
class Point: x = 0 y = 0 def __init__(self, new_x, new_y): self.x = new_x self.y = new_y def is_shortest(a, b, turn): if a.x == b.x and a.y < b.y: return not turn[0] and not turn[1] and not turn[3] elif a.x > b.x and a.y < b.y: return not turn[0] and not turn[3] elif a.x > b.x and a.y == b.y: return not turn[0] and not turn[2] and not turn[3] elif a.x > b.x and a.y > b.y: return not turn[0] and not turn[2] elif a.x == b.x and a.y > b.y: return not turn[0] and not turn[1] and not turn[2] elif a.x < b.x and a.y > b.y: return not turn[1] and not turn[2] elif a.x < b.x and a.y == b.y: return not turn[1] and not turn[2] and not turn[3] elif a.x < b.x and a.y < b.y: return not turn[1] and not turn[3] else: return not turn[0] and not turn[1] and not turn[2] and not turn[3] #print(is_shortest(Point(2, 2), Point(3, 2), [1, 0, 0, 0])) input() point = 0 turn = [0] * 4 A = Point(0, 0) B = Point(0, 0) state = Point(0, 0) s = input().strip() i = 0 while i < len(s): c = s[i] B.x = state.x B.y = state.y if c == "R": B.x += 1 turn[0] = 1 elif c == "L": B.x -= 1 turn[1] = 1 elif c == "U": B.y += 1 turn[2] = 1 else: B.y -= 1 turn[3] = 1 #print("#") #print(A.x, A.y) #print(B.x, B.y) if not is_shortest(A, B, turn): A.x = state.x A.y = state.y #print(A.x, A.y) point += 1 turn = [0] * 4 else: state.x = B.x state.y = B.y i += 1 print(point + 1)
Title: Santa Claus and Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches *p*1, it'll move to *p*2, again, choosing one of the shortest ways, then to *p*3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order. While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence. Input Specification: The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robot traveled the *k*-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation. Output Specification: The only line of input should contain the minimum possible length of the sequence. Demo Input: ['4\nRURD\n', '6\nRRULDD\n', '26\nRRRULURURUULULLLDLDDRDRDLD\n', '3\nRLL\n', '4\nLRLR\n'] Demo Output: ['2\n', '2\n', '7\n', '2\n', '4\n'] Note: The illustrations to the first three tests are given below. <img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1f.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/c7b4534f24cbad48148bcba24bc44f37bf7a2dbf.png" style="max-width: 100.0%;max-height: 100.0%;"/> The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
```python class Point: x = 0 y = 0 def __init__(self, new_x, new_y): self.x = new_x self.y = new_y def is_shortest(a, b, turn): if a.x == b.x and a.y < b.y: return not turn[0] and not turn[1] and not turn[3] elif a.x > b.x and a.y < b.y: return not turn[0] and not turn[3] elif a.x > b.x and a.y == b.y: return not turn[0] and not turn[2] and not turn[3] elif a.x > b.x and a.y > b.y: return not turn[0] and not turn[2] elif a.x == b.x and a.y > b.y: return not turn[0] and not turn[1] and not turn[2] elif a.x < b.x and a.y > b.y: return not turn[1] and not turn[2] elif a.x < b.x and a.y == b.y: return not turn[1] and not turn[2] and not turn[3] elif a.x < b.x and a.y < b.y: return not turn[1] and not turn[3] else: return not turn[0] and not turn[1] and not turn[2] and not turn[3] #print(is_shortest(Point(2, 2), Point(3, 2), [1, 0, 0, 0])) input() point = 0 turn = [0] * 4 A = Point(0, 0) B = Point(0, 0) state = Point(0, 0) s = input().strip() i = 0 while i < len(s): c = s[i] B.x = state.x B.y = state.y if c == "R": B.x += 1 turn[0] = 1 elif c == "L": B.x -= 1 turn[1] = 1 elif c == "U": B.y += 1 turn[2] = 1 else: B.y -= 1 turn[3] = 1 #print("#") #print(A.x, A.y) #print(B.x, B.y) if not is_shortest(A, B, turn): A.x = state.x A.y = state.y #print(A.x, A.y) point += 1 turn = [0] * 4 else: state.x = B.x state.y = B.y i += 1 print(point + 1) ```
3
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1", "output": "YES" }, { "input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1", "output": "NO" }, { "input": "10 3\n8 3 5 4 2 3 2 2 1", "output": "NO" }, { "input": "10 9\n8 3 5 4 2 3 2 2 1", "output": "YES" }, { "input": "3 2\n1 1", "output": "YES" }, { "input": "3 2\n2 1", "output": "NO" }, { "input": "4 2\n2 1 1", "output": "NO" }, { "input": "4 4\n2 2 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "3 3\n1 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 1 1", "output": "YES" }, { "input": "3 3\n2 1", "output": "YES" }, { "input": "4 4\n1 1 1", "output": "YES" }, { "input": "8 8\n1 1 1 1 1 1 1", "output": "YES" }, { "input": "5 5\n1 1 1 1", "output": "YES" } ]
1,674,648,566
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
1,945,600
n = [int(m) for m in input().split()] s = [int(c) for c in input().split()] t = 0 for i in range(len(s)): t += s[i] if t > n[1]: print("NO") break elif t == n[1]: print("YES") break
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. Input Specification: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. Output Specification: If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". Demo Input: ['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
```python n = [int(m) for m in input().split()] s = [int(c) for c in input().split()] t = 0 for i in range(len(s)): t += s[i] if t > n[1]: print("NO") break elif t == n[1]: print("YES") break ```
0
429
A
Xor-tree
PROGRAMMING
1,300
[ "dfs and similar", "trees" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
500
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output": "7\n1\n4\n7\n8\n9\n11\n13" }, { "input": "20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n10 2\n11 6\n12 9\n13 2\n14 12\n15 14\n16 8\n17 9\n18 13\n19 2\n20 17\n1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0\n1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1", "output": "8\n11\n15\n17\n20\n10\n18\n19\n7" }, { "input": "30\n2 1\n3 2\n4 3\n5 3\n6 5\n7 3\n8 3\n9 2\n10 3\n11 2\n12 11\n13 6\n14 4\n15 5\n16 11\n17 9\n18 14\n19 6\n20 2\n21 19\n22 9\n23 19\n24 20\n25 14\n26 22\n27 1\n28 6\n29 13\n30 27\n1 0 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0\n0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0", "output": "15\n1\n2\n4\n5\n6\n13\n29\n19\n21\n23\n28\n7\n22\n26\n30" }, { "input": "15\n2 1\n3 1\n4 1\n5 1\n6 3\n7 1\n8 1\n9 1\n10 5\n11 9\n12 3\n13 5\n14 5\n15 4\n1 1 0 0 0 0 1 1 1 0 1 1 1 0 0\n1 0 1 1 0 1 1 1 1 1 1 1 1 1 0", "output": "6\n2\n3\n6\n4\n10\n14" }, { "input": "20\n2 1\n3 1\n4 2\n5 2\n6 3\n7 1\n8 6\n9 2\n10 3\n11 6\n12 2\n13 3\n14 2\n15 1\n16 8\n17 15\n18 2\n19 14\n20 14\n0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1\n0 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0", "output": "10\n2\n4\n19\n18\n8\n16\n11\n10\n13\n7" }, { "input": "23\n2 1\n3 2\n4 1\n5 1\n6 5\n7 3\n8 2\n9 8\n10 5\n11 6\n12 9\n13 3\n14 11\n15 5\n16 2\n17 3\n18 10\n19 16\n20 14\n21 19\n22 17\n23 7\n0 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1", "output": "8\n2\n23\n13\n17\n9\n4\n11\n20" }, { "input": "1\n0\n0", "output": "0" }, { "input": "10\n1 10\n1 9\n10 2\n10 3\n3 7\n3 8\n9 4\n9 5\n5 6\n1 0 1 1 0 1 0 1 0 1\n0 0 0 0 0 0 0 0 0 0", "output": "6\n1\n10\n2\n7\n5\n6" } ]
1,399,858,941
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
30,412,800
import fileinput odd_change = 0 even_change = 0 class Node: def __init__(self, id, value): self.id = id self.children = [] self.value = value self.odd_change = 0 self.even_change = 0 self.is_odd = True def add_child(self, child): # print child self.children.append(child) def try_flip(self, target): rv = False # print str(self.id) + " " + str(self.even_change) + " " + str(self.odd_change) if not self.is_odd and self.even_change % 2 != 0: self.flip_value() elif self.is_odd and self.odd_change % 2 != 0: self.flip_value() if not (int(self.value) == int(target)): self.flip_value() if not self.is_odd: self.even_change = self.even_change + 1 else: self.odd_change = self.odd_change + 1 rv = True for c in self.children: c.odd_change = self.odd_change c.even_change = self.even_change return rv def flip_value(self): if int(self.value) == 1: self.value = 0 else: self.value = 1 def __repr__(self): # return str(self.id) + " " + str(self.value) + " " + str(self.is_odd) return str(self.value) full_input = fileinput.input() n = int(full_input[0]) nodes = {} for i in range(n): nodes[i + 1] = Node(i + 1, 0) for i in range(n - 1): edge = full_input[i + 1].rstrip().split(' ') # print "here" # print int(edge[0]) parent = int(edge[1]) child = int(edge[0]) nodes[parent].add_child(nodes[child]) if nodes[parent].is_odd: nodes[child].is_odd = False else: nodes[child].is_odd = True orig = full_input[n].rstrip().split(' ') for i in range(n): nodes[i + 1].value = orig[i] # string = bytearray() switches = [] cnt = 0 target = full_input[n+1].rstrip().split(' ') for i in range(n): # print nodes # print str(nodes[i + 1]) + " " + str(target[i]) if nodes[i + 1].try_flip(target[i]): # print i + 1 # print nodes # print "" value = str(i + 1) # string.extend(value) # string.extend("\n") switches.append(i + 1) cnt = cnt + 1 # print nodes print(cnt) # print switches # print "\n".join(str(x) for x in switches) # print(string) for v in switches: print(v)
Title: Xor-tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). Output Specification: In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. Demo Input: ['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n'] Demo Output: ['2\n4\n7\n'] Note: none
```python import fileinput odd_change = 0 even_change = 0 class Node: def __init__(self, id, value): self.id = id self.children = [] self.value = value self.odd_change = 0 self.even_change = 0 self.is_odd = True def add_child(self, child): # print child self.children.append(child) def try_flip(self, target): rv = False # print str(self.id) + " " + str(self.even_change) + " " + str(self.odd_change) if not self.is_odd and self.even_change % 2 != 0: self.flip_value() elif self.is_odd and self.odd_change % 2 != 0: self.flip_value() if not (int(self.value) == int(target)): self.flip_value() if not self.is_odd: self.even_change = self.even_change + 1 else: self.odd_change = self.odd_change + 1 rv = True for c in self.children: c.odd_change = self.odd_change c.even_change = self.even_change return rv def flip_value(self): if int(self.value) == 1: self.value = 0 else: self.value = 1 def __repr__(self): # return str(self.id) + " " + str(self.value) + " " + str(self.is_odd) return str(self.value) full_input = fileinput.input() n = int(full_input[0]) nodes = {} for i in range(n): nodes[i + 1] = Node(i + 1, 0) for i in range(n - 1): edge = full_input[i + 1].rstrip().split(' ') # print "here" # print int(edge[0]) parent = int(edge[1]) child = int(edge[0]) nodes[parent].add_child(nodes[child]) if nodes[parent].is_odd: nodes[child].is_odd = False else: nodes[child].is_odd = True orig = full_input[n].rstrip().split(' ') for i in range(n): nodes[i + 1].value = orig[i] # string = bytearray() switches = [] cnt = 0 target = full_input[n+1].rstrip().split(' ') for i in range(n): # print nodes # print str(nodes[i + 1]) + " " + str(target[i]) if nodes[i + 1].try_flip(target[i]): # print i + 1 # print nodes # print "" value = str(i + 1) # string.extend(value) # string.extend("\n") switches.append(i + 1) cnt = cnt + 1 # print nodes print(cnt) # print switches # print "\n".join(str(x) for x in switches) # print(string) for v in switches: print(v) ```
0
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,519,051,134
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
5,632,000
n = int(input()) a = list(map(int,input().split())) d = [0]*3005 for i in a: d[i-1] = 1 for i in range(1,3002): if d[i]==0: print (i+1) break
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 n = int(input()) a = list(map(int,input().split())) d = [0]*3005 for i in a: d[i-1] = 1 for i in range(1,3002): if d[i]==0: print (i+1) break ```
0
960
A
Check the string
PROGRAMMING
1,200
[ "implementation" ]
null
null
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time. You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
[ "aaabccc\n", "bbacc\n", "aabc\n" ]
[ "YES\n", "NO\n", "YES\n" ]
Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
500
[ { "input": "aaabccc", "output": "YES" }, { "input": "bbacc", "output": "NO" }, { "input": "aabc", "output": "YES" }, { "input": "aabbcc", "output": "YES" }, { "input": "aaacccbb", "output": "NO" }, { "input": "abc", "output": "YES" }, { "input": "acba", "output": "NO" }, { "input": "bbabbc", "output": "NO" }, { "input": "bbbabacca", "output": "NO" }, { "input": "aabcbcaca", "output": "NO" }, { "input": "aaaaabbbbbb", "output": "NO" }, { "input": "c", "output": "NO" }, { "input": "cc", "output": "NO" }, { "input": "bbb", "output": "NO" }, { "input": "bc", "output": "NO" }, { "input": "ccbcc", "output": "NO" }, { "input": "aaa", "output": "NO" }, { "input": "aaccaa", "output": "NO" }, { "input": "a", "output": "NO" }, { "input": "b", "output": "NO" }, { "input": "abca", "output": "NO" }, { "input": "aabbcccc", "output": "NO" }, { "input": "abac", "output": "NO" }, { "input": "abcc", "output": "NO" }, { "input": "abcb", "output": "NO" }, { "input": "aacc", "output": "NO" }, { "input": "aabbaacccc", "output": "NO" }, { "input": "aabb", "output": "NO" }, { "input": "ac", "output": "NO" }, { "input": "abbacc", "output": "NO" }, { "input": "abacc", "output": "NO" }, { "input": "ababc", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "aabaccc", "output": "NO" }, { "input": "bbcc", "output": "NO" }, { "input": "aaabcbc", "output": "NO" }, { "input": "acbbc", "output": "NO" }, { "input": "babc", "output": "NO" }, { "input": "bbbcc", "output": "NO" }, { "input": "bbc", "output": "NO" }, { "input": "abababccc", "output": "NO" }, { "input": "ccbbaa", "output": "NO" } ]
1,694,053,623
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
31
0
strn=str(input()) sortedstrn=sorted(strn) sortedstrn=''.join(sorted(sortedstrn)) a,b,c=0,0,0 # print((sortedstrn)) if strn==str(sortedstrn): a=strn.count('a') b=strn.count('b') c=strn.count('c') # print(a,b,c) if c==a+b or c==a or c==b: print("Yes") else: print("No") else: print("No")
Title: Check the string Time Limit: None seconds Memory Limit: None megabytes Problem Description: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time. You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes). Input Specification: The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. Output Specification: Print "YES" or "NO", according to the condition. Demo Input: ['aaabccc\n', 'bbacc\n', 'aabc\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
```python strn=str(input()) sortedstrn=sorted(strn) sortedstrn=''.join(sorted(sortedstrn)) a,b,c=0,0,0 # print((sortedstrn)) if strn==str(sortedstrn): a=strn.count('a') b=strn.count('b') c=strn.count('c') # print(a,b,c) if c==a+b or c==a or c==b: print("Yes") else: print("No") else: print("No") ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,655,959,087
2,147,483,647
PyPy 3-64
OK
TESTS
3
122
2,048,000
t = int(input()) while t>0: n= int(input()) check = False for i in range(3, 361): if n*i == (i-2)*180: print("YES") check = True break if check == False: print("NO") t-=1
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python t = int(input()) while t>0: n= int(input()) check = False for i in range(3, 361): if n*i == (i-2)*180: print("YES") check = True break if check == False: print("NO") t-=1 ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,679,399,701
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
l = list(map(int, input().split())) print(l[0]//l[2] + 1 + l[1]//l[2] + 1)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python l = list(map(int, input().split())) print(l[0]//l[2] + 1 + l[1]//l[2] + 1) ```
0
816
A
Karen and Morning
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59).
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
[ "05:39\n", "13:31\n", "23:59\n" ]
[ "11\n", "0\n", "1\n" ]
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
500
[ { "input": "05:39", "output": "11" }, { "input": "13:31", "output": "0" }, { "input": "23:59", "output": "1" }, { "input": "13:32", "output": "69" }, { "input": "14:40", "output": "1" }, { "input": "14:00", "output": "41" }, { "input": "05:50", "output": "0" }, { "input": "12:22", "output": "69" }, { "input": "12:34", "output": "57" }, { "input": "05:30", "output": "20" }, { "input": "14:14", "output": "27" }, { "input": "01:10", "output": "0" }, { "input": "02:20", "output": "0" }, { "input": "03:30", "output": "0" }, { "input": "04:40", "output": "0" }, { "input": "10:01", "output": "0" }, { "input": "11:11", "output": "0" }, { "input": "12:21", "output": "0" }, { "input": "14:41", "output": "0" }, { "input": "15:51", "output": "0" }, { "input": "20:02", "output": "0" }, { "input": "21:12", "output": "0" }, { "input": "22:22", "output": "0" }, { "input": "23:32", "output": "0" }, { "input": "01:11", "output": "69" }, { "input": "02:21", "output": "69" }, { "input": "03:31", "output": "69" }, { "input": "04:41", "output": "69" }, { "input": "05:51", "output": "250" }, { "input": "10:02", "output": "69" }, { "input": "11:12", "output": "69" }, { "input": "14:42", "output": "69" }, { "input": "15:52", "output": "250" }, { "input": "20:03", "output": "69" }, { "input": "21:13", "output": "69" }, { "input": "22:23", "output": "69" }, { "input": "23:33", "output": "27" }, { "input": "00:00", "output": "0" }, { "input": "00:01", "output": "69" }, { "input": "22:21", "output": "1" }, { "input": "20:01", "output": "1" }, { "input": "11:10", "output": "1" }, { "input": "06:59", "output": "182" }, { "input": "02:00", "output": "20" }, { "input": "02:19", "output": "1" }, { "input": "17:31", "output": "151" }, { "input": "19:00", "output": "62" }, { "input": "13:37", "output": "64" }, { "input": "07:59", "output": "122" }, { "input": "04:20", "output": "20" }, { "input": "07:10", "output": "171" }, { "input": "06:00", "output": "241" }, { "input": "06:01", "output": "240" }, { "input": "08:15", "output": "106" }, { "input": "06:59", "output": "182" }, { "input": "01:00", "output": "10" }, { "input": "07:00", "output": "181" }, { "input": "06:10", "output": "231" }, { "input": "18:52", "output": "70" }, { "input": "09:59", "output": "2" }, { "input": "19:00", "output": "62" }, { "input": "15:52", "output": "250" }, { "input": "06:50", "output": "191" }, { "input": "00:00", "output": "0" }, { "input": "19:20", "output": "42" }, { "input": "05:51", "output": "250" }, { "input": "06:16", "output": "225" }, { "input": "10:10", "output": "61" }, { "input": "17:11", "output": "171" }, { "input": "18:00", "output": "122" }, { "input": "00:01", "output": "69" }, { "input": "05:04", "output": "46" }, { "input": "16:00", "output": "242" }, { "input": "23:31", "output": "1" }, { "input": "17:25", "output": "157" }, { "input": "23:32", "output": "0" }, { "input": "23:58", "output": "2" }, { "input": "02:21", "output": "69" }, { "input": "01:11", "output": "69" }, { "input": "23:46", "output": "14" }, { "input": "00:09", "output": "61" }, { "input": "09:20", "output": "41" }, { "input": "05:59", "output": "242" }, { "input": "18:59", "output": "63" }, { "input": "02:02", "output": "18" }, { "input": "00:30", "output": "40" }, { "input": "05:54", "output": "247" }, { "input": "19:59", "output": "3" }, { "input": "16:59", "output": "183" }, { "input": "17:51", "output": "131" }, { "input": "09:30", "output": "31" }, { "input": "10:01", "output": "0" }, { "input": "16:55", "output": "187" }, { "input": "20:02", "output": "0" }, { "input": "16:12", "output": "230" }, { "input": "20:00", "output": "2" }, { "input": "01:01", "output": "9" }, { "input": "23:01", "output": "31" }, { "input": "06:05", "output": "236" }, { "input": "19:19", "output": "43" }, { "input": "17:00", "output": "182" }, { "input": "07:50", "output": "131" }, { "input": "21:20", "output": "62" }, { "input": "23:23", "output": "9" }, { "input": "19:30", "output": "32" }, { "input": "00:59", "output": "11" }, { "input": "22:59", "output": "33" }, { "input": "18:18", "output": "104" }, { "input": "17:46", "output": "136" }, { "input": "07:30", "output": "151" }, { "input": "17:16", "output": "166" }, { "input": "06:06", "output": "235" }, { "input": "23:30", "output": "2" }, { "input": "05:57", "output": "244" }, { "input": "19:46", "output": "16" }, { "input": "11:10", "output": "1" }, { "input": "17:07", "output": "175" }, { "input": "18:53", "output": "69" }, { "input": "07:06", "output": "175" }, { "input": "17:50", "output": "132" }, { "input": "09:15", "output": "46" }, { "input": "09:55", "output": "6" }, { "input": "20:05", "output": "67" }, { "input": "22:55", "output": "37" }, { "input": "10:00", "output": "1" }, { "input": "07:55", "output": "126" }, { "input": "07:40", "output": "141" }, { "input": "19:08", "output": "54" }, { "input": "23:24", "output": "8" }, { "input": "16:15", "output": "227" }, { "input": "07:20", "output": "161" }, { "input": "23:10", "output": "22" }, { "input": "06:51", "output": "190" }, { "input": "16:30", "output": "212" }, { "input": "17:54", "output": "128" }, { "input": "07:07", "output": "174" }, { "input": "08:01", "output": "120" }, { "input": "09:58", "output": "3" }, { "input": "18:03", "output": "119" }, { "input": "07:59", "output": "122" }, { "input": "05:55", "output": "246" }, { "input": "07:39", "output": "142" }, { "input": "05:52", "output": "249" }, { "input": "12:02", "output": "19" }, { "input": "08:59", "output": "62" }, { "input": "09:21", "output": "40" }, { "input": "16:04", "output": "238" }, { "input": "04:00", "output": "40" }, { "input": "18:21", "output": "101" }, { "input": "09:13", "output": "48" }, { "input": "17:20", "output": "162" }, { "input": "06:15", "output": "226" }, { "input": "19:21", "output": "41" }, { "input": "16:02", "output": "240" }, { "input": "15:59", "output": "243" }, { "input": "06:07", "output": "234" }, { "input": "08:08", "output": "113" }, { "input": "09:09", "output": "52" }, { "input": "02:19", "output": "1" }, { "input": "21:59", "output": "23" } ]
1,593,292,381
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
6,656,000
h,m = input().split(":") r = h[::-1] ans = 0 if m < r: ans = int(r) - int(m) else: if m > r: ans = 60 - int(m) + int(r) else: ans = 0 print(ans)
Title: Karen and Morning Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome? Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50. Input Specification: The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59). Output Specification: Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome. Demo Input: ['05:39\n', '13:31\n', '23:59\n'] Demo Output: ['11\n', '0\n', '1\n'] Note: In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
```python h,m = input().split(":") r = h[::-1] ans = 0 if m < r: ans = int(r) - int(m) else: if m > r: ans = 60 - int(m) + int(r) else: ans = 0 print(ans) ```
0
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,577,179,980
2,147,483,647
Python 3
OK
TESTS
45
218
0
import math a,b,c=map(int,input().split());cnt=int(0); while True: if cnt==0: cnt=1; if math.gcd(a,c)<=c: c-=math.gcd(a,c) else: print(1) exit(0) else: cnt=0 if(math.gcd(b,c)<=c): c-=math.gcd(b,c) else: print(0) exit(0)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python import math a,b,c=map(int,input().split());cnt=int(0); while True: if cnt==0: cnt=1; if math.gcd(a,c)<=c: c-=math.gcd(a,c) else: print(1) exit(0) else: cnt=0 if(math.gcd(b,c)<=c): c-=math.gcd(b,c) else: print(0) exit(0) ```
3
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,612,066,154
2,147,483,647
PyPy 3
OK
TESTS
55
109
0
s=input() a="Danil" b="Olya" c="Ann" d="Nikita" e="Slava" j=s.count(a)+s.count(b)+s.count(c)+s.count(d)+s.count(e) if j==1: print("YES") else: print("NO")
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input Specification: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Output Specification: Print "YES", if problem is from this contest, and "NO" otherwise. Demo Input: ['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n'] Demo Output: ['NO', 'YES', 'NO'] Note: none
```python s=input() a="Danil" b="Olya" c="Ann" d="Nikita" e="Slava" j=s.count(a)+s.count(b)+s.count(c)+s.count(d)+s.count(e) if j==1: print("YES") else: print("NO") ```
3
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,511,377,255
2,147,483,647
PyPy 3
OK
TESTS
96
108
307,200
n,k=map(int,input().split()) x=10**k if(n>x): big=n small=x else: big=x small=n mod=-1 while(mod!=0): mod=big%small big=small if(mod!=0): small=mod print(small*int(n/small)*int(x/small))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python n,k=map(int,input().split()) x=10**k if(n>x): big=n small=x else: big=x small=n mod=-1 while(mod!=0): mod=big%small big=small if(mod!=0): small=mod print(small*int(n/small)*int(x/small)) ```
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,415,381,744
2,147,483,647
Python 3
OK
TESTS
20
62
0
import sys import math k, d = [int(x) for x in (sys.stdin.readline()).split()] if(d == 0 and k == 1): print(0) exit() elif(d == 0): print("No solution") exit() t = [] for i in range(k - 1): t.append(str(9)) t.append(str(d)) print("".join(t))
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 import sys import math k, d = [int(x) for x in (sys.stdin.readline()).split()] if(d == 0 and k == 1): print(0) exit() elif(d == 0): print("No solution") exit() t = [] for i in range(k - 1): t.append(str(9)) t.append(str(d)) print("".join(t)) ```
3
244
B
Undoubtedly Lucky Numbers
PROGRAMMING
1,600
[ "bitmasks", "brute force", "dfs and similar" ]
null
null
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==<=4, and *y*<==<=7, then numbers 47, 744, 4 are lucky. Let's call a positive integer *a* undoubtedly lucky, if there are such digits *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=9), that the decimal representation of number *a* (without leading zeroes) contains only digits *x* and *y*. Polycarpus has integer *n*. He wants to know how many positive integers that do not exceed *n*, are undoubtedly lucky. Help him, count this number.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Polycarpus's number.
Print a single integer that says, how many positive integers that do not exceed *n* are undoubtedly lucky.
[ "10\n", "123\n" ]
[ "10\n", "113\n" ]
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky. In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
1,000
[ { "input": "10", "output": "10" }, { "input": "123", "output": "113" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "1000", "output": "352" }, { "input": "1000000000", "output": "40744" }, { "input": "999999999", "output": "40743" }, { "input": "999999998", "output": "40742" }, { "input": "999999997", "output": "40741" }, { "input": "909090901", "output": "38532" }, { "input": "142498040", "output": "21671" }, { "input": "603356456", "output": "31623" }, { "input": "64214872", "output": "15759" }, { "input": "820040584", "output": "36407" }, { "input": "442198", "output": "3071" }, { "input": "784262", "output": "4079" }, { "input": "642678", "output": "3615" }, { "input": "468390", "output": "3223" }, { "input": "326806", "output": "2759" }, { "input": "940", "output": "331" }, { "input": "356", "output": "175" }, { "input": "68", "output": "68" }, { "input": "132", "output": "114" }, { "input": "72", "output": "72" }, { "input": "89", "output": "89" }, { "input": "1", "output": "1" }, { "input": "3", "output": "3" }, { "input": "4", "output": "4" }, { "input": "5", "output": "5" }, { "input": "6", "output": "6" }, { "input": "7", "output": "7" }, { "input": "8", "output": "8" }, { "input": "9", "output": "9" }, { "input": "101", "output": "101" }, { "input": "102", "output": "101" } ]
1,683,990,738
2,147,483,647
Python 3
OK
TESTS
35
530
0
n=int(input()) g=len(str(n)) c=0 def sol(k,l): global c if k and int(k)>n: return if len(set(k))>2: return if l>g: return if k: c+=1 for i in range(0 if k else 1,10): sol(k+str(i),l+1) sol("",0) print(c)
Title: Undoubtedly Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==<=4, and *y*<==<=7, then numbers 47, 744, 4 are lucky. Let's call a positive integer *a* undoubtedly lucky, if there are such digits *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=9), that the decimal representation of number *a* (without leading zeroes) contains only digits *x* and *y*. Polycarpus has integer *n*. He wants to know how many positive integers that do not exceed *n*, are undoubtedly lucky. Help him, count this number. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Polycarpus's number. Output Specification: Print a single integer that says, how many positive integers that do not exceed *n* are undoubtedly lucky. Demo Input: ['10\n', '123\n'] Demo Output: ['10\n', '113\n'] Note: In the first test sample all numbers that do not exceed 10 are undoubtedly lucky. In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
```python n=int(input()) g=len(str(n)) c=0 def sol(k,l): global c if k and int(k)>n: return if len(set(k))>2: return if l>g: return if k: c+=1 for i in range(0 if k else 1,10): sol(k+str(i),l+1) sol("",0) print(c) ```
3
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, 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.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174", "output": "9" }, { "input": "12883340691714056185860211260984431382156326935244", "output": "424" }, { "input": "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "1528" }, { "input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119521202062222947560634301788787748428236988789594458520867663257476744168528121470923031438015546006185059454402637036376247785881323277542968298682307854655591317046086531554595892680980142608", "output": "30826" }, { "input": "123456", "output": "7" }, { "input": "4", "output": "1" }, { "input": "123", "output": "1" } ]
1,613,754,121
2,147,483,647
PyPy 3
OK
TESTS
22
202
10,854,400
s = input() s1 = list(s) count = 0 count += s1.count('0') count += s1.count('4') count += s1.count('8') for i in range(len(s)-1): if(int(''.join(s[i:i+2]))%4==0): count += i+1 print(count)
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. Output Specification: Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, 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: ['124\n', '04\n', '5810438174\n'] Demo Output: ['4\n', '3\n', '9\n'] Note: none
```python s = input() s1 = list(s) count = 0 count += s1.count('0') count += s1.count('4') count += s1.count('8') for i in range(len(s)-1): if(int(''.join(s[i:i+2]))%4==0): count += i+1 print(count) ```
3
596
D
Wilbur and Trees
PROGRAMMING
2,300
[ "dp", "math", "probabilities", "sortings" ]
null
null
Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are *n* trees located at various positions on a line. Tree *i* is located at position *x**i*. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height *h*. Due to the wind, when a tree is cut down, it either falls left with probability *p*, or falls right with probability 1<=-<=*p*. If a tree hits another tree while falling, that tree will fall in the same direction as the tree that hit it. A tree can hit another tree only if the distance between them is strictly less than *h*. For example, imagine there are 4 trees located at positions 1, 3, 5 and 8, while *h*<==<=3 and the tree at position 1 falls right. It hits the tree at position 3 and it starts to fall too. In it's turn it hits the tree at position 5 and it also starts to fall. The distance between 8 and 5 is exactly 3, so the tree at position 8 will not fall. As long as there are still trees standing, Wilbur will select either the leftmost standing tree with probability 0.5 or the rightmost standing tree with probability 0.5. Selected tree is then cut down. If there is only one tree remaining, Wilbur always selects it. As the ground is covered with grass, Wilbur wants to know the expected total length of the ground covered with fallen trees after he cuts them all down because he is concerned about his grass-eating cow friends. Please help Wilbur.
The first line of the input contains two integers, *n* (1<=≤<=*n*<=≤<=2000) and *h* (1<=≤<=*h*<=≤<=108) and a real number *p* (0<=≤<=*p*<=≤<=1), given with no more than six decimal places. The second line of the input contains *n* integers, *x*1,<=*x*2,<=...,<=*x**n* (<=-<=108<=≤<=*x**i*<=≤<=108) in no particular order.
Print a single real number — the expected total length of the ground covered by trees when they have all fallen down. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "2 2 0.500000\n1 2\n", "4 3 0.4\n4 3 1 2\n" ]
[ "3.250000000\n", "6.631200000\n" ]
Consider the first example, we have 2 trees with height 2. 1. Both trees falls left. This can either happen with the right tree falling left first, which has <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d0f634778b5b369e93c5e4521921161fd08259cb.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability (also knocking down the left tree), or the left tree can fall left and then the right tree can fall left, which has <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/641d3274da41b4a98609d2f4fad1fa35c9a8a0a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability. Total probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ef2d54b84025327b541b1c00210b659d1ed21135.png" style="max-width: 100.0%;max-height: 100.0%;"/>. 2. Both trees fall right. This is analogous to (1), so the probability of this happening is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/43481774386d410a1bf5213c8638987fd86ac23a.png" style="max-width: 100.0%;max-height: 100.0%;"/>. 3. The left tree fall left and the right tree falls right. This is the only remaining scenario so it must have <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0166ed98b57be8fa0496443c205adee6e32c4f0b.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability. Cases 1 and 2 lead to a total of 3 units of ground covered, while case 3 leads to a total of 4 units of ground covered. Thus, the expected value is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/558a70d9a0e95f0b97db05aac6ef64a78d8e80fb.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
2,250
[]
1,689,633,920
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689633920.0478349")# 1689633920.047856
Title: Wilbur and Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down. There are *n* trees located at various positions on a line. Tree *i* is located at position *x**i*. All the given positions of the trees are distinct. The trees are equal, i.e. each tree has height *h*. Due to the wind, when a tree is cut down, it either falls left with probability *p*, or falls right with probability 1<=-<=*p*. If a tree hits another tree while falling, that tree will fall in the same direction as the tree that hit it. A tree can hit another tree only if the distance between them is strictly less than *h*. For example, imagine there are 4 trees located at positions 1, 3, 5 and 8, while *h*<==<=3 and the tree at position 1 falls right. It hits the tree at position 3 and it starts to fall too. In it's turn it hits the tree at position 5 and it also starts to fall. The distance between 8 and 5 is exactly 3, so the tree at position 8 will not fall. As long as there are still trees standing, Wilbur will select either the leftmost standing tree with probability 0.5 or the rightmost standing tree with probability 0.5. Selected tree is then cut down. If there is only one tree remaining, Wilbur always selects it. As the ground is covered with grass, Wilbur wants to know the expected total length of the ground covered with fallen trees after he cuts them all down because he is concerned about his grass-eating cow friends. Please help Wilbur. Input Specification: The first line of the input contains two integers, *n* (1<=≤<=*n*<=≤<=2000) and *h* (1<=≤<=*h*<=≤<=108) and a real number *p* (0<=≤<=*p*<=≤<=1), given with no more than six decimal places. The second line of the input contains *n* integers, *x*1,<=*x*2,<=...,<=*x**n* (<=-<=108<=≤<=*x**i*<=≤<=108) in no particular order. Output Specification: Print a single real number — the expected total length of the ground covered by trees when they have all fallen down. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['2 2 0.500000\n1 2\n', '4 3 0.4\n4 3 1 2\n'] Demo Output: ['3.250000000\n', '6.631200000\n'] Note: Consider the first example, we have 2 trees with height 2. 1. Both trees falls left. This can either happen with the right tree falling left first, which has <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d0f634778b5b369e93c5e4521921161fd08259cb.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability (also knocking down the left tree), or the left tree can fall left and then the right tree can fall left, which has <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/641d3274da41b4a98609d2f4fad1fa35c9a8a0a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability. Total probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ef2d54b84025327b541b1c00210b659d1ed21135.png" style="max-width: 100.0%;max-height: 100.0%;"/>. 2. Both trees fall right. This is analogous to (1), so the probability of this happening is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/43481774386d410a1bf5213c8638987fd86ac23a.png" style="max-width: 100.0%;max-height: 100.0%;"/>. 3. The left tree fall left and the right tree falls right. This is the only remaining scenario so it must have <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0166ed98b57be8fa0496443c205adee6e32c4f0b.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability. Cases 1 and 2 lead to a total of 3 units of ground covered, while case 3 leads to a total of 4 units of ground covered. Thus, the expected value is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/558a70d9a0e95f0b97db05aac6ef64a78d8e80fb.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python print("_RANDOM_GUESS_1689633920.0478349")# 1689633920.047856 ```
0
711
A
Bus to Udayland
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus. Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row. Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output). If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line. If there are multiple solutions, you may print any of them.
[ "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n", "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n" ]
[ "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "NO\n", "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n" ]
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
500
[ { "input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX" }, { "input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO" }, { "input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO" }, { "input": "1\nXO|OX", "output": "NO" }, { "input": "1\nOO|OO", "output": "YES\n++|OO" }, { "input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO", "output": "NO" }, { "input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX", "output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX" }, { "input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX", "output": "NO" }, { "input": "1\nOO|XX", "output": "YES\n++|XX" }, { "input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX", "output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX" }, { "input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO", "output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++" }, { "input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO" }, { "input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX", "output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX" } ]
1,598,276,458
2,147,483,647
Python 3
OK
TESTS
71
109
6,963,200
n = int(input()) result = [] z = 0 for i in range(n): place = input() if place.count('OO') > 0: if z == 0: result.append(place.replace('OO', '++', 1)) z += 1 else: result.append(place) else: result.append(place) if z == 1: print('YES') for elem in result: print(elem, end="\n") else: print('NO')
Title: Bus to Udayland Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus. Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row. Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. Output Specification: If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output). If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line. If there are multiple solutions, you may print any of them. Demo Input: ['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n'] Demo Output: ['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n'] Note: Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
```python n = int(input()) result = [] z = 0 for i in range(n): place = input() if place.count('OO') > 0: if z == 0: result.append(place.replace('OO', '++', 1)) z += 1 else: result.append(place) else: result.append(place) if z == 1: print('YES') for elem in result: print(elem, end="\n") else: print('NO') ```
3
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808", "output": "7" }, { "input": "1\n487 550", "output": "0" }, { "input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676", "output": "0" }, { "input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136", "output": "8" }, { "input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188", "output": "9" }, { "input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191", "output": "5" }, { "input": "4\n1 0\n2 0\n1 1\n1 -1", "output": "0" } ]
1,604,874,159
2,147,483,647
Python 3
OK
TESTS
26
280
307,200
n = int(input()) lst = [] for i in range(n): lst.append(list(map(int, input().split()))) counter = 0 for i in range(n): up, low, left, right = False, False, False, False for j in range(n): if lst[i][0] > lst[j][0] and lst[i][1] == lst[j][1]: right = True if lst[i][0] < lst[j][0] and lst[i][1] == lst[j][1]: left = True if lst[i][0] == lst[j][0] and lst[i][1] < lst[j][1]: low = True if lst[i][0] == lst[j][0] and lst[i][1] > lst[j][1]: up = True if up and low and right and left: counter += 1 break print(counter)
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input Specification: The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Specification: Print the only number — the number of supercentral points of the given set. Demo Input: ['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
```python n = int(input()) lst = [] for i in range(n): lst.append(list(map(int, input().split()))) counter = 0 for i in range(n): up, low, left, right = False, False, False, False for j in range(n): if lst[i][0] > lst[j][0] and lst[i][1] == lst[j][1]: right = True if lst[i][0] < lst[j][0] and lst[i][1] == lst[j][1]: left = True if lst[i][0] == lst[j][0] and lst[i][1] < lst[j][1]: low = True if lst[i][0] == lst[j][0] and lst[i][1] > lst[j][1]: up = True if up and low and right and left: counter += 1 break print(counter) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him?
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input": "6 11", "output": "6 2" }, { "input": "10 40", "output": "10 15" }, { "input": "11 56", "output": "11 22" }, { "input": "34 30", "output": "30 2" }, { "input": "33 33", "output": "33 0" }, { "input": "100 45", "output": "45 27" }, { "input": "100 23", "output": "23 38" }, { "input": "45 12", "output": "12 16" }, { "input": "1 1", "output": "1 0" }, { "input": "1 100", "output": "1 49" }, { "input": "100 1", "output": "1 49" }, { "input": "68 59", "output": "59 4" }, { "input": "45 99", "output": "45 27" }, { "input": "99 100", "output": "99 0" }, { "input": "100 98", "output": "98 1" }, { "input": "59 12", "output": "12 23" }, { "input": "86 4", "output": "4 41" }, { "input": "68 21", "output": "21 23" }, { "input": "100 11", "output": "11 44" }, { "input": "100 10", "output": "10 45" }, { "input": "15 45", "output": "15 15" }, { "input": "11 32", "output": "11 10" }, { "input": "34 96", "output": "34 31" }, { "input": "89 89", "output": "89 0" } ]
1,664,397,157
2,147,483,647
Python 3
OK
TESTS
30
46
0
strs = input() a,b = tuple(strs.split()) a,b = int(a), int(b) if a == b: fashion = a onecolor = 0 else: if a > b: fashion = b onecolor = (a-b)//2 else: fashion = a onecolor = (b-a)//2 print("{} {}".format(fashion,onecolor))
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input Specification: The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. Output Specification: Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Demo Input: ['3 1\n', '2 3\n', '7 3\n'] Demo Output: ['1 1\n', '2 0\n', '3 2\n'] Note: In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
```python strs = input() a,b = tuple(strs.split()) a,b = int(a), int(b) if a == b: fashion = a onecolor = 0 else: if a > b: fashion = b onecolor = (a-b)//2 else: fashion = a onecolor = (b-a)//2 print("{} {}".format(fashion,onecolor)) ```
3
670
A
Holidays
PROGRAMMING
900
[ "brute force", "constructive algorithms", "greedy", "math" ]
null
null
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
[ "14\n", "2\n" ]
[ "4 4\n", "0 2\n" ]
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
500
[ { "input": "14", "output": "4 4" }, { "input": "2", "output": "0 2" }, { "input": "1", "output": "0 1" }, { "input": "3", "output": "0 2" }, { "input": "4", "output": "0 2" }, { "input": "5", "output": "0 2" }, { "input": "6", "output": "1 2" }, { "input": "7", "output": "2 2" }, { "input": "8", "output": "2 3" }, { "input": "9", "output": "2 4" }, { "input": "10", "output": "2 4" }, { "input": "11", "output": "2 4" }, { "input": "12", "output": "2 4" }, { "input": "13", "output": "3 4" }, { "input": "1000000", "output": "285714 285715" }, { "input": "16", "output": "4 6" }, { "input": "17", "output": "4 6" }, { "input": "18", "output": "4 6" }, { "input": "19", "output": "4 6" }, { "input": "20", "output": "5 6" }, { "input": "21", "output": "6 6" }, { "input": "22", "output": "6 7" }, { "input": "23", "output": "6 8" }, { "input": "24", "output": "6 8" }, { "input": "25", "output": "6 8" }, { "input": "26", "output": "6 8" }, { "input": "27", "output": "7 8" }, { "input": "28", "output": "8 8" }, { "input": "29", "output": "8 9" }, { "input": "30", "output": "8 10" }, { "input": "100", "output": "28 30" }, { "input": "99", "output": "28 29" }, { "input": "98", "output": "28 28" }, { "input": "97", "output": "27 28" }, { "input": "96", "output": "26 28" }, { "input": "95", "output": "26 28" }, { "input": "94", "output": "26 28" }, { "input": "93", "output": "26 28" }, { "input": "92", "output": "26 27" }, { "input": "91", "output": "26 26" }, { "input": "90", "output": "25 26" }, { "input": "89", "output": "24 26" }, { "input": "88", "output": "24 26" }, { "input": "87", "output": "24 26" }, { "input": "86", "output": "24 26" }, { "input": "85", "output": "24 25" }, { "input": "84", "output": "24 24" }, { "input": "83", "output": "23 24" }, { "input": "82", "output": "22 24" }, { "input": "81", "output": "22 24" }, { "input": "80", "output": "22 24" }, { "input": "1000", "output": "285 286" }, { "input": "999", "output": "284 286" }, { "input": "998", "output": "284 286" }, { "input": "997", "output": "284 286" }, { "input": "996", "output": "284 286" }, { "input": "995", "output": "284 285" }, { "input": "994", "output": "284 284" }, { "input": "993", "output": "283 284" }, { "input": "992", "output": "282 284" }, { "input": "991", "output": "282 284" }, { "input": "990", "output": "282 284" }, { "input": "989", "output": "282 284" }, { "input": "988", "output": "282 283" }, { "input": "987", "output": "282 282" }, { "input": "986", "output": "281 282" }, { "input": "985", "output": "280 282" }, { "input": "984", "output": "280 282" }, { "input": "983", "output": "280 282" }, { "input": "982", "output": "280 282" }, { "input": "981", "output": "280 281" }, { "input": "980", "output": "280 280" }, { "input": "10000", "output": "2856 2858" }, { "input": "9999", "output": "2856 2858" }, { "input": "9998", "output": "2856 2858" }, { "input": "9997", "output": "2856 2857" }, { "input": "9996", "output": "2856 2856" }, { "input": "9995", "output": "2855 2856" }, { "input": "9994", "output": "2854 2856" }, { "input": "9993", "output": "2854 2856" }, { "input": "9992", "output": "2854 2856" }, { "input": "9991", "output": "2854 2856" }, { "input": "9990", "output": "2854 2855" }, { "input": "9989", "output": "2854 2854" }, { "input": "9988", "output": "2853 2854" }, { "input": "9987", "output": "2852 2854" }, { "input": "9986", "output": "2852 2854" }, { "input": "9985", "output": "2852 2854" }, { "input": "9984", "output": "2852 2854" }, { "input": "9983", "output": "2852 2853" }, { "input": "9982", "output": "2852 2852" }, { "input": "9981", "output": "2851 2852" }, { "input": "9980", "output": "2850 2852" }, { "input": "100000", "output": "28570 28572" }, { "input": "99999", "output": "28570 28572" }, { "input": "99998", "output": "28570 28572" }, { "input": "99997", "output": "28570 28572" }, { "input": "99996", "output": "28570 28571" }, { "input": "99995", "output": "28570 28570" }, { "input": "99994", "output": "28569 28570" }, { "input": "99993", "output": "28568 28570" }, { "input": "99992", "output": "28568 28570" }, { "input": "99991", "output": "28568 28570" }, { "input": "99990", "output": "28568 28570" }, { "input": "99989", "output": "28568 28569" }, { "input": "99988", "output": "28568 28568" }, { "input": "99987", "output": "28567 28568" }, { "input": "99986", "output": "28566 28568" }, { "input": "99985", "output": "28566 28568" }, { "input": "99984", "output": "28566 28568" }, { "input": "99983", "output": "28566 28568" }, { "input": "99982", "output": "28566 28567" }, { "input": "99981", "output": "28566 28566" }, { "input": "99980", "output": "28565 28566" }, { "input": "999999", "output": "285714 285714" }, { "input": "999998", "output": "285713 285714" }, { "input": "999997", "output": "285712 285714" }, { "input": "999996", "output": "285712 285714" }, { "input": "999995", "output": "285712 285714" }, { "input": "999994", "output": "285712 285714" }, { "input": "999993", "output": "285712 285713" }, { "input": "999992", "output": "285712 285712" }, { "input": "999991", "output": "285711 285712" }, { "input": "999990", "output": "285710 285712" }, { "input": "999989", "output": "285710 285712" }, { "input": "999988", "output": "285710 285712" }, { "input": "999987", "output": "285710 285712" }, { "input": "999986", "output": "285710 285711" }, { "input": "999985", "output": "285710 285710" }, { "input": "999984", "output": "285709 285710" }, { "input": "999983", "output": "285708 285710" }, { "input": "999982", "output": "285708 285710" }, { "input": "999981", "output": "285708 285710" }, { "input": "999980", "output": "285708 285710" }, { "input": "234123", "output": "66892 66893" }, { "input": "234122", "output": "66892 66892" }, { "input": "234121", "output": "66891 66892" }, { "input": "234120", "output": "66890 66892" }, { "input": "234119", "output": "66890 66892" }, { "input": "234118", "output": "66890 66892" }, { "input": "234117", "output": "66890 66892" }, { "input": "234116", "output": "66890 66891" }, { "input": "234115", "output": "66890 66890" }, { "input": "234114", "output": "66889 66890" }, { "input": "234113", "output": "66888 66890" }, { "input": "234112", "output": "66888 66890" }, { "input": "234111", "output": "66888 66890" }, { "input": "234110", "output": "66888 66890" }, { "input": "234109", "output": "66888 66889" }, { "input": "234108", "output": "66888 66888" }, { "input": "234107", "output": "66887 66888" }, { "input": "234106", "output": "66886 66888" }, { "input": "234105", "output": "66886 66888" }, { "input": "234104", "output": "66886 66888" }, { "input": "234103", "output": "66886 66888" }, { "input": "868531", "output": "248151 248152" }, { "input": "868530", "output": "248150 248152" }, { "input": "868529", "output": "248150 248152" }, { "input": "868528", "output": "248150 248152" }, { "input": "868527", "output": "248150 248152" }, { "input": "868526", "output": "248150 248151" }, { "input": "868525", "output": "248150 248150" }, { "input": "868524", "output": "248149 248150" }, { "input": "868523", "output": "248148 248150" }, { "input": "868522", "output": "248148 248150" }, { "input": "868521", "output": "248148 248150" }, { "input": "868520", "output": "248148 248150" }, { "input": "868519", "output": "248148 248149" }, { "input": "868518", "output": "248148 248148" }, { "input": "868517", "output": "248147 248148" }, { "input": "868516", "output": "248146 248148" }, { "input": "868515", "output": "248146 248148" }, { "input": "868514", "output": "248146 248148" }, { "input": "868513", "output": "248146 248148" }, { "input": "868512", "output": "248146 248147" }, { "input": "868511", "output": "248146 248146" }, { "input": "123413", "output": "35260 35262" }, { "input": "123412", "output": "35260 35262" }, { "input": "123411", "output": "35260 35261" }, { "input": "123410", "output": "35260 35260" }, { "input": "123409", "output": "35259 35260" }, { "input": "123408", "output": "35258 35260" }, { "input": "123407", "output": "35258 35260" }, { "input": "123406", "output": "35258 35260" }, { "input": "123405", "output": "35258 35260" }, { "input": "123404", "output": "35258 35259" }, { "input": "123403", "output": "35258 35258" }, { "input": "123402", "output": "35257 35258" }, { "input": "123401", "output": "35256 35258" }, { "input": "123400", "output": "35256 35258" }, { "input": "123399", "output": "35256 35258" }, { "input": "123398", "output": "35256 35258" }, { "input": "123397", "output": "35256 35257" }, { "input": "123396", "output": "35256 35256" }, { "input": "123395", "output": "35255 35256" }, { "input": "123394", "output": "35254 35256" }, { "input": "123393", "output": "35254 35256" }, { "input": "15", "output": "4 5" } ]
1,695,392,297
2,147,483,647
PyPy 3-64
OK
TESTS
198
77
1,638,400
def calculate_days_off(n, start_day): days_off = 0 current_day = start_day for i in range(1, n+1): if current_day == 6 or current_day == 7: # Saturday or Sunday days_off += 1 current_day = (current_day % 7) + 1 return days_off n = int(input()) min_start_day = 1 max_start_day = 6 min_days_off = calculate_days_off(n, min_start_day) max_days_off = calculate_days_off(n, max_start_day) print(min_days_off, max_days_off)
Title: Holidays Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. Output Specification: Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. Demo Input: ['14\n', '2\n'] Demo Output: ['4 4\n', '0 2\n'] Note: In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off . In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
```python def calculate_days_off(n, start_day): days_off = 0 current_day = start_day for i in range(1, n+1): if current_day == 6 or current_day == 7: # Saturday or Sunday days_off += 1 current_day = (current_day % 7) + 1 return days_off n = int(input()) min_start_day = 1 max_start_day = 6 min_days_off = calculate_days_off(n, min_start_day) max_days_off = calculate_days_off(n, max_start_day) print(min_days_off, max_days_off) ```
3
44
E
Anfisa the Monkey
PROGRAMMING
1,400
[ "dp" ]
E. Anfisa the Monkey
2
256
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble human speech more. Help Anfisa.
The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols.
Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print "No solution" (without quotes).
[ "3 2 5\nabrakadabra\n", "4 1 2\nabrakadabra\n" ]
[ "ab\nrakad\nabra\n", "No solution\n" ]
none
0
[ { "input": "3 2 5\nabrakadabra", "output": "abra\nkada\nbra" }, { "input": "4 1 2\nabrakadabra", "output": "No solution" }, { "input": "3 1 2\nvgnfpo", "output": "vg\nnf\npo" }, { "input": "5 3 4\nvrrdnhazvexzjfv", "output": "vrr\ndnh\nazv\nexz\njfv" }, { "input": "10 12 15\nctxgddcfdtllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmp", "output": "ctxgddcfdtllm\npuxsjkubuqpld\nznulsilueakbw\nwlzgeyudyrjac\nhmitfdcgyzszo\nejphrubpxzpdt\ngexaqpxgnoxwf\njoikljudnouci\nrussumyhetfwg\naoxfbugfiyjmp" }, { "input": "10 20 30\nbvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpsh", "output": "bvdqvlxiyogiyimdlwdy\nxsummjgqxaxsucfeuegl\neetybsylpnepkqzbutib\ntlgqrbjbwqnvkysxftms\njqkczoploxoqfuwyrufz\nwwsxpcqfuckjainpphpb\nvvtllgkljnnoibsvwnxv\naksxjrffakpoxwkhjjje\nmqatbfkmmlmjhhroetlq\nvfaumctbicqkuxaabpsh" }, { "input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidf", "output": "olahgjusovchbowjxtw\nzvjakrktyjqcgkqmcxk\nnjchzxcvbnkbakwnxdo\nuebomyhjsrfsicmzsgd\nweabbuipbzrhuqfpyny\nbaohzquqbbsqpoaskcc\nszzsmnfleevtasmjuwq\ngcqtvysohvyutqipnvu\nhjumwwyytkeuebbncxs\nnpavwdkoxyycqrhcidf" }, { "input": "30 3 6\nebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqke", "output": "ebd\ngac\nrmh\nfld\nirw\nrcf\nadu\nrng\near\nrfy\njiq\nkmf\nqmg\nzpn\nzcp\nprk\njye\nuup\npzv\nmib\nzzw\nyou\nhxc\nlcg\nqtj\nhjm\nucy\npqn\nhda\nqke" }, { "input": "200 1 200\nlycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqg", "output": "l\ny\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz..." }, { "input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrc", "output": "aro\nnay\njut\njdh\njce\nlge\nxga\nlny\niru\nevj\nelv\ncvz\naih\ngbw\nwrc" }, { "input": "7 3 4\nweoghhroclwslkfcsszplh", "output": "weog\nhhr\nocl\nwsl\nkfc\nssz\nplh" }, { "input": "12 2 5\nozgscnrddhejkhllokmafxcuorxryhvqnkikauclhfbddfoxl", "output": "ozgsc\nnrdd\nhejk\nhllo\nkmaf\nxcuo\nrxry\nhvqn\nkika\nuclh\nfbdd\nfoxl" }, { "input": "3 1 2\nfpos", "output": "fp\no\ns" }, { "input": "5 3 4\nvrrdnhazvexzjfvs", "output": "vrrd\nnha\nzve\nxzj\nfvs" }, { "input": "10 12 15\nllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmpm", "output": "llmpuxsjkubuq\npldznulsilue\nakbwwlzgeyud\nyrjachmitfdc\ngyzszoejphru\nbpxzpdtgexaq\npxgnoxwfjoik\nljudnoucirus\nsumyhetfwgao\nxfbugfiyjmpm" }, { "input": "10 20 30\nvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpshu", "output": "vdqvlxiyogiyimdlwdyx\nsummjgqxaxsucfeuegle\netybsylpnepkqzbutibt\nlgqrbjbwqnvkysxftmsj\nqkczoploxoqfuwyrufzw\nwsxpcqfuckjainpphpbv\nvtllgkljnnoibsvwnxva\nksxjrffakpoxwkhjjjem\nqatbfkmmlmjhhroetlqv\nfaumctbicqkuxaabpshu" }, { "input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidfd", "output": "olahgjusovchbowjxtwz\nvjakrktyjqcgkqmcxkn\njchzxcvbnkbakwnxdou\nebomyhjsrfsicmzsgdw\neabbuipbzrhuqfpynyb\naohzquqbbsqpoaskccs\nzzsmnfleevtasmjuwqg\ncqtvysohvyutqipnvuh\njumwwyytkeuebbncxsn\npavwdkoxyycqrhcidfd" }, { "input": "30 3 6\nhstvoyuksbbsbgatemzmvbhbjdmnzpluefgzlcqgfsmkdydadsonaryzskleebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqkea", "output": "hstvoy\nuksbb\nsbgat\nemzmv\nbhbjd\nmnzpl\nuefgz\nlcqgf\nsmkdy\ndadso\nnaryz\nsklee\nbdgac\nrmhfl\ndirwr\ncfadu\nrngea\nrrfyj\niqkmf\nqmgzp\nnzcpp\nrkjye\nuuppz\nvmibz\nzwyou\nhxclc\ngqtjh\njmucy\npqnhd\naqkea" }, { "input": "200 1 200\nycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqgn", "output": "y\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz\nc..." }, { "input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrcq", "output": "aron\nayj\nutj\ndhj\ncel\ngex\ngal\nnyi\nrue\nvje\nlvc\nvza\nihg\nbww\nrcq" }, { "input": "200 1 10\njtlykeyfekfrzbpzrhvrxagzywzlsktyzoriwiyatoetikfnhyhlrhuogyhjrxdmlqvpfsmqiqkivtodligzerymdtnqahuprhbfefbjwuavmpkurtfzmwediq", "output": "No solution" }, { "input": "15 2 3\ndplkzxpsxodehcj", "output": "No solution" }, { "input": "100 100 200\nximcxraplfjygtrpxrgjhqagrojixizlogaqfvwvqjaiqvcimelxtmtcsqluvcrdzhihgmwhywfgxmzmikdqdytfrlpzqmvhaexrtflwacsuxhkuzbukgvbdcmwpcvxwznupsmmryxwexlevjlonpipuxjgagxtcgqjdczrnmktgcaagmiumnbcxuafmysisahaqnngc", "output": "No solution" }, { "input": "7 2 3\nggzkinj", "output": "No solution" }, { "input": "17 2 4\npgyujupquzenuldnt", "output": "No solution" }, { "input": "100 1 1\nratfdjnvjmaqgcttjtenixeocyxrtuwhpmejhpxjcqhzjsujqolgcccmvnpoomkrforsdtvhgrcpakibozhgqotcrctzozhggrufk", "output": "No solution" }, { "input": "50 2 3\nizlszyucwjarrrgxzbfzyoxapozmunxuygfjynslcjnxitimjjklucjowtkccbnfsuwtyroxirhxzosbyhvnrroaxryhcvvcjvwfcpvnpdaqwzaiuzycyrtvkgkjfbdqnzrmritaonptpvncdifushrquywzykybhjdplbmsrgibpknxkxkqqywmkeljpxrrmufpkubv", "output": "No solution" }, { "input": "15 2 5\nkddainaviqrjsesrhhdnbuisennbgcxseeyxqtmautpoobtpfigcpgagcixmyzsntmgzwmiczsfp", "output": "No solution" }, { "input": "3 1 50\nhcdonseimahtfmtejvxebwctfkjsrcqjrunpcofrapijvwmmbbbrohkskjomeknlwkdxscybxkintcaynwyjfaghwcofpsbwruzqqqkhyndbxbdpgqokjqitznnnrfuaciriqmyuvktpdxewkrycjefkmjwglhoggpgvztvqndbhiajryxqlrqdb", "output": "No solution" }, { "input": "5 1 30\nxmuatgstrlkerxzezenrauupxiskpfugncncatcgtffhuwzojuapgrevnwzfkpyzbzljbzwvfoeuqhinyravsfqrjmgidjoszvkkhxrdstmydvbertvzltpipmcuakzqflldztzdjqlicvadgpicqio", "output": "No solution" }, { "input": "5 2 3\nabacababb", "output": "No solution" }, { "input": "5 6 6\nabacabadabacabaabacabadabacab", "output": "No solution" } ]
1,572,263,553
2,147,483,647
PyPy 3
OK
TESTS
32
280
0
k,a,b = map(int, input().split()) s=input() length = len(s) if length < a*k or length > b*k: print("No solution") quit() parts=[a]*k length -= a*k cur=0 while length > 0: if length < b-a: parts[cur] += length length = 0 else: parts[cur] += b-a length -= (b-a) cur += 1 for part in parts: print(s[:part]) s = s[part:]
Title: Anfisa the Monkey Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble human speech more. Help Anfisa. Input Specification: The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols. Output Specification: Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print "No solution" (without quotes). Demo Input: ['3 2 5\nabrakadabra\n', '4 1 2\nabrakadabra\n'] Demo Output: ['ab\nrakad\nabra\n', 'No solution\n'] Note: none
```python k,a,b = map(int, input().split()) s=input() length = len(s) if length < a*k or length > b*k: print("No solution") quit() parts=[a]*k length -= a*k cur=0 while length > 0: if length < b-a: parts[cur] += length length = 0 else: parts[cur] += b-a length -= (b-a) cur += 1 for part in parts: print(s[:part]) s = s[part:] ```
3.93
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
1,627,738,166
2,147,483,647
Python 3
OK
TESTS
37
124
6,963,200
n = int(input()) array = list(map(int, input().split())) hash_map = {} for x in array: if x not in hash_map: hash_map[x] = 1 else: hash_map[x] += 1 flag = True for v in hash_map.values(): if v > (n + 1) / 2: flag = False break if flag: print("YES") else: print("NO")
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
```python n = int(input()) array = list(map(int, input().split())) hash_map = {} for x in array: if x not in hash_map: hash_map[x] = 1 else: hash_map[x] += 1 flag = True for v in hash_map.values(): if v > (n + 1) / 2: flag = False break if flag: print("YES") else: print("NO") ```
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,536,071,866
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
l, r, a = map(int,input().split()) if l > r: r += a - (l - r) if a != 0: l += a//2 r += a//2 else: l += a - (r - l) if a != 0: l += a//2 r += a//2 k = 0 while l > 0 and r > 0: l -= 1 r -= 1 k += 2 print(k)
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 = map(int,input().split()) if l > r: r += a - (l - r) if a != 0: l += a//2 r += a//2 else: l += a - (r - l) if a != 0: l += a//2 r += a//2 k = 0 while l > 0 and r > 0: l -= 1 r -= 1 k += 2 print(k) ```
0
195
B
After Training
PROGRAMMING
1,300
[ "data structures", "implementation", "math" ]
null
null
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.
The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly.
Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball.
[ "4 3\n", "3 1\n" ]
[ "2\n1\n3\n2\n", "1\n1\n1\n" ]
none
1,000
[ { "input": "4 3", "output": "2\n1\n3\n2" }, { "input": "3 1", "output": "1\n1\n1" }, { "input": "10 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2" }, { "input": "6 5", "output": "3\n2\n4\n1\n5\n3" }, { "input": "2 6", "output": "3\n4" }, { "input": "5 2", "output": "1\n2\n1\n2\n1" }, { "input": "85702 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "9 2", "output": "1\n2\n1\n2\n1\n2\n1\n2\n1" }, { "input": "45 88", "output": "44\n45\n43\n46\n42\n47\n41\n48\n40\n49\n39\n50\n38\n51\n37\n52\n36\n53\n35\n54\n34\n55\n33\n56\n32\n57\n31\n58\n30\n59\n29\n60\n28\n61\n27\n62\n26\n63\n25\n64\n24\n65\n23\n66\n22" }, { "input": "61 51", "output": "26\n25\n27\n24\n28\n23\n29\n22\n30\n21\n31\n20\n32\n19\n33\n18\n34\n17\n35\n16\n36\n15\n37\n14\n38\n13\n39\n12\n40\n11\n41\n10\n42\n9\n43\n8\n44\n7\n45\n6\n46\n5\n47\n4\n48\n3\n49\n2\n50\n1\n51\n26\n25\n27\n24\n28\n23\n29\n22\n30\n21" }, { "input": "21 57", "output": "29\n28\n30\n27\n31\n26\n32\n25\n33\n24\n34\n23\n35\n22\n36\n21\n37\n20\n38\n19\n39" }, { "input": "677 787", "output": "394\n393\n395\n392\n396\n391\n397\n390\n398\n389\n399\n388\n400\n387\n401\n386\n402\n385\n403\n384\n404\n383\n405\n382\n406\n381\n407\n380\n408\n379\n409\n378\n410\n377\n411\n376\n412\n375\n413\n374\n414\n373\n415\n372\n416\n371\n417\n370\n418\n369\n419\n368\n420\n367\n421\n366\n422\n365\n423\n364\n424\n363\n425\n362\n426\n361\n427\n360\n428\n359\n429\n358\n430\n357\n431\n356\n432\n355\n433\n354\n434\n353\n435\n352\n436\n351\n437\n350\n438\n349\n439\n348\n440\n347\n441\n346\n442\n345\n443\n344\n444\n343\n4..." }, { "input": "37 849", "output": "425\n424\n426\n423\n427\n422\n428\n421\n429\n420\n430\n419\n431\n418\n432\n417\n433\n416\n434\n415\n435\n414\n436\n413\n437\n412\n438\n411\n439\n410\n440\n409\n441\n408\n442\n407\n443" }, { "input": "453 855", "output": "428\n427\n429\n426\n430\n425\n431\n424\n432\n423\n433\n422\n434\n421\n435\n420\n436\n419\n437\n418\n438\n417\n439\n416\n440\n415\n441\n414\n442\n413\n443\n412\n444\n411\n445\n410\n446\n409\n447\n408\n448\n407\n449\n406\n450\n405\n451\n404\n452\n403\n453\n402\n454\n401\n455\n400\n456\n399\n457\n398\n458\n397\n459\n396\n460\n395\n461\n394\n462\n393\n463\n392\n464\n391\n465\n390\n466\n389\n467\n388\n468\n387\n469\n386\n470\n385\n471\n384\n472\n383\n473\n382\n474\n381\n475\n380\n476\n379\n477\n378\n478\n377\n4..." }, { "input": "165 374", "output": "187\n188\n186\n189\n185\n190\n184\n191\n183\n192\n182\n193\n181\n194\n180\n195\n179\n196\n178\n197\n177\n198\n176\n199\n175\n200\n174\n201\n173\n202\n172\n203\n171\n204\n170\n205\n169\n206\n168\n207\n167\n208\n166\n209\n165\n210\n164\n211\n163\n212\n162\n213\n161\n214\n160\n215\n159\n216\n158\n217\n157\n218\n156\n219\n155\n220\n154\n221\n153\n222\n152\n223\n151\n224\n150\n225\n149\n226\n148\n227\n147\n228\n146\n229\n145\n230\n144\n231\n143\n232\n142\n233\n141\n234\n140\n235\n139\n236\n138\n237\n137\n238\n1..." }, { "input": "328 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3..." }, { "input": "8 80", "output": "40\n41\n39\n42\n38\n43\n37\n44" }, { "input": "90 544", "output": "272\n273\n271\n274\n270\n275\n269\n276\n268\n277\n267\n278\n266\n279\n265\n280\n264\n281\n263\n282\n262\n283\n261\n284\n260\n285\n259\n286\n258\n287\n257\n288\n256\n289\n255\n290\n254\n291\n253\n292\n252\n293\n251\n294\n250\n295\n249\n296\n248\n297\n247\n298\n246\n299\n245\n300\n244\n301\n243\n302\n242\n303\n241\n304\n240\n305\n239\n306\n238\n307\n237\n308\n236\n309\n235\n310\n234\n311\n233\n312\n232\n313\n231\n314\n230\n315\n229\n316\n228\n317" }, { "input": "85 60", "output": "30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18\n43\n17\n44\n16\n45\n15\n46\n14\n47\n13\n48\n12\n49\n11\n50\n10\n51\n9\n52\n8\n53\n7\n54\n6\n55\n5\n56\n4\n57\n3\n58\n2\n59\n1\n60\n30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18" }, { "input": "392 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "8 87", "output": "44\n43\n45\n42\n46\n41\n47\n40" }, { "input": "6 358", "output": "179\n180\n178\n181\n177\n182" }, { "input": "501 70", "output": "35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n66\n4\n67\n3\n68\n2\n69\n1\n70\n35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n6..." }, { "input": "3834 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "1 8828", "output": "4414" }, { "input": "69230 89906", "output": "44953\n44954\n44952\n44955\n44951\n44956\n44950\n44957\n44949\n44958\n44948\n44959\n44947\n44960\n44946\n44961\n44945\n44962\n44944\n44963\n44943\n44964\n44942\n44965\n44941\n44966\n44940\n44967\n44939\n44968\n44938\n44969\n44937\n44970\n44936\n44971\n44935\n44972\n44934\n44973\n44933\n44974\n44932\n44975\n44931\n44976\n44930\n44977\n44929\n44978\n44928\n44979\n44927\n44980\n44926\n44981\n44925\n44982\n44924\n44983\n44923\n44984\n44922\n44985\n44921\n44986\n44920\n44987\n44919\n44988\n44918\n44989\n44917\n..." }, { "input": "27646 59913", "output": "29957\n29956\n29958\n29955\n29959\n29954\n29960\n29953\n29961\n29952\n29962\n29951\n29963\n29950\n29964\n29949\n29965\n29948\n29966\n29947\n29967\n29946\n29968\n29945\n29969\n29944\n29970\n29943\n29971\n29942\n29972\n29941\n29973\n29940\n29974\n29939\n29975\n29938\n29976\n29937\n29977\n29936\n29978\n29935\n29979\n29934\n29980\n29933\n29981\n29932\n29982\n29931\n29983\n29930\n29984\n29929\n29985\n29928\n29986\n29927\n29987\n29926\n29988\n29925\n29989\n29924\n29990\n29923\n29991\n29922\n29992\n29921\n29993\n..." }, { "input": "37006 54783", "output": "27392\n27391\n27393\n27390\n27394\n27389\n27395\n27388\n27396\n27387\n27397\n27386\n27398\n27385\n27399\n27384\n27400\n27383\n27401\n27382\n27402\n27381\n27403\n27380\n27404\n27379\n27405\n27378\n27406\n27377\n27407\n27376\n27408\n27375\n27409\n27374\n27410\n27373\n27411\n27372\n27412\n27371\n27413\n27370\n27414\n27369\n27415\n27368\n27416\n27367\n27417\n27366\n27418\n27365\n27419\n27364\n27420\n27363\n27421\n27362\n27422\n27361\n27423\n27360\n27424\n27359\n27425\n27358\n27426\n27357\n27427\n27356\n27428\n..." }, { "input": "1 100000", "output": "50000" }, { "input": "100000 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "100000 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "100000 13", "output": "7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n..." }, { "input": "100000 44", "output": "22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21..." }, { "input": "100000 37820", "output": "18910\n18911\n18909\n18912\n18908\n18913\n18907\n18914\n18906\n18915\n18905\n18916\n18904\n18917\n18903\n18918\n18902\n18919\n18901\n18920\n18900\n18921\n18899\n18922\n18898\n18923\n18897\n18924\n18896\n18925\n18895\n18926\n18894\n18927\n18893\n18928\n18892\n18929\n18891\n18930\n18890\n18931\n18889\n18932\n18888\n18933\n18887\n18934\n18886\n18935\n18885\n18936\n18884\n18937\n18883\n18938\n18882\n18939\n18881\n18940\n18880\n18941\n18879\n18942\n18878\n18943\n18877\n18944\n18876\n18945\n18875\n18946\n18874\n..." }, { "input": "99999 77777", "output": "38889\n38888\n38890\n38887\n38891\n38886\n38892\n38885\n38893\n38884\n38894\n38883\n38895\n38882\n38896\n38881\n38897\n38880\n38898\n38879\n38899\n38878\n38900\n38877\n38901\n38876\n38902\n38875\n38903\n38874\n38904\n38873\n38905\n38872\n38906\n38871\n38907\n38870\n38908\n38869\n38909\n38868\n38910\n38867\n38911\n38866\n38912\n38865\n38913\n38864\n38914\n38863\n38915\n38862\n38916\n38861\n38917\n38860\n38918\n38859\n38919\n38858\n38920\n38857\n38921\n38856\n38922\n38855\n38923\n38854\n38924\n38853\n38925\n..." }, { "input": "1991 1935", "output": "968\n967\n969\n966\n970\n965\n971\n964\n972\n963\n973\n962\n974\n961\n975\n960\n976\n959\n977\n958\n978\n957\n979\n956\n980\n955\n981\n954\n982\n953\n983\n952\n984\n951\n985\n950\n986\n949\n987\n948\n988\n947\n989\n946\n990\n945\n991\n944\n992\n943\n993\n942\n994\n941\n995\n940\n996\n939\n997\n938\n998\n937\n999\n936\n1000\n935\n1001\n934\n1002\n933\n1003\n932\n1004\n931\n1005\n930\n1006\n929\n1007\n928\n1008\n927\n1009\n926\n1010\n925\n1011\n924\n1012\n923\n1013\n922\n1014\n921\n1015\n920\n1016\n919\n1017..." }, { "input": "17 812", "output": "406\n407\n405\n408\n404\n409\n403\n410\n402\n411\n401\n412\n400\n413\n399\n414\n398" }, { "input": "30078 300", "output": "150\n151\n149\n152\n148\n153\n147\n154\n146\n155\n145\n156\n144\n157\n143\n158\n142\n159\n141\n160\n140\n161\n139\n162\n138\n163\n137\n164\n136\n165\n135\n166\n134\n167\n133\n168\n132\n169\n131\n170\n130\n171\n129\n172\n128\n173\n127\n174\n126\n175\n125\n176\n124\n177\n123\n178\n122\n179\n121\n180\n120\n181\n119\n182\n118\n183\n117\n184\n116\n185\n115\n186\n114\n187\n113\n188\n112\n189\n111\n190\n110\n191\n109\n192\n108\n193\n107\n194\n106\n195\n105\n196\n104\n197\n103\n198\n102\n199\n101\n200\n100\n201\n9..." }, { "input": "10500 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "90091 322", "output": "161\n162\n160\n163\n159\n164\n158\n165\n157\n166\n156\n167\n155\n168\n154\n169\n153\n170\n152\n171\n151\n172\n150\n173\n149\n174\n148\n175\n147\n176\n146\n177\n145\n178\n144\n179\n143\n180\n142\n181\n141\n182\n140\n183\n139\n184\n138\n185\n137\n186\n136\n187\n135\n188\n134\n189\n133\n190\n132\n191\n131\n192\n130\n193\n129\n194\n128\n195\n127\n196\n126\n197\n125\n198\n124\n199\n123\n200\n122\n201\n121\n202\n120\n203\n119\n204\n118\n205\n117\n206\n116\n207\n115\n208\n114\n209\n113\n210\n112\n211\n111\n212\n1..." }, { "input": "8471 92356", "output": "46178\n46179\n46177\n46180\n46176\n46181\n46175\n46182\n46174\n46183\n46173\n46184\n46172\n46185\n46171\n46186\n46170\n46187\n46169\n46188\n46168\n46189\n46167\n46190\n46166\n46191\n46165\n46192\n46164\n46193\n46163\n46194\n46162\n46195\n46161\n46196\n46160\n46197\n46159\n46198\n46158\n46199\n46157\n46200\n46156\n46201\n46155\n46202\n46154\n46203\n46153\n46204\n46152\n46205\n46151\n46206\n46150\n46207\n46149\n46208\n46148\n46209\n46147\n46210\n46146\n46211\n46145\n46212\n46144\n46213\n46143\n46214\n46142\n..." }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1\n1" }, { "input": "52097 88310", "output": "44155\n44156\n44154\n44157\n44153\n44158\n44152\n44159\n44151\n44160\n44150\n44161\n44149\n44162\n44148\n44163\n44147\n44164\n44146\n44165\n44145\n44166\n44144\n44167\n44143\n44168\n44142\n44169\n44141\n44170\n44140\n44171\n44139\n44172\n44138\n44173\n44137\n44174\n44136\n44175\n44135\n44176\n44134\n44177\n44133\n44178\n44132\n44179\n44131\n44180\n44130\n44181\n44129\n44182\n44128\n44183\n44127\n44184\n44126\n44185\n44125\n44186\n44124\n44187\n44123\n44188\n44122\n44189\n44121\n44190\n44120\n44191\n44119\n..." } ]
1,648,838,445
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
6,758,400
def chooseBasket(x, baskets, m): smaller = -1 smallerList = [] for i in range(m): if len(baskets[i]) < smaller or smaller == -1: smallerList = [i] smaller = len(baskets[i]) elif len(baskets[i]) == smaller: smallerList.append(i) if len(smallerList) == 1: baskets[smallerList[0]].append(x) return closest = -1 closestList = [] for small in smallerList: aux = abs(0.5*(m+1) - (small+1)) if aux < closest or closest == -1: closestList = [small] closest = aux elif aux == closest: closestList.append(small) if len(closestList) == 1: baskets[closestList[0]].append(x) return smaller = -1 for i in range(len(closestList)): if closestList[i] < smaller or smaller == -1: smaller = closestList[i] baskets[smaller].append(x) n,m = map(int, input().split()) baskets = [] for i in range(m): baskets.append([]) for i in range(n): chooseBasket(i, baskets, m) outputList = [] for i in range(m): for ball in baskets[i]: outputList.append([ball, i+1]) outputList = sorted(outputList, key=lambda el : el[0]) for x in outputList: print(x[1])
Title: After Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on. Input Specification: The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. Output Specification: Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. Demo Input: ['4 3\n', '3 1\n'] Demo Output: ['2\n1\n3\n2\n', '1\n1\n1\n'] Note: none
```python def chooseBasket(x, baskets, m): smaller = -1 smallerList = [] for i in range(m): if len(baskets[i]) < smaller or smaller == -1: smallerList = [i] smaller = len(baskets[i]) elif len(baskets[i]) == smaller: smallerList.append(i) if len(smallerList) == 1: baskets[smallerList[0]].append(x) return closest = -1 closestList = [] for small in smallerList: aux = abs(0.5*(m+1) - (small+1)) if aux < closest or closest == -1: closestList = [small] closest = aux elif aux == closest: closestList.append(small) if len(closestList) == 1: baskets[closestList[0]].append(x) return smaller = -1 for i in range(len(closestList)): if closestList[i] < smaller or smaller == -1: smaller = closestList[i] baskets[smaller].append(x) n,m = map(int, input().split()) baskets = [] for i in range(m): baskets.append([]) for i in range(n): chooseBasket(i, baskets, m) outputList = [] for i in range(m): for ball in baskets[i]: outputList.append([ball, i+1]) outputList = sorted(outputList, key=lambda el : el[0]) for x in outputList: print(x[1]) ```
0
570
B
Simple Game
PROGRAMMING
1,300
[ "constructive algorithms", "games", "greedy", "implementation", "math" ]
null
null
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*. Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n* is chosen with the same probability), after which the winner is the player, whose number was closer to *c*. The boys agreed that if *m* and *a* are located on the same distance from *c*, Misha wins. Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number *n*. You need to determine which value of *a* Andrew must choose, so that the probability of his victory is the highest possible. More formally, you need to find such integer *a* (1<=≤<=*a*<=≤<=*n*), that the probability that is maximal, where *c* is the equiprobably chosen integer from 1 to *n* (inclusive).
The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively.
Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.
[ "3 1\n", "4 3\n" ]
[ "2", "2" ]
In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0. In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of *a* the probability of winning is less.
1,000
[ { "input": "3 1", "output": "2" }, { "input": "4 3", "output": "2" }, { "input": "5 5", "output": "4" }, { "input": "10 5", "output": "6" }, { "input": "20 13", "output": "12" }, { "input": "51 1", "output": "2" }, { "input": "100 50", "output": "51" }, { "input": "100 51", "output": "50" }, { "input": "100 49", "output": "50" }, { "input": "1000000000 1000000000", "output": "999999999" }, { "input": "1000000000 1", "output": "2" }, { "input": "1000000000 100000000", "output": "100000001" }, { "input": "1000000000 500000000", "output": "500000001" }, { "input": "1000000000 123124", "output": "123125" }, { "input": "12412523 125123", "output": "125124" }, { "input": "54645723 432423", "output": "432424" }, { "input": "1 1", "output": "1" }, { "input": "262833325 131416663", "output": "131416662" }, { "input": "477667530 238833766", "output": "238833765" }, { "input": "692501734 346250868", "output": "346250867" }, { "input": "907335939 453667970", "output": "453667969" }, { "input": "746085224 373042613", "output": "373042612" }, { "input": "189520699 94760350", "output": "94760349" }, { "input": "404354904 202177453", "output": "202177452" }, { "input": "619189108 309594555", "output": "309594554" }, { "input": "81813292 40906647", "output": "40906646" }, { "input": "296647497 148323750", "output": "148323749" }, { "input": "511481701 255740851", "output": "255740850" }, { "input": "726315905 363157953", "output": "363157952" }, { "input": "496110970 201868357", "output": "201868358" }, { "input": "710945175 173165570", "output": "173165571" }, { "input": "925779379 720443954", "output": "720443953" }, { "input": "140613583 93171580", "output": "93171579" }, { "input": "355447788 85890184", "output": "85890185" }, { "input": "570281992 291648263", "output": "291648262" }, { "input": "541904957 459371829", "output": "459371828" }, { "input": "756739161 125332525", "output": "125332526" }, { "input": "971573366 216791157", "output": "216791158" }, { "input": "186407570 160453970", "output": "160453969" }, { "input": "401241775 170032078", "output": "170032079" }, { "input": "616075979 207073797", "output": "207073798" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "2" }, { "input": "2 2", "output": "1" }, { "input": "3 1", "output": "2" }, { "input": "3 2", "output": "1" }, { "input": "3 3", "output": "2" }, { "input": "4 1", "output": "2" }, { "input": "4 2", "output": "3" }, { "input": "4 3", "output": "2" }, { "input": "4 4", "output": "3" }, { "input": "5 1", "output": "2" }, { "input": "5 2", "output": "3" }, { "input": "5 3", "output": "2" }, { "input": "5 4", "output": "3" }, { "input": "5 5", "output": "4" }, { "input": "3 2", "output": "1" }, { "input": "7 4", "output": "3" }, { "input": "2 2", "output": "1" }, { "input": "7 3", "output": "4" } ]
1,527,497,775
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
0
a = list(input().split()) n = int (a[0]) m = int (a[1]) if n%2==0: if m<n/2: print(int (m+1)) else: print(int (m-1)) else: if m<=n//2: print(int (m+1)) else: print(int (m-1))
Title: Simple Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*. Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n* is chosen with the same probability), after which the winner is the player, whose number was closer to *c*. The boys agreed that if *m* and *a* are located on the same distance from *c*, Misha wins. Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number *n*. You need to determine which value of *a* Andrew must choose, so that the probability of his victory is the highest possible. More formally, you need to find such integer *a* (1<=≤<=*a*<=≤<=*n*), that the probability that is maximal, where *c* is the equiprobably chosen integer from 1 to *n* (inclusive). Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively. Output Specification: Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them. Demo Input: ['3 1\n', '4 3\n'] Demo Output: ['2', '2'] Note: In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0. In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of *a* the probability of winning is less.
```python a = list(input().split()) n = int (a[0]) m = int (a[1]) if n%2==0: if m<n/2: print(int (m+1)) else: print(int (m-1)) else: if m<=n//2: print(int (m+1)) else: print(int (m-1)) ```
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,692,386,295
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
28
92
0
v,v1=map(int,input().split());c=v+1;c1=v1 while c%2==0 or (c%3==0 and c!=3) or (c%5==0 and c!=5) or (c%7==0 and c1!=7): c+=1 if c==c1 and c<=50: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 v,v1=map(int,input().split());c=v+1;c1=v1 while c%2==0 or (c%3==0 and c!=3) or (c%5==0 and c!=5) or (c%7==0 and c1!=7): c+=1 if c==c1 and c<=50:print("YES") else:print("NO") ```
0
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,670,326,206
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
n=int(input()) d={} for x in range(3): d[x]=set(input().split()) print(int(*(d[0]-d[1]))) print(int(*(d[1]-d[2])))
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()) d={} for x in range(3): d[x]=set(input().split()) print(int(*(d[0]-d[1]))) print(int(*(d[1]-d[2]))) ```
0
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,618,191,270
2,147,483,647
Python 3
OK
TESTS
38
77
0
string = str(input()) counter = 0 l = ['1','3','5','7','9','a','i','o','u','e'] for ch in string: if ch in l: counter += 1 print(counter)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python string = str(input()) counter = 0 l = ['1','3','5','7','9','a','i','o','u','e'] for ch in string: if ch in l: counter += 1 print(counter) ```
3
79
B
Colorful Field
PROGRAMMING
1,400
[ "implementation", "sortings" ]
B. Colorful Field
2
256
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: - Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. Now she is wondering how to determine the crop plants in some certain cells.
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*).
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
[ "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n" ]
[ "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n" ]
The sample corresponds to the figure in the statement.
1,000
[ { "input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots" }, { "input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2", "output": "Grapes\nWaste" }, { "input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 30\n2 5\n30 10\n4 21", "output": "Kiwis\nCarrots\nGrapes\nGrapes" }, { "input": "39898 39898 3 1\n4567 8901\n12345 23456\n24680 35679\n29292 12121", "output": "Grapes" }, { "input": "1 1 1 1\n1 1\n1 1", "output": "Waste" }, { "input": "1 2 1 2\n1 1\n1 2\n1 1", "output": "Carrots\nWaste" }, { "input": "1 6 3 12\n1 2\n1 4\n1 6\n1 1\n1 2\n1 6\n1 2\n1 5\n1 3\n1 4\n1 5\n1 5\n1 4\n1 6\n1 3", "output": "Carrots\nWaste\nWaste\nWaste\nGrapes\nKiwis\nWaste\nGrapes\nGrapes\nWaste\nWaste\nKiwis" }, { "input": "1 10 1 3\n1 5\n1 5\n1 5\n1 5", "output": "Waste\nWaste\nWaste" }, { "input": "5 5 1 3\n2 2\n2 2\n2 2\n2 2", "output": "Waste\nWaste\nWaste" }, { "input": "3 3 3 5\n1 1\n2 2\n3 3\n1 1\n2 2\n2 2\n2 2\n3 3", "output": "Waste\nWaste\nWaste\nWaste\nWaste" }, { "input": "1 10 2 4\n1 9\n1 5\n1 5\n1 6\n1 9\n1 10", "output": "Waste\nKiwis\nWaste\nKiwis" }, { "input": "5 2 2 1\n3 2\n4 2\n5 2", "output": "Kiwis" } ]
1,628,612,638
2,147,483,647
Python 3
OK
TESTS
29
434
6,963,200
n,m,k,t=map(int,input().split()) plant=['Grapes','Carrots','Kiwis'] waste=[] for i in range(0,k): x,y=map(int,input().split()) waste.append((x-1)*m+(y-1)) for i in range(0,t): x,y=map(int,input().split()) index=(x-1)*m+(y-1) if index in waste: print("Waste") else: num=index+1 for j in waste: if j<index: num=num-1 print(plant[num%3])
Title: Colorful Field Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: - Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. Now she is wondering how to determine the crop plants in some certain cells. Input Specification: In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*). Output Specification: For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Demo Input: ['4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n'] Demo Output: ['Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n'] Note: The sample corresponds to the figure in the statement.
```python n,m,k,t=map(int,input().split()) plant=['Grapes','Carrots','Kiwis'] waste=[] for i in range(0,k): x,y=map(int,input().split()) waste.append((x-1)*m+(y-1)) for i in range(0,t): x,y=map(int,input().split()) index=(x-1)*m+(y-1) if index in waste: print("Waste") else: num=index+1 for j in waste: if j<index: num=num-1 print(plant[num%3]) ```
3.87853
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,623,655,348
2,147,483,647
Python 3
OK
TESTS
102
77
0
s = '' s1,s2 = input(), input() for i,j in zip(s1,s2): if i != j: s += '1' else: s += '0' print(s)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python s = '' s1,s2 = input(), input() for i,j in zip(s1,s2): if i != j: s += '1' else: s += '0' print(s) ```
3.98075
501
B
Misha and Changing Handles
PROGRAMMING
1,100
[ "data structures", "dsu", "strings" ]
null
null
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order. Each user who changes the handle must occur exactly once in this description.
[ "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n" ]
[ "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n" ]
none
500
[ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123" }, { "input": "1\nMisha Vasya", "output": "1\nMisha Vasya" }, { "input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k", "output": "1\na k" }, { "input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha", "output": "2\n123abc 1A2B3C\n1 Misha" }, { "input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e", "output": "3\nM G\n1 R\nS e" }, { "input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV", "output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV" }, { "input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI", "output": "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9" }, { "input": "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6", "output": "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ" }, { "input": "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ", "output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ" } ]
1,625,535,858
2,147,483,647
Python 3
OK
TESTS
49
77
0
times = int(input()) old_to_new = {} new_to_old = {} for _ in range(times): (old, new) = input().split(" ") if old in new_to_old: old_to_new[new_to_old[old]] = new new_to_old[new] = new_to_old[old] else: old_to_new[old] = new new_to_old[new] = old print(len(old_to_new)) for k in old_to_new: print(f"{k} {old_to_new[k]}")
Title: Misha and Changing Handles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. Input Specification: The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. Output Specification: In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Demo Input: ['5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n'] Demo Output: ['3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n'] Note: none
```python times = int(input()) old_to_new = {} new_to_old = {} for _ in range(times): (old, new) = input().split(" ") if old in new_to_old: old_to_new[new_to_old[old]] = new new_to_old[new] = new_to_old[old] else: old_to_new[old] = new new_to_old[new] = old print(len(old_to_new)) for k in old_to_new: print(f"{k} {old_to_new[k]}") ```
3
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201", "output": "2\n100 10101 " }, { "input": "314159", "output": "9\n1 1 1 1 11 1011 101011 101011 111111 " }, { "input": "999999", "output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 " }, { "input": "2", "output": "2\n1 1 " }, { "input": "10", "output": "1\n10 " }, { "input": "21", "output": "2\n10 11 " }, { "input": "98", "output": "9\n10 11 11 11 11 11 11 11 11 " }, { "input": "102030", "output": "3\n10 1010 101010 " }, { "input": "909090", "output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 " }, { "input": "909823", "output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 " }, { "input": "1000000", "output": "1\n1000000 " }, { "input": "111111", "output": "1\n111111 " }, { "input": "123456", "output": "6\n1 11 111 1111 11111 111111 " }, { "input": "987654", "output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 " }, { "input": "908172", "output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 " }, { "input": "8", "output": "8\n1 1 1 1 1 1 1 1 " }, { "input": "100009", "output": "9\n1 1 1 1 1 1 1 1 100001 " }, { "input": "900000", "output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 " }, { "input": "1435", "output": "5\n1 101 111 111 1111 " }, { "input": "1453", "output": "5\n10 110 111 111 1111 " } ]
1,443,185,209
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
0
#In the name of Allah from sys import stdin, stdout input = stdin.readline a = [1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010, 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011, 111100, 111101, 111110, 111111, 1000000] n = int(input()) def f(n): for i in range(64): if a[i] > n: i -= 1 break return i ans = [] while n: ans.append(a[f(n)]) n -= ans[-1] stdout.write(str(len(ans)) + "\n") stdout.write(" ".join(map(str, ans)))
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). Output Specification: In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. Demo Input: ['9\n', '32\n'] Demo Output: ['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n'] Note: none
```python #In the name of Allah from sys import stdin, stdout input = stdin.readline a = [1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010, 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011, 111100, 111101, 111110, 111111, 1000000] n = int(input()) def f(n): for i in range(64): if a[i] > n: i -= 1 break return i ans = [] while n: ans.append(a[f(n)]) n -= ans[-1] stdout.write(str(len(ans)) + "\n") stdout.write(" ".join(map(str, ans))) ```
0
868
B
Race Against Time
PROGRAMMING
1,400
[ "implementation" ]
null
null
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds. Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand.
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "12 30 45 3 11\n", "12 0 1 12 1\n", "3 47 0 4 9\n" ]
[ "NO\n", "YES\n", "YES\n" ]
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
500
[ { "input": "12 30 45 3 11", "output": "NO" }, { "input": "12 0 1 12 1", "output": "YES" }, { "input": "3 47 0 4 9", "output": "YES" }, { "input": "10 22 59 6 10", "output": "YES" }, { "input": "3 1 13 12 3", "output": "NO" }, { "input": "11 19 28 9 10", "output": "YES" }, { "input": "9 38 22 6 1", "output": "NO" }, { "input": "5 41 11 5 8", "output": "NO" }, { "input": "11 2 53 10 4", "output": "YES" }, { "input": "9 41 17 10 1", "output": "YES" }, { "input": "6 54 48 12 6", "output": "YES" }, { "input": "12 55 9 5 1", "output": "NO" }, { "input": "8 55 35 9 3", "output": "NO" }, { "input": "3 21 34 3 10", "output": "YES" }, { "input": "2 52 1 12 3", "output": "NO" }, { "input": "7 17 11 1 7", "output": "NO" }, { "input": "11 6 37 6 4", "output": "YES" }, { "input": "9 6 22 8 1", "output": "NO" }, { "input": "3 10 5 5 9", "output": "YES" }, { "input": "7 12 22 11 2", "output": "YES" }, { "input": "7 19 4 7 3", "output": "NO" }, { "input": "11 36 21 4 6", "output": "NO" }, { "input": "10 32 49 1 3", "output": "YES" }, { "input": "1 9 43 11 3", "output": "NO" }, { "input": "1 8 33 4 8", "output": "NO" }, { "input": "3 0 33 9 4", "output": "NO" }, { "input": "7 15 9 10 3", "output": "NO" }, { "input": "8 3 57 11 1", "output": "NO" }, { "input": "1 33 49 5 9", "output": "NO" }, { "input": "3 40 0 5 7", "output": "YES" }, { "input": "5 50 9 2 7", "output": "NO" }, { "input": "10 0 52 6 1", "output": "YES" }, { "input": "3 10 4 1 11", "output": "NO" }, { "input": "2 41 53 4 6", "output": "YES" }, { "input": "10 29 30 4 7", "output": "NO" }, { "input": "5 13 54 9 11", "output": "NO" }, { "input": "1 0 23 3 9", "output": "NO" }, { "input": "1 0 41 12 1", "output": "NO" }, { "input": "6 30 30 3 9", "output": "YES" }, { "input": "3 7 32 11 10", "output": "YES" }, { "input": "1 0 25 12 4", "output": "NO" }, { "input": "12 0 0 5 6", "output": "YES" }, { "input": "1 5 4 3 2", "output": "YES" }, { "input": "6 30 30 9 10", "output": "YES" }, { "input": "6 0 0 2 8", "output": "NO" }, { "input": "10 50 59 9 10", "output": "YES" }, { "input": "12 59 59 12 6", "output": "NO" }, { "input": "3 0 30 3 4", "output": "NO" }, { "input": "2 10 10 1 11", "output": "YES" }, { "input": "10 5 30 1 12", "output": "YES" }, { "input": "5 29 31 5 10", "output": "YES" }, { "input": "5 2 2 11 2", "output": "NO" }, { "input": "5 15 46 3 10", "output": "YES" }, { "input": "1 30 50 1 2", "output": "NO" }, { "input": "5 26 14 1 12", "output": "YES" }, { "input": "1 58 43 12 1", "output": "YES" }, { "input": "12 0 12 11 1", "output": "NO" }, { "input": "6 52 41 6 5", "output": "YES" }, { "input": "5 8 2 1 3", "output": "NO" }, { "input": "2 0 0 1 3", "output": "NO" }, { "input": "1 5 6 2 1", "output": "YES" }, { "input": "9 5 5 11 12", "output": "YES" }, { "input": "12 5 19 3 4", "output": "NO" }, { "input": "6 14 59 1 3", "output": "NO" }, { "input": "10 38 34 4 12", "output": "YES" }, { "input": "2 54 14 2 12", "output": "YES" }, { "input": "5 31 0 6 7", "output": "NO" }, { "input": "6 15 30 3 9", "output": "YES" }, { "input": "3 54 41 8 10", "output": "NO" }, { "input": "3 39 10 10 12", "output": "YES" }, { "input": "1 11 50 1 2", "output": "NO" }, { "input": "5 40 24 8 1", "output": "NO" }, { "input": "9 5 59 1 3", "output": "NO" }, { "input": "5 0 0 6 7", "output": "YES" }, { "input": "4 40 59 6 8", "output": "YES" }, { "input": "10 13 55 12 1", "output": "YES" }, { "input": "6 50 0 5 6", "output": "YES" }, { "input": "7 59 3 7 4", "output": "YES" }, { "input": "6 0 1 6 7", "output": "NO" }, { "input": "6 15 55 3 5", "output": "NO" }, { "input": "12 9 55 10 2", "output": "YES" }, { "input": "2 0 1 11 2", "output": "NO" }, { "input": "8 45 17 12 9", "output": "NO" }, { "input": "5 30 31 11 3", "output": "YES" }, { "input": "6 43 0 10 6", "output": "NO" }, { "input": "6 30 30 1 11", "output": "YES" }, { "input": "11 59 59 11 12", "output": "YES" }, { "input": "5 45 35 9 5", "output": "NO" }, { "input": "2 43 4 9 7", "output": "NO" }, { "input": "12 30 50 6 9", "output": "NO" }, { "input": "1 10 1 2 3", "output": "NO" }, { "input": "10 5 55 9 1", "output": "NO" }, { "input": "1 59 59 2 3", "output": "YES" }, { "input": "1 49 14 10 3", "output": "NO" }, { "input": "3 15 15 2 4", "output": "YES" }, { "input": "10 5 55 1 5", "output": "NO" }, { "input": "6 33 45 12 6", "output": "YES" }, { "input": "1 20 20 11 1", "output": "YES" }, { "input": "2 30 45 1 11", "output": "YES" }, { "input": "1 55 1 11 10", "output": "YES" }, { "input": "3 0 1 11 1", "output": "NO" }, { "input": "1 5 6 1 12", "output": "YES" }, { "input": "12 10 5 11 4", "output": "YES" }, { "input": "6 5 59 12 1", "output": "YES" }, { "input": "12 0 20 11 12", "output": "YES" }, { "input": "3 25 30 4 5", "output": "YES" }, { "input": "2 15 18 11 1", "output": "YES" }, { "input": "12 5 48 11 9", "output": "NO" }, { "input": "6 30 30 10 2", "output": "YES" }, { "input": "1 0 11 1 2", "output": "NO" }, { "input": "10 0 1 10 11", "output": "NO" }, { "input": "3 30 45 10 1", "output": "YES" }, { "input": "11 21 56 3 12", "output": "YES" }, { "input": "3 16 16 3 4", "output": "YES" }, { "input": "11 55 55 1 12", "output": "YES" }, { "input": "12 12 12 11 12", "output": "YES" }, { "input": "3 5 1 1 2", "output": "NO" }, { "input": "3 30 45 10 11", "output": "YES" }, { "input": "10 0 1 9 10", "output": "YES" }, { "input": "3 0 5 3 6", "output": "NO" }, { "input": "1 1 49 1 10", "output": "NO" }, { "input": "9 45 15 11 12", "output": "YES" }, { "input": "12 15 59 3 8", "output": "NO" }, { "input": "5 0 5 3 6", "output": "NO" }, { "input": "3 30 45 1 2", "output": "YES" }, { "input": "2 10 11 2 4", "output": "YES" }, { "input": "2 10 10 4 3", "output": "YES" }, { "input": "3 30 59 1 2", "output": "YES" }, { "input": "11 59 59 12 11", "output": "YES" }, { "input": "10 25 50 5 6", "output": "NO" }, { "input": "6 30 30 9 3", "output": "YES" }, { "input": "8 14 40 12 3", "output": "NO" }, { "input": "2 10 10 1 6", "output": "YES" } ]
1,525,127,780
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
77
7,065,600
x=list(map(int,input().split())) x[0]=int((x[0]*(60/12))) % 60 m=x[1] s=x[2] x[3]=int((x[3]*(60/12))) % 60 x[4]=int((x[4]*(60/12))) % 60 z=[x[1],x[2],x[0]] z.sort() x1=[] x2=[] for i in range(1,3): if z[i-1]==z[i]: del(z[i]) break if len(z)==3: if x[3]>z[0] and x[3]<z[1]: x1.append(1) if x[3]>z[1] and x[3]<z[2]: x1.append(2) if x[3]==z[0]: x1.append(1) x1.append(3) if x[3]==z[1]: x1.append(2) x1.append(1) if x[3]==z[2]: x1.append(2) x1.append(3) elif len(x1)==0: x1.append(3) if x[4]>z[0] and x[4]<z[1]: x2.append(1) if x[4]>z[1] and x[4]<z[2]: x2.append(2) if x[4]==z[0]: x2.append(1) x2.append(3) if x[4]==z[1]: x2.append(2) x2.append(1) if x[4]==z[2]: x2.append(2) x2.append(3) elif len(x2)==0: x2.append(3) else: if x[3]>z[0] and x[3]<z[1]: x1.append(1) if x[3]==z[0]: x1.append(1) x1.append(2) if x[3]==z[1]: x1.append(1) x1.append(2) elif len(x)==0: x1.append(2) if x[4]>z[0] and x[4]<z[1]: x1.append(1) if x[4]==z[0]: x2.append(1) x2.append(2) if x[4]==z[1]: x2.append(1) x2.append(2) elif len(x2)==0: x2.append(2) d=x1 f=len(x1) s='NO' if len(x1)<len(x2): d=x2 f=len(x2) x2=x1 for i in range(f): if d[i]in x2: s='YES' print(s)
Title: Race Against Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds. Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. Input Specification: Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand. Output Specification: Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n'] Note: The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
```python x=list(map(int,input().split())) x[0]=int((x[0]*(60/12))) % 60 m=x[1] s=x[2] x[3]=int((x[3]*(60/12))) % 60 x[4]=int((x[4]*(60/12))) % 60 z=[x[1],x[2],x[0]] z.sort() x1=[] x2=[] for i in range(1,3): if z[i-1]==z[i]: del(z[i]) break if len(z)==3: if x[3]>z[0] and x[3]<z[1]: x1.append(1) if x[3]>z[1] and x[3]<z[2]: x1.append(2) if x[3]==z[0]: x1.append(1) x1.append(3) if x[3]==z[1]: x1.append(2) x1.append(1) if x[3]==z[2]: x1.append(2) x1.append(3) elif len(x1)==0: x1.append(3) if x[4]>z[0] and x[4]<z[1]: x2.append(1) if x[4]>z[1] and x[4]<z[2]: x2.append(2) if x[4]==z[0]: x2.append(1) x2.append(3) if x[4]==z[1]: x2.append(2) x2.append(1) if x[4]==z[2]: x2.append(2) x2.append(3) elif len(x2)==0: x2.append(3) else: if x[3]>z[0] and x[3]<z[1]: x1.append(1) if x[3]==z[0]: x1.append(1) x1.append(2) if x[3]==z[1]: x1.append(1) x1.append(2) elif len(x)==0: x1.append(2) if x[4]>z[0] and x[4]<z[1]: x1.append(1) if x[4]==z[0]: x2.append(1) x2.append(2) if x[4]==z[1]: x2.append(1) x2.append(2) elif len(x2)==0: x2.append(2) d=x1 f=len(x1) s='NO' if len(x1)<len(x2): d=x2 f=len(x2) x2=x1 for i in range(f): if d[i]in x2: s='YES' print(s) ```
0
0
none
none
none
0
[ "none" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
0
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes" }, { "input": "1\n2 3", "output": "No" }, { "input": "1\n1062961 1031", "output": "Yes" }, { "input": "1\n6 12", "output": "No" }, { "input": "1\n3 1", "output": "No" }, { "input": "1\n3 10", "output": "No" }, { "input": "1\n31159 970883281", "output": "Yes" }, { "input": "1\n9907 98148649", "output": "Yes" }, { "input": "1\n16 8", "output": "No" }, { "input": "1\n90 72", "output": "No" } ]
1,608,538,312
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
0
1,000
117,043,200
def CreateCubes(n): cant=n**3+1 cubes={} for x in range(1,n+1): cubes[x**3] = x return cubes def TheMeaninglessGame(): n = int(input()) cubes=CreateCubes(1000000) for x in range(n): i=input().split() a=int(i[0]) b=int(i[1]) r=cubes.get(a*b) if not r: print('No') continue X_1=a%r X_2=b%r bl=X_1==X_2==0 if bl:print('Yes') else: print('No') TheMeaninglessGame()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one. Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. Input Specification: In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. Output Specification: For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). Demo Input: ['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n'] Demo Output: ['Yes\nYes\nYes\nNo\nNo\nYes\n'] Note: First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
```python def CreateCubes(n): cant=n**3+1 cubes={} for x in range(1,n+1): cubes[x**3] = x return cubes def TheMeaninglessGame(): n = int(input()) cubes=CreateCubes(1000000) for x in range(n): i=input().split() a=int(i[0]) b=int(i[1]) r=cubes.get(a*b) if not r: print('No') continue X_1=a%r X_2=b%r bl=X_1==X_2==0 if bl:print('Yes') else: print('No') TheMeaninglessGame() ```
0
774
J
Stepan's Series
PROGRAMMING
2,000
[ "*special", "dp" ]
null
null
Well, the series which Stepan watched for a very long time, ended. In total, the series had *n* episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch. Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*) — the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of *n* symbols "Y", "N" and "?". If the *i*-th symbol equals "Y", Stepan remembers that he has watched the episode number *i*. If the *i*-th symbol equals "N", Stepan remembers that he hasn't watched the epizode number *i*. If the *i*-th symbol equals "?", Stepan doesn't exactly remember if he has watched the episode number *i* or not.
If Stepan's dissatisfaction can be exactly equal to *k*, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes).
[ "5 2\nNYNNY\n", "6 1\n????NN\n" ]
[ "YES\n", "NO\n" ]
In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "YES", because *k* = 2. In the second test *k* = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row — number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive.
0
[ { "input": "5 2\nNYNNY", "output": "YES" }, { "input": "6 1\n????NN", "output": "NO" }, { "input": "100 8\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN", "output": "YES" }, { "input": "10 1\nNY???NY?Y?", "output": "YES" }, { "input": "20 7\nN?N??NNN?NNN?Y???Y??", "output": "YES" }, { "input": "30 1\nNYYYNYYY?Y?YY?YYYYYYYYYYYYYNYY", "output": "YES" }, { "input": "40 14\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN", "output": "NO" }, { "input": "51 1\nYYYNYNYNNYYNNY?YNYYYYYYNNYNYN??NYNYYNYYYYYYNNYNNNYY", "output": "NO" }, { "input": "70 3\nYNNNYYYNY?YYNYYNYYN?NYYYYYYYYYYYYYNYYNNYYYYYYYNYYNNNY??YYNYYYYYYYYNYYN", "output": "YES" }, { "input": "85 10\nYNNYNNNNNYNNNNNNNNNNNYNYYNNYNNNYYYNNNYYNNNNYNNNYNNNYNNNNNNNNNNNNN?NNNNYNNYYNNNNNNYNNN", "output": "NO" }, { "input": "90 18\nNNNN?NNNNNYNYNYNNY?NNNNNNNNNNNNNNYNNNNNNYYNYYNNNNYNNNNNNNNNNNNNNNNNNNYNNYYNYNNNNNNNYNNNNYN", "output": "NO" }, { "input": "99 2\nYNYYYYYYYYYYYN?YYNYYYYYYYYYYYYYY?YYYNYYYYYYYYYYYYYNYYYYYYNY?YYYYYNNYYYNYNYYYYNYYYYYYYYYYYNYY?NYYYYY", "output": "YES" }, { "input": "100 74\nNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN?NNNNNNNNNNNN?NNNNNNNNNNNNNN", "output": "NO" }, { "input": "100 19\nYYNN?NNNNNNNNNNNYNYYNYNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNYNNNNNNYNNYYNNNYNNNYNYNNYNNNYYNNNYNNN?NNNNN?YNN", "output": "NO" }, { "input": "100 10\nNNNNYNNNYNNNNNNNNYNYNYNNNNNYNNNNNYNNNNNNNNNNNYNYYNNNNNNNYYNNYNYNNYYNNNNYNNNNNYNNNNYNNNNYNNY??YNNNNYY", "output": "NO" }, { "input": "100 4\nYYNNNNYYYNNNNNNYNYYYNYYNYYNNYYNNNNNNNYNYYNYYNNYNNNNNYN?YNYYYNNYNNNNNYNNNNYYNYYYYYNYNNNNYYNNNNYNNNNYY", "output": "NO" }, { "input": "100 2\nYYNNYYYNNYYYYYYYYYYYYYYYNYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNYNYYYYYYNNYYYNYYNNYYNYYYYNYNYYYYYYNYYY", "output": "YES" }, { "input": "100 3\nYYYYYYYYNNNYNYNYYYYNY?YYYYYYNYYYNYYYYYYYYYYYYNNYYYYYNYNYYNYYYYYYYYYYYYYYYYYYY?YYNNYYNNYYYNYYYYYYYYYY", "output": "YES" }, { "input": "100 2\nYYYYYYYYYYYNYYYYYYYYYYYYYYYYYYYYYYYYYNYY?YYYYYYYYYYYYYYYNYYYYYYYYYYYYNNYYYYYYYYYNYYYYYYYYYYNYYYYYYYY", "output": "YES" }, { "input": "100 3\nNYNNYYYYYYNYNNYYYYYYNYYNYNYYYYYNYYYYYNNNYYYYYNYNYYNYYNYYNYNNNYYNYYYYYNYYYYYYNNYYNYNNYYNYYYY?YYNNYYNN", "output": "YES" }, { "input": "100 26\nNNYNNNNNNNNNNNNN?NNNNNNNNNNNNNYNNNNYNNNNNNNNNNNNYNNNNNN?NNNYNNNNNNNNNNYYNNNNNNNNYNNNNNNNNYYYNNNNYYNY", "output": "NO" }, { "input": "1 1\nY", "output": "NO" }, { "input": "1 1\nN", "output": "YES" }, { "input": "1 1\n?", "output": "YES" }, { "input": "1 0\n?", "output": "YES" }, { "input": "1 0\nN", "output": "NO" }, { "input": "1 0\nY", "output": "YES" }, { "input": "100 100\n????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "YES" }, { "input": "6 4\nNN??NN", "output": "NO" }, { "input": "6 3\nNNYYN?", "output": "NO" }, { "input": "7 3\nN?YY???", "output": "YES" }, { "input": "24 4\nY?NYYNYYYNYYN?NNN?N?Y?Y?", "output": "NO" }, { "input": "3 3\n?Y?", "output": "NO" }, { "input": "10 1\nNY???NY?Y?", "output": "YES" }, { "input": "20 8\nNNNYY?????NN???N?YN?", "output": "YES" }, { "input": "30 2\n??????????????????????????????", "output": "YES" }, { "input": "40 17\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN", "output": "YES" }, { "input": "51 5\nY??N????????Y??N?????N???N???YN?N?Y?N??Y?Y??Y???NN?", "output": "YES" }, { "input": "70 3\nY?N?Y???NN?NY?N?YY?Y????YNYY?Y?N??Y????YY??N????NY?NYY?YY?YYYY?YY?N?Y?", "output": "YES" }, { "input": "85 18\nNNNNNNN??Y???NN?YNNNNNNNN???YNNNNNN??Y?N?YNYYNN?NNNNNNNNNNNNNN????NNY??NNNN?NN??NNNNN", "output": "YES" }, { "input": "90 15\nYNNNNN?NNYNNYNNNN?NNNNYNNY?NNNNNNN?NNNNNNYN?NNYNNNNNN?NNYYNNYN?NNN??NNNNYNNN?YN?NNNNYNN?NY", "output": "YES" }, { "input": "99 1\nYYYYYYYNYYY??YY??YYYYYYY????NYY?YYY?Y??YYYY????YY?YY?YYY?YY??YYY?Y??NYYYY?YNYY??Y??YYYYY?YYY????YYY", "output": "YES" }, { "input": "100 34\n?NNNN??N???NNNN?NNN?N???N?N????NNNNNNN?N??N???NNNN???N?N?NN?NNNNN?NNN???N??NN??Y??NNN??N?NNN???NN?NN", "output": "YES" }, { "input": "100 21\n?NNNNNYNN??NNN?N????N?NN?N??NN?NNNY?NN?NY?NN?NNN?NN?N?NNNNNNY?NYNN??N??NYNN?NN?NNNN?N???NN?NN?Y?NYNY", "output": "YES" }, { "input": "100 10\nN?NNYYYNNNNNNYYNNYYNNNNNNNNYYNNNYYNNYNYNY?NNNNNNNNNYYNNNNYNNNNYNNNYNNYNNN?NNY?NNNNNNNNN?NYNYNNNNNNNN", "output": "YES" }, { "input": "100 6\n????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "YES" }, { "input": "100 2\nYYNNYYYNNYYYYYYYYYYYYYYYNYYYNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNYNYYYYYYNNYYYNYYNNYYNYYYYNYNYYYYYYNYYY", "output": "YES" }, { "input": "100 1\n???Y??????????????????????????????????????Y?????????N???Y????????Y?????Y???????Y??Y??????????YY?????", "output": "YES" }, { "input": "100 1\nYYYYYYYYY??YYN?YYNYYYYYYYNYYYYYYYYYYY?YN?YYYYY?YYYYYYYYYYYYY?YYYYYYYYYYYYN?YYYYYYYY?YYYYY?YYNYYYYYNY", "output": "YES" }, { "input": "100 3\n?YNNYYNYYYYYYNYYYYYNY?NNYYYYNYY??NYYNYNYYYY?YYNYYNYYYYYYYYYYNYYYYNYYYYNYYYYNYYNYYYYYYNYNYNYYYYYYNNYY", "output": "YES" }, { "input": "3 2\n?Y?", "output": "NO" } ]
1,492,502,454
2,147,483,647
Python 3
OK
TESTS
51
342
12,288,000
from sys import stdin from functools import lru_cache from collections import defaultdict infile = stdin N, K = map(int, infile.readline().split()) watched = infile.readline().strip() mem = set() mem.add((0,0,0)) for i, letter in enumerate(watched): for d in range(K+1): for c in range(K+1): if (i,d,c) in mem: if letter in ('N', '?'): mem.add((i+1, max(d, c+1), c+1)) if letter in ('Y', '?'): mem.add((i+1, d, 0)) def good(): for i,d,c in mem: if i == N and d == K: return 'YES' return 'NO' print(good())
Title: Stepan's Series Time Limit: None seconds Memory Limit: None megabytes Problem Description: Well, the series which Stepan watched for a very long time, ended. In total, the series had *n* episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch. Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*) — the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of *n* symbols "Y", "N" and "?". If the *i*-th symbol equals "Y", Stepan remembers that he has watched the episode number *i*. If the *i*-th symbol equals "N", Stepan remembers that he hasn't watched the epizode number *i*. If the *i*-th symbol equals "?", Stepan doesn't exactly remember if he has watched the episode number *i* or not. Output Specification: If Stepan's dissatisfaction can be exactly equal to *k*, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes). Demo Input: ['5 2\nNYNNY\n', '6 1\n????NN\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "YES", because *k* = 2. In the second test *k* = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row — number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive.
```python from sys import stdin from functools import lru_cache from collections import defaultdict infile = stdin N, K = map(int, infile.readline().split()) watched = infile.readline().strip() mem = set() mem.add((0,0,0)) for i, letter in enumerate(watched): for d in range(K+1): for c in range(K+1): if (i,d,c) in mem: if letter in ('N', '?'): mem.add((i+1, max(d, c+1), c+1)) if letter in ('Y', '?'): mem.add((i+1, d, 0)) def good(): for i,d,c in mem: if i == N and d == K: return 'YES' return 'NO' print(good()) ```
3
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 91", "output": "-48" }, { "input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "output": "-86" }, { "input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94", "output": "-98" }, { "input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46", "output": "-91" }, { "input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89", "output": "-98" }, { "input": "2\n-1 -1", "output": "NO" }, { "input": "3\n-2 -2 -2", "output": "NO" }, { "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": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47", "output": "40" }, { "input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90", "output": "-64" }, { "input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93", "output": "-93" }, { "input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83", "output": "-86" }, { "input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43", "output": "-95" }, { "input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92", "output": "-92" }, { "input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12", "output": "-98" }, { "input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100", "output": "-98" }, { "input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92", "output": "-98" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "3\n1 3 2", "output": "2" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "3\n3 1 2", "output": "2" }, { "input": "3\n3 2 1", "output": "2" }, { "input": "9\n99 99 99 99 100 100 100 100 100", "output": "100" }, { "input": "5\n-100 -100 -100 -100 -100", "output": "NO" } ]
1,686,491,836
2,147,483,647
Python 3
OK
TESTS
31
92
0
t = int(input()) a = list(map(int, input().split()[:t])) new_a = sorted(set(a)) if len(new_a) < 2: print("NO") else: print(new_a[1])
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. Output Specification: If the given sequence has the second order statistics, output this order statistics, otherwise output NO. Demo Input: ['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n'] Demo Output: ['1\n', '2\n'] Note: none
```python t = int(input()) a = list(map(int, input().split()[:t])) new_a = sorted(set(a)) if len(new_a) < 2: print("NO") else: print(new_a[1]) ```
3.977
712
C
Memory and De-Evolution
PROGRAMMING
1,600
[ "greedy", "math" ]
null
null
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y*?
The first and only line contains two integers *x* and *y* (3<=≤<=*y*<=&lt;<=*x*<=≤<=100<=000) — the starting and ending equilateral triangle side lengths respectively.
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*.
[ "6 3\n", "8 5\n", "22 4\n" ]
[ "4\n", "3\n", "6\n" ]
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21c6.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcfd51d1b2d764a1cf5fbc255cc02e6f5aaed3b1.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample test, Memory can do: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0969b7d413854c1e7528991d926bef1f7ffba008.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/63e9e66b882c03e4c73e93ad92204dc255329309.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,500
[ { "input": "6 3", "output": "4" }, { "input": "8 5", "output": "3" }, { "input": "22 4", "output": "6" }, { "input": "4 3", "output": "3" }, { "input": "57 27", "output": "4" }, { "input": "61 3", "output": "9" }, { "input": "5 4", "output": "3" }, { "input": "10 6", "output": "3" }, { "input": "20 10", "output": "4" }, { "input": "30 5", "output": "6" }, { "input": "25 24", "output": "3" }, { "input": "25 3", "output": "7" }, { "input": "12 7", "output": "3" }, { "input": "18 6", "output": "5" }, { "input": "100000 3", "output": "25" }, { "input": "100000 9999", "output": "7" }, { "input": "9999 3", "output": "20" }, { "input": "5323 32", "output": "13" }, { "input": "6666 66", "output": "12" }, { "input": "38578 32201", "output": "3" }, { "input": "49449 5291", "output": "7" }, { "input": "65310 32879", "output": "3" }, { "input": "41183 4453", "output": "7" }, { "input": "49127 9714", "output": "6" }, { "input": "19684 12784", "output": "3" }, { "input": "15332 5489", "output": "4" }, { "input": "33904 32701", "output": "3" }, { "input": "9258 2966", "output": "5" }, { "input": "21648 11231", "output": "3" }, { "input": "90952 47239", "output": "3" }, { "input": "49298 23199", "output": "4" }, { "input": "33643 24915", "output": "3" }, { "input": "40651 5137", "output": "6" }, { "input": "52991 15644", "output": "5" }, { "input": "97075 62157", "output": "3" }, { "input": "82767 53725", "output": "3" }, { "input": "58915 26212", "output": "4" }, { "input": "86516 16353", "output": "6" }, { "input": "14746 7504", "output": "3" }, { "input": "20404 7529", "output": "4" }, { "input": "52614 8572", "output": "6" }, { "input": "50561 50123", "output": "3" }, { "input": "37509 7908", "output": "5" }, { "input": "36575 23933", "output": "3" }, { "input": "75842 8002", "output": "7" }, { "input": "47357 2692", "output": "8" }, { "input": "23214 4255", "output": "6" }, { "input": "9474 46", "output": "13" }, { "input": "79874 76143", "output": "3" }, { "input": "63784 31333", "output": "4" }, { "input": "70689 29493", "output": "4" }, { "input": "43575 4086", "output": "7" }, { "input": "87099 7410", "output": "7" }, { "input": "75749 55910", "output": "3" }, { "input": "87827 20996", "output": "5" }, { "input": "31162 4580", "output": "6" }, { "input": "63175 33696", "output": "3" }, { "input": "15108 10033", "output": "3" }, { "input": "82991 29195", "output": "4" }, { "input": "48258 12837", "output": "5" }, { "input": "59859 33779", "output": "3" }, { "input": "93698 23890", "output": "5" }, { "input": "42724 379", "output": "12" }, { "input": "70434 39286", "output": "3" }, { "input": "69826 18300", "output": "5" }, { "input": "57825 17636", "output": "5" }, { "input": "64898 2076", "output": "9" }, { "input": "76375 67152", "output": "3" }, { "input": "30698 3778", "output": "7" }, { "input": "100 3", "output": "10" }, { "input": "41 3", "output": "8" }, { "input": "28 4", "output": "7" }, { "input": "2487 19", "output": "12" }, { "input": "100000 25000", "output": "5" }, { "input": "10000 3", "output": "20" }, { "input": "16 3", "output": "6" } ]
1,595,600,263
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
21,401,600
x,y = map(int,input().split()) turn = cnt = 0 a = b = c = y while True: if a >= x and b >= x and c >= x: print(cnt) break cnt += 1 if turn % 3 == 0: a = b + c - 1 if turn % 3 == 1: b = a + c - 1 if turn % 3 == 2: c = a + b - 1
Title: Memory and De-Evolution Time Limit: None seconds Memory Limit: None megabytes Problem Description: Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y*? Input Specification: The first and only line contains two integers *x* and *y* (3<=≤<=*y*<=&lt;<=*x*<=≤<=100<=000) — the starting and ending equilateral triangle side lengths respectively. Output Specification: Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*. Demo Input: ['6 3\n', '8 5\n', '22 4\n'] Demo Output: ['4\n', '3\n', '6\n'] Note: In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21c6.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcfd51d1b2d764a1cf5fbc255cc02e6f5aaed3b1.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the third sample test, Memory can do: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0969b7d413854c1e7528991d926bef1f7ffba008.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/63e9e66b882c03e4c73e93ad92204dc255329309.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python x,y = map(int,input().split()) turn = cnt = 0 a = b = c = y while True: if a >= x and b >= x and c >= x: print(cnt) break cnt += 1 if turn % 3 == 0: a = b + c - 1 if turn % 3 == 1: b = a + c - 1 if turn % 3 == 2: c = a + b - 1 ```
0
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 21 73839", "output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99991 623 36438", "output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 334 94854", "output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99252 9827 84849", "output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99313 9833 10561", "output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "94885 55815 11417", "output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99492 58525 53481", "output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99858 28531 79193", "output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99136 47208 42607", "output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "63270 19953 5555", "output": "-1" }, { "input": "10240 128 100000", "output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "12 11 3", "output": "12100" }, { "input": "14 12 99998", "output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1 11 3", "output": "1100" }, { "input": "3 40 1", "output": "-1" }, { "input": "150 100 10", "output": "1500000000000" }, { "input": "5 10 1", "output": "50" }, { "input": "1 15 10", "output": "15000000000" }, { "input": "3 13 2", "output": "390" } ]
1,660,557,157
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
77
204,800
a,b,n=map(int, input().split()) num = a flag=0 ans=str(a) for i in range(n): if num%b==0: ans+="0" else: ost = (num*10)%b if (b-ost)>9: print(-1) flag=1 break else: #num = (num*10)+b-ost ans+=str(b-ost) num = 0 if flag==0: print(ans)
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. Input Specification: The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). Output Specification: In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. Demo Input: ['5 4 5\n', '12 11 1\n', '260 150 10\n'] Demo Output: ['524848\n', '121\n', '-1\n'] Note: none
```python a,b,n=map(int, input().split()) num = a flag=0 ans=str(a) for i in range(n): if num%b==0: ans+="0" else: ost = (num*10)%b if (b-ost)>9: print(-1) flag=1 break else: #num = (num*10)+b-ost ans+=str(b-ost) num = 0 if flag==0: print(ans) ```
0
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,579,110,279
2,147,483,647
Python 3
OK
TESTS
39
109
307,200
a = int(input()) x = [] y = [] res = [] for i in range(a**2): a = [i for i in input().split()] if a[0] not in x and a[1] not in y: res.append(int(i)+1) x.append(a[0]) y.append(a[1]) print(*res)
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 a = int(input()) x = [] y = [] res = [] for i in range(a**2): a = [i for i in input().split()] if a[0] not in x and a[1] not in y: res.append(int(i)+1) x.append(a[0]) y.append(a[1]) print(*res) ```
3
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it? You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=&lt;<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1. A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1. Find the length of the longest almost constant range.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 2 1", "output": "3" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9", "output": "3" }, { "input": "3\n1 2 2", "output": "3" }, { "input": "4\n10 9 10 9", "output": "4" }, { "input": "4\n4 3 2 3", "output": "3" }, { "input": "4\n8 8 7 7", "output": "4" }, { "input": "3\n99998 99999 100000", "output": "2" }, { "input": "3\n100000 99999 99998", "output": "2" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "2\n99999 100000", "output": "2" }, { "input": "2\n100000 100000", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "15" } ]
1,621,024,660
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
77
0
n = int(input()) arr = list(map(int, input().split())) maxi = (-1)*1e10 for i in range(len(arr)): cnt = 0 for j in range(i, len(arr)): if abs(arr[j] - arr[i]) > 1: maxi = max(maxi, cnt) break else: cnt += 1 print(maxi)
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it? You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=&lt;<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1. A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1. Find the length of the longest almost constant range. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). Output Specification: Print a single number — the maximum length of an almost constant range of the given sequence. Demo Input: ['5\n1 2 3 3 2\n', '11\n5 4 5 5 6 7 8 8 8 7 6\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
```python n = int(input()) arr = list(map(int, input().split())) maxi = (-1)*1e10 for i in range(len(arr)): cnt = 0 for j in range(i, len(arr)): if abs(arr[j] - arr[i]) > 1: maxi = max(maxi, cnt) break else: cnt += 1 print(maxi) ```
0
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,575,912,581
2,147,483,647
Python 3
OK
TESTS
45
248
0
n, k = [int(i) for i in input().split()] #int(input()) corr = [int(i) for i in input().split()] wrong = [int(i) for i in input().split()] max_corr = max(corr) min_corr = min(corr) min_wrong = min(wrong) best_tl = max(max_corr, 2*min_corr) if best_tl<min_wrong: print(best_tl) else: print(-1)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python n, k = [int(i) for i in input().split()] #int(input()) corr = [int(i) for i in input().split()] wrong = [int(i) for i in input().split()] max_corr = max(corr) min_corr = min(corr) min_wrong = min(wrong) best_tl = max(max_corr, 2*min_corr) if best_tl<min_wrong: print(best_tl) else: print(-1) ```
3
740
B
Alyona and flowers
PROGRAMMING
1,200
[ "constructive algorithms" ]
null
null
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in. For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then: - the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays. Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this! Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100). The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Each subarray can encounter more than once.
Print single integer — the maximum possible value added to the Alyona's happiness.
[ "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n", "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n", "2 2\n-1 -2\n1 1\n1 2\n" ]
[ "7\n", "16\n", "0\n" ]
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
1,000
[ { "input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7" }, { "input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16" }, { "input": "2 2\n-1 -2\n1 1\n1 2", "output": "0" }, { "input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5", "output": "8" }, { "input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3", "output": "10" }, { "input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8", "output": "0" }, { "input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2", "output": "0" }, { "input": "3 3\n1 -1 3\n1 2\n2 3\n1 3", "output": "5" }, { "input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6", "output": "13" }, { "input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4", "output": "50" }, { "input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5", "output": "0" }, { "input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3", "output": "59" }, { "input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3", "output": "67" }, { "input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35", "output": "170" }, { "input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13", "output": "1502" }, { "input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54", "output": "804" }, { "input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5", "output": "103" }, { "input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3", "output": "121" }, { "input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2", "output": "27" }, { "input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7", "output": "0" }, { "input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5", "output": "26" }, { "input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3", "output": "261" }, { "input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6", "output": "81" }, { "input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5", "output": "163" }, { "input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3", "output": "0" }, { "input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8", "output": "74" }, { "input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7", "output": "0" }, { "input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5", "output": "72" }, { "input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4", "output": "79" }, { "input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4", "output": "0" }, { "input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9", "output": "0" }, { "input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3", "output": "127" }, { "input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3", "output": "140" }, { "input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3", "output": "22" }, { "input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4", "output": "6" }, { "input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71", "output": "3076" }, { "input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27", "output": "1366" }, { "input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6", "output": "777" }, { "input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62", "output": "82" }, { "input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4", "output": "140" }, { "input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2", "output": "9" }, { "input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4", "output": "120" } ]
1,479,988,553
2,147,483,647
Python 3
OK
TESTS
53
78
0
inp = [int(x) for x in input().split()] l = [int(x) for x in input().split()] total = 0 ans = 0 for x in range(inp[1]): val = [int(y) for y in input().split()] total = sum(l[val[0]-1:val[1]]) if(total > 0): ans = ans + total print(ans)
Title: Alyona and flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in. For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then: - the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays. Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this! Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100). The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Each subarray can encounter more than once. Output Specification: Print single integer — the maximum possible value added to the Alyona's happiness. Demo Input: ['5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n', '4 3\n1 2 3 4\n1 3\n2 4\n1 1\n', '2 2\n-1 -2\n1 1\n1 2\n'] Demo Output: ['7\n', '16\n', '0\n'] Note: The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
```python inp = [int(x) for x in input().split()] l = [int(x) for x in input().split()] total = 0 ans = 0 for x in range(inp[1]): val = [int(y) for y in input().split()] total = sum(l[val[0]-1:val[1]]) if(total > 0): ans = ans + total print(ans) ```
3
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }, { "input": "1\n1\n4", "output": "0" }, { "input": "1\n2\n3", "output": "0" }, { "input": "1\n1000\n1000", "output": "7" }, { "input": "1000\n1\n1000", "output": "0" }, { "input": "1000\n2\n1000", "output": "7" }, { "input": "1000\n500\n1000", "output": "1750" }, { "input": "1000\n1000\n4", "output": "7" }, { "input": "1000\n1000\n3", "output": "0" }, { "input": "4\n8\n12", "output": "21" }, { "input": "10\n20\n40", "output": "70" }, { "input": "100\n200\n399", "output": "693" }, { "input": "200\n400\n800", "output": "1400" }, { "input": "199\n400\n800", "output": "1393" }, { "input": "201\n400\n800", "output": "1400" }, { "input": "200\n399\n800", "output": "1393" }, { "input": "200\n401\n800", "output": "1400" }, { "input": "200\n400\n799", "output": "1393" }, { "input": "200\n400\n801", "output": "1400" }, { "input": "139\n252\n871", "output": "882" }, { "input": "109\n346\n811", "output": "763" }, { "input": "237\n487\n517", "output": "903" }, { "input": "161\n331\n725", "output": "1127" }, { "input": "39\n471\n665", "output": "273" }, { "input": "9\n270\n879", "output": "63" }, { "input": "137\n422\n812", "output": "959" }, { "input": "15\n313\n525", "output": "105" }, { "input": "189\n407\n966", "output": "1323" }, { "input": "18\n268\n538", "output": "126" }, { "input": "146\n421\n978", "output": "1022" }, { "input": "70\n311\n685", "output": "490" }, { "input": "244\n405\n625", "output": "1092" }, { "input": "168\n454\n832", "output": "1176" }, { "input": "46\n344\n772", "output": "322" }, { "input": "174\n438\n987", "output": "1218" }, { "input": "144\n387\n693", "output": "1008" }, { "input": "22\n481\n633", "output": "154" }, { "input": "196\n280\n848", "output": "980" }, { "input": "190\n454\n699", "output": "1218" }, { "input": "231\n464\n928", "output": "1617" }, { "input": "151\n308\n616", "output": "1057" }, { "input": "88\n182\n364", "output": "616" }, { "input": "12\n26\n52", "output": "84" }, { "input": "204\n412\n824", "output": "1428" }, { "input": "127\n256\n512", "output": "889" }, { "input": "224\n446\n896", "output": "1561" }, { "input": "146\n291\n584", "output": "1015" }, { "input": "83\n164\n332", "output": "574" }, { "input": "20\n38\n80", "output": "133" }, { "input": "198\n393\n792", "output": "1372" }, { "input": "120\n239\n480", "output": "833" }, { "input": "208\n416\n831", "output": "1449" }, { "input": "130\n260\n517", "output": "903" }, { "input": "67\n134\n267", "output": "462" }, { "input": "245\n490\n979", "output": "1708" }, { "input": "182\n364\n727", "output": "1267" }, { "input": "104\n208\n413", "output": "721" }, { "input": "10\n2\n100", "output": "7" }, { "input": "2\n100\n100", "output": "14" }, { "input": "2\n3\n8", "output": "7" }, { "input": "1\n2\n8", "output": "7" }, { "input": "1\n2\n200", "output": "7" }, { "input": "5\n4\n16", "output": "14" }, { "input": "1\n10\n10", "output": "7" }, { "input": "1\n4\n8", "output": "7" }, { "input": "100\n4\n1000", "output": "14" }, { "input": "2\n6\n12", "output": "14" }, { "input": "10\n7\n4", "output": "7" }, { "input": "2\n10\n100", "output": "14" }, { "input": "2\n3\n4", "output": "7" }, { "input": "1\n2\n999", "output": "7" }, { "input": "1\n10\n20", "output": "7" }, { "input": "100\n18\n20", "output": "35" }, { "input": "100\n1\n100", "output": "0" }, { "input": "3\n7\n80", "output": "21" }, { "input": "2\n8\n24", "output": "14" }, { "input": "1\n100\n100", "output": "7" }, { "input": "2\n1\n8", "output": "0" }, { "input": "10\n5\n23", "output": "14" } ]
1,609,357,406
2,147,483,647
Python 3
OK
TESTS
84
109
0
a=int(input()) b=int(input()) c=int(input()) for i in range (a,-1,-1): if(b>=2*i and c>=4*i): print(7*i) break elif(i==0): print(0)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. Input Specification: The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. Output Specification: Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. Demo Input: ['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n'] Demo Output: ['7\n', '21\n', '0\n'] Note: In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
```python a=int(input()) b=int(input()) c=int(input()) for i in range (a,-1,-1): if(b>=2*i and c>=4*i): print(7*i) break elif(i==0): print(0) ```
3
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 999", "output": "339" }, { "input": "32 62 92", "output": "62" }, { "input": "123456789 123456789 123456789", "output": "123456789" }, { "input": "3 5 5", "output": "4" }, { "input": "666806767 385540591 357848286", "output": "470065214" }, { "input": "80010646 727118126 817880463", "output": "541669744" }, { "input": "829651016 732259171 572879931", "output": "711596705" }, { "input": "242854896 442432924 180395753", "output": "288561190" }, { "input": "139978911 5123031 935395222", "output": "360165721" }, { "input": "553182792 10264076 395427398", "output": "319624755" }, { "input": "597790453 720437830 855459575", "output": "724562619" }, { "input": "494914467 356982656 757942689", "output": "536613270" }, { "input": "908118348 67156409 217974865", "output": "397749873" }, { "input": "952726009 629846517 972974334", "output": "851848953" }, { "input": "775140200 616574841 630329230", "output": "674014756" }, { "input": "524780569 326748594 90361407", "output": "313963523" }, { "input": "937984449 184405994 992844522", "output": "705078321" }, { "input": "835108464 525983528 452876698", "output": "604656229" }, { "input": "879716125 531124573 207876166", "output": "539572288" }, { "input": "292920005 241298326 667908343", "output": "400708891" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1000000000 999999999 999999998", "output": "999999998" }, { "input": "999999998 999999998 999999999", "output": "999999998" }, { "input": "0 1 1", "output": "0" }, { "input": "0 1000000000 0", "output": "333333333" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 2 2", "output": "0" }, { "input": "3 3 5", "output": "3" }, { "input": "2 2 0", "output": "0" }, { "input": "0 5 5", "output": "2" }, { "input": "2 0 11", "output": "3" }, { "input": "9 9 7", "output": "8" }, { "input": "65 30 74", "output": "56" } ]
1,634,912,512
2,147,483,647
PyPy 3-64
OK
TESTS
40
122
28,364,800
r,g,b=map(int,input().split()) ans=0 for i in range(3): t=0 rt=r gt=g bt=b if rt>=i and gt>=i and bt>=i: rt-=i gt-=i bt-=i t+=i t+=rt//3+gt//3+bt//3 ans=max(ans,t) print(ans)
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make. Input Specification: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. Output Specification: Print the maximal number of bouquets Fox Ciel can make. Demo Input: ['3 6 9\n', '4 4 4\n', '0 0 0\n'] Demo Output: ['6\n', '4\n', '0\n'] Note: In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
```python r,g,b=map(int,input().split()) ans=0 for i in range(3): t=0 rt=r gt=g bt=b if rt>=i and gt>=i and bt>=i: rt-=i gt-=i bt-=i t+=i t+=rt//3+gt//3+bt//3 ans=max(ans,t) print(ans) ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,689,314,936
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
s = input() check = s.replace("WUB","") print(check)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s = input() check = s.replace("WUB","") print(check) ```
0
416
A
Guess a number!
PROGRAMMING
1,400
[ "greedy", "implementation", "two pointers" ]
null
null
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that *y* is strictly larger than number *x*? - Is it true that *y* is strictly smaller than number *x*? - Is it true that *y* is larger than or equal to number *x*? - Is it true that *y* is smaller than or equal to number *x*? On each question the host answers truthfully, "yes" or "no". Given the sequence of questions and answers, find any integer value of *y* that meets the criteria of all answers. If there isn't such value, print "Impossible".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - "&gt;" (for the first type queries), - "&lt;" (for the second type queries), - "&gt;=" (for the third type queries), - "&lt;=" (for the fourth type queries). All values of *x* are integer and meet the inequation <=-<=109<=≤<=*x*<=≤<=109. The answer is an English letter "Y" (for "yes") or "N" (for "no"). Consequtive elements in lines are separated by a single space.
Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
[ "4\n&gt;= 1 Y\n&lt; 3 N\n&lt;= -3 N\n&gt; 55 N\n", "2\n&gt; 100 Y\n&lt; -100 Y\n" ]
[ "17\n", "Impossible\n" ]
none
500
[ { "input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17" }, { "input": "2\n> 100 Y\n< -100 Y", "output": "Impossible" }, { "input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N", "output": "1" }, { "input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y", "output": "1" }, { "input": "4\n< 10 Y\n> -6 Y\n< 10 Y\n< -10 N", "output": "-5" }, { "input": "1\n< 1 N", "output": "1361956" }, { "input": "1\n<= 1 Y", "output": "-1998638045" }, { "input": "1\n> 1 N", "output": "-1998638045" }, { "input": "1\n>= 1 Y", "output": "1361956" }, { "input": "4\n< 1 N\n< 1 N\n< 1 N\n<= 1 Y", "output": "1" }, { "input": "4\n< 1 N\n>= 1 Y\n< 1 N\n< 1 N", "output": "1361956" }, { "input": "4\n> 1 N\n<= 1 Y\n<= 1 Y\n> 1 N", "output": "-1998638045" }, { "input": "4\n>= 1 Y\n> 1 N\n>= 1 Y\n>= 1 Y", "output": "1" }, { "input": "4\n<= 9 Y\n< 3 Y\n< 2 Y\n< 2 Y", "output": "-1998638045" }, { "input": "4\n< 0 N\n< -7 N\n>= 8 N\n>= -5 Y", "output": "3" }, { "input": "4\n<= -6 N\n<= -8 N\n<= 3 Y\n<= 7 Y", "output": "-2" }, { "input": "4\n>= 7 N\n<= -1 N\n>= 5 N\n<= -10 N", "output": "0" }, { "input": "4\n> 5 N\n>= -5 Y\n> -9 Y\n> -9 Y", "output": "-4" }, { "input": "10\n<= -60 N\n>= -59 Y\n> 22 Y\n> 95 N\n<= 91 Y\n> 77 Y\n>= -59 Y\n> -25 Y\n> -22 Y\n>= 52 Y", "output": "85" }, { "input": "10\n>= -18 Y\n>= -35 Y\n> -94 Y\n< -23 N\n< -69 N\n< -68 N\n< 82 Y\n> 92 N\n< 29 Y\n>= -25 Y", "output": "18" }, { "input": "10\n>= 18 Y\n<= -32 N\n>= 85 N\n<= 98 Y\n<= -43 N\n<= -79 N\n>= 97 N\n< -38 N\n< -55 N\n<= -93 N", "output": "64" }, { "input": "10\n<= 2 Y\n< -33 Y\n> 6 N\n> -6 N\n< -28 Y\n> -62 Y\n< 57 Y\n<= 24 Y\n> 23 N\n> -25 N", "output": "-54" }, { "input": "10\n<= -31 N\n>= 66 N\n<= 0 Y\n> -95 Y\n< 27 Y\n< -42 N\n> 3 N\n< 6 Y\n>= -42 Y\n> -70 Y", "output": "-29" }, { "input": "10\n>= 54 N\n<= -52 N\n>= 64 N\n> 65 N\n< 37 Y\n> -84 Y\n>= -94 Y\n>= -95 Y\n> -72 Y\n<= 18 N", "output": "22" }, { "input": "10\n> -24 N\n<= -5 Y\n<= -33 Y\n> 45 N\n> -59 Y\n> -21 N\n<= -48 N\n> 40 N\n< 12 Y\n>= 14 N", "output": "-47" }, { "input": "10\n>= 91 Y\n>= -68 Y\n< 92 N\n>= -15 Y\n> 51 Y\n<= 14 N\n> 17 Y\n< 94 Y\n>= 49 Y\n> -36 Y", "output": "93" }, { "input": "1\n< -1000000000 Y", "output": "-1998638045" }, { "input": "1\n< 1 Y", "output": "-1998638045" }, { "input": "1\n>= -999999999 Y", "output": "-998638044" }, { "input": "1\n> 100000 Y", "output": "1461956" }, { "input": "1\n<= 999999999 Y", "output": "-1998638045" }, { "input": "1\n<= 1000000000 N", "output": "1001361956" }, { "input": "4\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y", "output": "-1998638045" }, { "input": "1\n>= 1000000000 Y", "output": "1001361955" }, { "input": "1\n<= 999999999 N", "output": "1001361955" }, { "input": "1\n<= 100 Y", "output": "-1998638045" }, { "input": "1\n> 1000000000 Y", "output": "1001361956" }, { "input": "1\n<= 1 Y", "output": "-1998638045" }, { "input": "1\n<= 1000000000 Y", "output": "-1998638045" }, { "input": "1\n<= -1000000000 Y", "output": "-1998638045" }, { "input": "1\n<= -999999999 Y", "output": "-1998638045" }, { "input": "1\n> 100 Y", "output": "1362056" }, { "input": "2\n< -1000000000 Y\n< 3 Y", "output": "-1998638045" }, { "input": "1\n<= -1000000 Y", "output": "-1998638045" }, { "input": "8\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y\n< -1000000000 Y", "output": "-1998638045" }, { "input": "1\n<= 15 Y", "output": "-1998638045" }, { "input": "1\n< 1000000000 Y", "output": "-1998638045" }, { "input": "1\n> 10000000 Y", "output": "11361956" }, { "input": "1\n< 0 Y", "output": "-1998638045" }, { "input": "1\n< 100 Y", "output": "-1998638045" }, { "input": "1\n<= 5 Y", "output": "-1998638045" }, { "input": "3\n> 5 Y\n> 0 Y\n< 4 Y", "output": "Impossible" }, { "input": "1\n>= -1000000000 N", "output": "-1998638045" }, { "input": "3\n>= 1 Y\n<= 1 Y\n> 10 Y", "output": "Impossible" }, { "input": "2\n> 1 Y\n< 2 Y", "output": "Impossible" }, { "input": "3\n>= 5 Y\n<= 5 Y\n< 5 Y", "output": "Impossible" }, { "input": "2\n>= 5 N\n> 5 Y", "output": "Impossible" }, { "input": "3\n>= 4 Y\n> 4 Y\n<= 4 Y", "output": "Impossible" }, { "input": "2\n>= 4 Y\n> 4 Y", "output": "1361960" } ]
1,642,654,100
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
l=-2e9 r=2e9 n=int(input()) for i in range(0,n): listi=input().split() f=int(listi[1]) if listi[-1]=='Y': if listi[0]=='>=': l=f if listi[0]=='>': l=f+1 if listi[0]=='<=': r=f if listi[0]=='<': r=f-1 else: if listi[0]=='>=': r=f-1 if listi[0]=='>': r=f if listi[0]=='<=': l=f+1 if listi[0]=='<': l=f if l<=r: print(l) else: print("Impossible")
Title: Guess a number! Time Limit: None seconds Memory Limit: None megabytes Problem Description: A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that *y* is strictly larger than number *x*? - Is it true that *y* is strictly smaller than number *x*? - Is it true that *y* is larger than or equal to number *x*? - Is it true that *y* is smaller than or equal to number *x*? On each question the host answers truthfully, "yes" or "no". Given the sequence of questions and answers, find any integer value of *y* that meets the criteria of all answers. If there isn't such value, print "Impossible". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - "&gt;" (for the first type queries), - "&lt;" (for the second type queries), - "&gt;=" (for the third type queries), - "&lt;=" (for the fourth type queries). All values of *x* are integer and meet the inequation <=-<=109<=≤<=*x*<=≤<=109. The answer is an English letter "Y" (for "yes") or "N" (for "no"). Consequtive elements in lines are separated by a single space. Output Specification: Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). Demo Input: ['4\n&gt;= 1 Y\n&lt; 3 N\n&lt;= -3 N\n&gt; 55 N\n', '2\n&gt; 100 Y\n&lt; -100 Y\n'] Demo Output: ['17\n', 'Impossible\n'] Note: none
```python l=-2e9 r=2e9 n=int(input()) for i in range(0,n): listi=input().split() f=int(listi[1]) if listi[-1]=='Y': if listi[0]=='>=': l=f if listi[0]=='>': l=f+1 if listi[0]=='<=': r=f if listi[0]=='<': r=f-1 else: if listi[0]=='>=': r=f-1 if listi[0]=='>': r=f if listi[0]=='<=': l=f+1 if listi[0]=='<': l=f if l<=r: print(l) else: print("Impossible") ```
0
373
B
Making Sequences is Fun
PROGRAMMING
1,600
[ "binary search", "implementation", "math" ]
null
null
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence. You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
The first line should contain a single integer — the answer to the problem.
[ "9 1 1\n", "77 7 7\n", "114 5 14\n", "1 1 2\n" ]
[ "9\n", "7\n", "6\n", "0\n" ]
none
1,000
[ { "input": "9 1 1", "output": "9" }, { "input": "77 7 7", "output": "7" }, { "input": "114 5 14", "output": "6" }, { "input": "1 1 2", "output": "0" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "10000000000000000 1 1", "output": "674074074074073" }, { "input": "2155990066796462 2710473050636183 563261158", "output": "239230" }, { "input": "552719169048748 7822730034794389 374302919", "output": "92291" }, { "input": "6895788044242644 3474119895793364 732614708", "output": "588285" }, { "input": "9230573804495452 8577408935470783 90893866", "output": "6347082" }, { "input": "5363062262667637 2932858345469643 449197576", "output": "746200" }, { "input": "1951414609070432 8979282171178729 260239468", "output": "468658" }, { "input": "6289344232651169 4170875805886064 618522710", "output": "635520" }, { "input": "111984789523940 8017182602114316 976839488", "output": "7164" }, { "input": "3663662721733869 4845943245608254 787880219", "output": "290626" }, { "input": "10000000000000000 10000000000000000 1", "output": "588235294117647" }, { "input": "10000000000000000 9999999999999999 1", "output": "588235294117647" }, { "input": "9999999999999999 1 1", "output": "674074074074073" }, { "input": "3 1 4", "output": "0" }, { "input": "9999999999999998 1 1", "output": "674074074074072" }, { "input": "1 1000000000000000 1", "output": "0" }, { "input": "1 1000000000000000 1000000000", "output": "0" }, { "input": "10000000000000000 10000000000000000 1000000000", "output": "588235" }, { "input": "10000000000000000 10000000000000000 1", "output": "588235294117647" }, { "input": "121212121 3434343434 56", "output": "216450" }, { "input": "1 1 1", "output": "1" }, { "input": "98 55 1", "output": "47" }, { "input": "1 10000000000000000 123456", "output": "0" }, { "input": "10000000000000000 1000000000000001 1000000000", "output": "625000" } ]
1,563,651,338
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
2,000
409,600
a=input().split() l=len(a[1]) p=int(a[1]) d=10**l m=int(a[2]) w=int(a[0]) c=0 while l<w: r=min(int(w/(l*m)),d-p) c+=r w-=r*l*m p=d d*=10 l+=1 print(c)
Title: Making Sequences is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence. You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input Specification: The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: The first line should contain a single integer — the answer to the problem. Demo Input: ['9 1 1\n', '77 7 7\n', '114 5 14\n', '1 1 2\n'] Demo Output: ['9\n', '7\n', '6\n', '0\n'] Note: none
```python a=input().split() l=len(a[1]) p=int(a[1]) d=10**l m=int(a[2]) w=int(a[0]) c=0 while l<w: r=min(int(w/(l*m)),d-p) c+=r w-=r*l*m p=d d*=10 l+=1 print(c) ```
0
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,669,999,168
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
60
0
n, k = map(int,input().split()) a = list(map(int,input().split())) print(a[k])
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 n, k = map(int,input().split()) a = list(map(int,input().split())) print(a[k]) ```
0
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,665,137,409
2,147,483,647
PyPy 3-64
OK
TESTS
118
140
16,281,600
n,k=map(int,input().split()) arr=list(map(int,input().split())) dp=[0]*(n) arr=[el-1 for el in arr] for i in range(n): if arr[i]==-1: dp[i]=1+min(n-1-i,k)+min(k,i) else : dp[i]=dp[arr[i]]+min(1+min(n-1-i,k)+min(i,k),min(n-1,i+k)-min(n-1,arr[i]+k)) print(*dp)
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 n,k=map(int,input().split()) arr=list(map(int,input().split())) dp=[0]*(n) arr=[el-1 for el in arr] for i in range(n): if arr[i]==-1: dp[i]=1+min(n-1-i,k)+min(k,i) else : dp[i]=dp[arr[i]]+min(1+min(n-1-i,k)+min(i,k),min(n-1,i+k)-min(n-1,arr[i]+k)) print(*dp) ```
3
991
A
If at first you don't succeed...
PROGRAMMING
1,000
[ "implementation" ]
null
null
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group. Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
[ "10 10 5 20\n", "2 2 0 4\n", "2 2 2 1\n" ]
[ "5", "-1", "-1" ]
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible. The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
500
[ { "input": "10 10 5 20", "output": "5" }, { "input": "2 2 0 4", "output": "-1" }, { "input": "2 2 2 1", "output": "-1" }, { "input": "98 98 97 100", "output": "1" }, { "input": "1 5 2 10", "output": "-1" }, { "input": "5 1 2 10", "output": "-1" }, { "input": "6 7 5 8", "output": "-1" }, { "input": "6 7 5 9", "output": "1" }, { "input": "6 7 5 7", "output": "-1" }, { "input": "50 50 1 100", "output": "1" }, { "input": "8 3 2 12", "output": "3" }, { "input": "10 19 6 25", "output": "2" }, { "input": "1 0 0 99", "output": "98" }, { "input": "0 1 0 98", "output": "97" }, { "input": "1 1 0 97", "output": "95" }, { "input": "1 1 1 96", "output": "95" }, { "input": "0 0 0 0", "output": "-1" }, { "input": "100 0 0 0", "output": "-1" }, { "input": "0 100 0 0", "output": "-1" }, { "input": "100 100 0 0", "output": "-1" }, { "input": "0 0 100 0", "output": "-1" }, { "input": "100 0 100 0", "output": "-1" }, { "input": "0 100 100 0", "output": "-1" }, { "input": "100 100 100 0", "output": "-1" }, { "input": "0 0 0 100", "output": "100" }, { "input": "100 0 0 100", "output": "-1" }, { "input": "0 100 0 100", "output": "-1" }, { "input": "100 100 0 100", "output": "-1" }, { "input": "0 0 100 100", "output": "-1" }, { "input": "100 0 100 100", "output": "-1" }, { "input": "0 100 100 100", "output": "-1" }, { "input": "100 100 100 100", "output": "-1" }, { "input": "10 45 7 52", "output": "4" }, { "input": "38 1 1 68", "output": "30" }, { "input": "8 45 2 67", "output": "16" }, { "input": "36 36 18 65", "output": "11" }, { "input": "10 30 8 59", "output": "27" }, { "input": "38 20 12 49", "output": "3" }, { "input": "8 19 4 38", "output": "15" }, { "input": "36 21 17 72", "output": "32" }, { "input": "14 12 12 89", "output": "75" }, { "input": "38 6 1 44", "output": "1" }, { "input": "13 4 6 82", "output": "-1" }, { "input": "5 3 17 56", "output": "-1" }, { "input": "38 5 29 90", "output": "-1" }, { "input": "22 36 18 55", "output": "15" }, { "input": "13 0 19 75", "output": "-1" }, { "input": "62 65 10 89", "output": "-1" }, { "input": "2 29 31 72", "output": "-1" }, { "input": "1 31 19 55", "output": "-1" }, { "input": "1 25 28 88", "output": "-1" }, { "input": "34 32 28 33", "output": "-1" }, { "input": "43 36 1 100", "output": "22" }, { "input": "16 39 55 70", "output": "-1" }, { "input": "2 3 0 91", "output": "86" }, { "input": "55 29 12 48", "output": "-1" }, { "input": "7 33 20 88", "output": "-1" }, { "input": "40 38 27 99", "output": "48" }, { "input": "18 28 14 84", "output": "52" }, { "input": "34 25 25 92", "output": "58" }, { "input": "4 24 5 76", "output": "-1" }, { "input": "5 22 16 96", "output": "-1" }, { "input": "1 1 0 4", "output": "2" }, { "input": "5 5 3 1", "output": "-1" }, { "input": "0 0 0 1", "output": "1" }, { "input": "2 3 0 8", "output": "3" }, { "input": "5 5 2 5", "output": "-1" }, { "input": "1 2 1 3", "output": "1" }, { "input": "3 0 0 4", "output": "1" }, { "input": "0 0 0 5", "output": "5" }, { "input": "5 5 0 3", "output": "-1" }, { "input": "5 6 1 7", "output": "-1" }, { "input": "10 10 10 11", "output": "1" }, { "input": "0 0 0 10", "output": "10" }, { "input": "5 15 5 30", "output": "15" }, { "input": "3 2 0 7", "output": "2" } ]
1,548,725,565
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
108
0
a, b, c, n = map(int, input().split()) total = a + b - c if total >= n: print('-1') else: print(n - total)
Title: If at first you don't succeed... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group. Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time? Input Specification: The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). Output Specification: If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$. Demo Input: ['10 10 5 20\n', '2 2 0 4\n', '2 2 2 1\n'] Demo Output: ['5', '-1', '-1'] Note: The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible. The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
```python a, b, c, n = map(int, input().split()) total = a + b - c if total >= n: print('-1') else: print(n - total) ```
0
0
none
none
none
0
[ "none" ]
null
null
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are *n* (*n* is always even) possible starting positions for characters marked along the *Ox* axis. The positions are given by their distinct coordinates *x*1,<=*x*2,<=...,<=*x**n*, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be *n*<=-<=2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally.
The first line on the input contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000, *n* is even) — the number of positions available initially. The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109), giving the coordinates of the corresponding positions.
Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
[ "6\n0 1 3 7 15 31\n", "2\n73 37\n" ]
[ "7\n", "36\n" ]
In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 1. Lesha bans the position at coordinate 3; 1. Vova bans the position at coordinate 31; 1. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
0
[ { "input": "6\n0 1 3 7 15 31", "output": "7" }, { "input": "2\n73 37", "output": "36" }, { "input": "2\n0 1000000000", "output": "1000000000" }, { "input": "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782", "output": "470242129" }, { "input": "2\n0 1", "output": "1" }, { "input": "8\n552283832 997699491 89302459 301640204 288141798 31112026 710831619 862166501", "output": "521171806" }, { "input": "4\n0 500000000 500000001 1000000000", "output": "500000000" }, { "input": "18\n515925896 832652240 279975694 570998878 28122427 209724246 898414431 709461320 358922485 439508829 403574907 358500312 596248410 968234748 187793884 728450713 30350176 528924900", "output": "369950401" }, { "input": "20\n713900269 192811911 592111899 609607891 585084800 601258511 223103775 876894656 751583891 230837577 971499807 312977833 344314550 397998873 558637732 216574673 913028292 762852863 464376621 61315042", "output": "384683838" }, { "input": "10\n805513144 38998401 16228409 266085559 293487744 471510400 138613792 649258082 904651590 244678415", "output": "277259335" }, { "input": "6\n0 166666666 333333333 499999998 666666665 833333330", "output": "499999997" }, { "input": "16\n1 62500001 125000001 187500000 250000000 312500000 375000000 437500001 500000000 562500000 625000000 687500001 750000001 812500002 875000002 937500000", "output": "499999999" }, { "input": "12\n5 83333336 166666669 250000001 333333336 416666670 500000004 583333336 666666667 750000001 833333334 916666671", "output": "499999998" }, { "input": "20\n54 50000046 100000041 150000049 200000061 250000039 300000043 350000054 400000042 450000045 500000076 550000052 600000064 650000065 700000055 750000046 800000044 850000042 900000052 950000054", "output": "499999988" } ]
1,447,001,835
1,635
Python 3
SKIPPED
TESTS
0
46
204,800
__author__ = 'cmashinho' n = int(input()) l = list(map(int, input().split())) def findMax(): maxx = 0 coord = 0 for i in range(1, len(l)): if max(l[i], l[i - 1]) - min(l[i], l[i - 1]) > maxx: maxx = max(l[i], l[i - 1]) - min(l[i], l[i - 1]) coord = i - 1 return coord def findMin(): minn = 10 ** 18 coord = 0 for i in range(1, len(l)): if max(l[i], l[i - 1]) - min(l[i], l[i - 1]) < minn: minn = max(l[i], l[i - 1]) - min(l[i], l[i - 1]) coord = i - 1 return coord if n == 2: print(max(l) - min(l)) elif n == 3: minn = 10 ** 18 if max(l[0], l[1]) - min(l[0], l[1]) < minn: minn = max(l[0], l[1]) - min(l[0], l[1]) if max(l[1], l[2]) - min(l[1], l[2]) < minn: minn = max(l[1], l[2]) - min(l[1], l[2]) if max(l[0], l[2]) - min(l[0], l[2]) < minn: minn = max(l[0], l[2]) - min(l[0], l[2]) print(minn) else: current = 0 while(len(l) != 2): if current == 0: l.pop(findMax() + 1) current = 1 else: l.pop(findMin() + 1) current = 0 print(max(l) - min(l))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible. There are *n* (*n* is always even) possible starting positions for characters marked along the *Ox* axis. The positions are given by their distinct coordinates *x*1,<=*x*2,<=...,<=*x**n*, two characters cannot end up at the same position. Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be *n*<=-<=2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting. Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally. Input Specification: The first line on the input contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000, *n* is even) — the number of positions available initially. The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109), giving the coordinates of the corresponding positions. Output Specification: Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. Demo Input: ['6\n0 1 3 7 15 31\n', '2\n73 37\n'] Demo Output: ['7\n', '36\n'] Note: In the first sample one of the optimum behavior of the players looks like that: 1. Vova bans the position at coordinate 15; 1. Lesha bans the position at coordinate 3; 1. Vova bans the position at coordinate 31; 1. Lesha bans the position at coordinate 1. After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7. In the second sample there are only two possible positions, so there will be no bans.
```python __author__ = 'cmashinho' n = int(input()) l = list(map(int, input().split())) def findMax(): maxx = 0 coord = 0 for i in range(1, len(l)): if max(l[i], l[i - 1]) - min(l[i], l[i - 1]) > maxx: maxx = max(l[i], l[i - 1]) - min(l[i], l[i - 1]) coord = i - 1 return coord def findMin(): minn = 10 ** 18 coord = 0 for i in range(1, len(l)): if max(l[i], l[i - 1]) - min(l[i], l[i - 1]) < minn: minn = max(l[i], l[i - 1]) - min(l[i], l[i - 1]) coord = i - 1 return coord if n == 2: print(max(l) - min(l)) elif n == 3: minn = 10 ** 18 if max(l[0], l[1]) - min(l[0], l[1]) < minn: minn = max(l[0], l[1]) - min(l[0], l[1]) if max(l[1], l[2]) - min(l[1], l[2]) < minn: minn = max(l[1], l[2]) - min(l[1], l[2]) if max(l[0], l[2]) - min(l[0], l[2]) < minn: minn = max(l[0], l[2]) - min(l[0], l[2]) print(minn) else: current = 0 while(len(l) != 2): if current == 0: l.pop(findMax() + 1) current = 1 else: l.pop(findMin() + 1) current = 0 print(max(l) - min(l)) ```
-1
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,660,576,309
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
Tn=[] Ts=[] for _ in range(int(input())): S=input() Tn.append(S[:S.find(' ')]) Ts.append(int(S[S.find(' ')+1:])) if max(Ts)==Ts[-1] and Ts.count(max(Ts))==1: print(Tn[Ts.index(max(Ts[:-1]))]) else: print(Tn[Ts.index(max(Ts))])
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python Tn=[] Ts=[] for _ in range(int(input())): S=input() Tn.append(S[:S.find(' ')]) Ts.append(int(S[S.find(' ')+1:])) if max(Ts)==Ts[-1] and Ts.count(max(Ts))==1: print(Tn[Ts.index(max(Ts[:-1]))]) else: print(Tn[Ts.index(max(Ts))]) ```
0
235
A
LCM Challenge
PROGRAMMING
1,600
[ "number theory" ]
null
null
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
[ "9\n", "7\n" ]
[ "504\n", "210\n" ]
The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
500
[ { "input": "9", "output": "504" }, { "input": "7", "output": "210" }, { "input": "1", "output": "1" }, { "input": "5", "output": "60" }, { "input": "6", "output": "60" }, { "input": "33", "output": "32736" }, { "input": "21", "output": "7980" }, { "input": "2", "output": "2" }, { "input": "41", "output": "63960" }, { "input": "29", "output": "21924" }, { "input": "117", "output": "1560780" }, { "input": "149", "output": "3241644" }, { "input": "733", "output": "392222436" }, { "input": "925", "output": "788888100" }, { "input": "509", "output": "131096004" }, { "input": "829", "output": "567662724" }, { "input": "117", "output": "1560780" }, { "input": "605", "output": "220348260" }, { "input": "245", "output": "14526540" }, { "input": "925", "output": "788888100" }, { "input": "213", "output": "9527916" }, { "input": "53", "output": "140556" }, { "input": "341", "output": "39303660" }, { "input": "21", "output": "7980" }, { "input": "605", "output": "220348260" }, { "input": "149", "output": "3241644" }, { "input": "733", "output": "392222436" }, { "input": "117", "output": "1560780" }, { "input": "53", "output": "140556" }, { "input": "245", "output": "14526540" }, { "input": "829", "output": "567662724" }, { "input": "924", "output": "783776526" }, { "input": "508", "output": "130065780" }, { "input": "700", "output": "341042100" }, { "input": "636", "output": "254839470" }, { "input": "20", "output": "6460" }, { "input": "604", "output": "218891412" }, { "input": "796", "output": "501826260" }, { "input": "732", "output": "389016270" }, { "input": "412", "output": "69256788" }, { "input": "700", "output": "341042100" }, { "input": "244", "output": "14289372" }, { "input": "828", "output": "563559150" }, { "input": "508", "output": "130065780" }, { "input": "796", "output": "501826260" }, { "input": "636", "output": "254839470" }, { "input": "924", "output": "783776526" }, { "input": "245", "output": "14526540" }, { "input": "828", "output": "563559150" }, { "input": "21", "output": "7980" }, { "input": "605", "output": "220348260" }, { "input": "636", "output": "254839470" }, { "input": "924", "output": "783776526" }, { "input": "116", "output": "1507420" }, { "input": "700", "output": "341042100" }, { "input": "732", "output": "389016270" }, { "input": "20", "output": "6460" }, { "input": "508", "output": "130065780" }, { "input": "148", "output": "3154620" }, { "input": "828", "output": "563559150" }, { "input": "763116", "output": "444394078546562430" }, { "input": "756604", "output": "433115377058855412" }, { "input": "447244", "output": "89460162932862372" }, { "input": "372636", "output": "51742503205363470" }, { "input": "546924", "output": "163597318076822526" }, { "input": "540412", "output": "157823524476316788" }, { "input": "714700", "output": "365063922340784100" }, { "input": "520731", "output": "141201007712496270" }, { "input": "695019", "output": "335728459024850814" }, { "input": "688507", "output": "326379736779169710" }, { "input": "862795", "output": "642275489615199390" }, { "input": "668827", "output": "299184742915995150" }, { "input": "810411", "output": "532248411551110590" }, { "input": "836603", "output": "585540171302562606" }, { "input": "978187", "output": "935975171582120670" }, { "input": "816923", "output": "545182335484592526" }, { "input": "958507", "output": "880611813728059710" }, { "input": "984699", "output": "954792870629291694" }, { "input": "642635", "output": "265393998349453470" }, { "input": "296604", "output": "26092892528622606" }, { "input": "1000000", "output": "999996000003000000" }, { "input": "8", "output": "280" }, { "input": "3", "output": "6" }, { "input": "4", "output": "12" }, { "input": "30", "output": "21924" }, { "input": "18", "output": "4080" }, { "input": "12", "output": "990" } ]
1,559,187,059
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
31
310
0
import math n = int(input()) if(n<=2): print(n) exit() if(n%2!=0): print(n*(n-1)*(n-2)) else: print(max(((n*(n-2))//math.gcd(n,n-2))*(n-1),((n*(n-2))//math.gcd(n,n-3))*(n-1)))
Title: LCM Challenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. Output Specification: Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. Demo Input: ['9\n', '7\n'] Demo Output: ['504\n', '210\n'] Note: The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
```python import math n = int(input()) if(n<=2): print(n) exit() if(n%2!=0): print(n*(n-1)*(n-2)) else: print(max(((n*(n-2))//math.gcd(n,n-2))*(n-1),((n*(n-2))//math.gcd(n,n-3))*(n-1))) ```
0
839
A
Arya and Bran
PROGRAMMING
900
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
500
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "output": "18" }, { "input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "output": "30" }, { "input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47", "output": "40" }, { "input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9", "output": "-1" }, { "input": "37 30\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", "output": "30" }, { "input": "100 456\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": "57" }, { "input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100", "output": "38" }, { "input": "7 43\n4 3 7 9 3 8 10", "output": "-1" }, { "input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8", "output": "-1" }, { "input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8", "output": "-1" }, { "input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5", "output": "-1" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69", "output": "13" }, { "input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53", "output": "85" }, { "input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5", "output": "100" }, { "input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6", "output": "98" }, { "input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1", "output": "18" }, { "input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2", "output": "21" }, { "input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1", "output": "-1" }, { "input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91", "output": "45" }, { "input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90", "output": "-1" }, { "input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50", "output": "97" }, { "input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9", "output": "24" }, { "input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42", "output": "21" }, { "input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100", "output": "1" }, { "input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5", "output": "13" }, { "input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92", "output": "14" }, { "input": "2 16\n10 6", "output": "2" }, { "input": "2 8\n7 8", "output": "2" }, { "input": "2 9\n4 8", "output": "2" }, { "input": "3 19\n9 9 1", "output": "3" }, { "input": "4 32\n9 9 9 5", "output": "4" }, { "input": "2 15\n14 1", "output": "2" }, { "input": "2 3\n3 3", "output": "1" }, { "input": "3 10\n10 1 1", "output": "2" }, { "input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4", "output": "4" }, { "input": "4 15\n14 3 3 3", "output": "2" }, { "input": "5 40\n10 10 10 10 1", "output": "5" }, { "input": "4 31\n9 9 8 5", "output": "4" }, { "input": "4 31\n20 7 1 1", "output": "-1" }, { "input": "2 10\n9 1", "output": "2" }, { "input": "10 50\n100 10 1 1 1 1 1 1 1 1", "output": "7" }, { "input": "2 11\n10 2", "output": "2" }, { "input": "3 21\n10 10 1", "output": "3" }, { "input": "2 2\n1 2", "output": "2" }, { "input": "3 2\n1 8 8", "output": "2" }, { "input": "2 11\n10 1", "output": "2" }, { "input": "2 16\n12 4", "output": "2" }, { "input": "3 11\n9 2 2", "output": "2" }, { "input": "3 11\n4 3 4", "output": "3" }, { "input": "2 13\n7 6", "output": "2" }, { "input": "3 24\n14 3 4", "output": "-1" }, { "input": "2 13\n10 3", "output": "2" }, { "input": "3 11\n9 2 1", "output": "2" }, { "input": "2 15\n12 3", "output": "2" }, { "input": "2 14\n11 4", "output": "2" } ]
1,647,282,632
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
n,k=[int(i) for i in input().split()] konfeta=[int(i) for i in input().split()] sum_konfet=0 for i in range(0,n): sum_konfet+=konfeta[i] if k%8==0: min_kolvo_days=k//8 else: min_kolvo_days=k//8+1 if min_kolvo_days>n or sum_konfet<k: print(-1) else: print(n)
Title: Arya and Bran Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Demo Input: ['2 3\n1 2\n', '3 17\n10 10 10\n', '1 9\n10\n'] Demo Output: ['2', '3', '-1'] Note: In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
```python n,k=[int(i) for i in input().split()] konfeta=[int(i) for i in input().split()] sum_konfet=0 for i in range(0,n): sum_konfet+=konfeta[i] if k%8==0: min_kolvo_days=k//8 else: min_kolvo_days=k//8+1 if min_kolvo_days>n or sum_konfet<k: print(-1) else: print(n) ```
0
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 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 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "386 1 2747", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "123 2 50000", "output": "1 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 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,614,580,714
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
def potatoes(y, k ,n): arr = list(range(k, n, k)) arr = [i - y for i in arr if i-y >= 1] if len(arr) > 0: print(*arr) else: print(-1) y, k, n = map(int, input().split()) potatoes(y, k ,n)
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python def potatoes(y, k ,n): arr = list(range(k, n, k)) arr = [i - y for i in arr if i-y >= 1] if len(arr) > 0: print(*arr) else: print(-1) y, k, n = map(int, input().split()) potatoes(y, k ,n) ```
0
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,699,382,194
2,147,483,647
PyPy 3
OK
TESTS
71
186
0
s = input() og = '' i = 0 while i < len(s): if s[i:i+3] != "WUB": og = og + s[i] i = i + 1 else: if (len(og) != 0) and (og[-1] != " "): og = og + " " i = i + 3 print(og)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s = input() og = '' i = 0 while i < len(s): if s[i:i+3] != "WUB": og = og + s[i] i = i + 1 else: if (len(og) != 0) and (og[-1] != " "): og = og + " " i = i + 3 print(og) ```
3
644
A
Parliament of Berland
PROGRAMMING
1,000
[ "*special", "constructive algorithms" ]
null
null
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues. Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
[ "3 2 2\n", "8 4 3\n", "10 2 2\n" ]
[ "0 3\n1 2\n", "7 8 3\n0 1 4\n6 0 5\n0 2 0\n", "-1\n" ]
In the first sample there are many other possible solutions. For example, and The following assignment is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
500
[ { "input": "3 2 2", "output": "1 2 \n0 3 " }, { "input": "8 4 3", "output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 " }, { "input": "10 2 2", "output": "-1" }, { "input": "1 1 1", "output": "1 " }, { "input": "8 3 3", "output": "1 2 3 \n4 5 6 \n7 8 0 " }, { "input": "1 1 100", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "1 100 1", "output": "1 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 " }, { "input": "12 4 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 " }, { "input": "64 8 9", "output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 0 0 0 0 0 0 0 0 " }, { "input": "13 2 6", "output": "-1" }, { "input": "41 6 7", "output": "1 2 3 4 5 6 7 \n8 9 10 11 12 13 14 \n15 16 17 18 19 20 21 \n22 23 24 25 26 27 28 \n29 30 31 32 33 34 35 \n36 37 38 39 40 41 0 " }, { "input": "9999 100 100", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "10000 100 100", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2099 70 30", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 \n32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 \n61 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 \n92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n152 151 1..." }, { "input": "2098 30 70", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 \n72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 \n141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "10000 1 1", "output": "-1" }, { "input": "1583 49 36", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 \n38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 \n73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 \n110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153..." }, { "input": "4825 77 88", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "26 1 33", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 0 0 0 0 0 0 " }, { "input": "274 25 77", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 \n78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 \n..." }, { "input": "694 49 22", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "3585 77 62", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3 1 6", "output": "1 2 3 0 0 0 " }, { "input": "352 25 59", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 \n60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 \n119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "150 53 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 110 111 \n112 113 114 \n115 116 117 \n118 119 120 \n121 122 123 \n124 125 126 \n127 128 129 \n130 131 132 \n133..." }, { "input": "4227 91 80", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \n82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "378 19 25", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 \n76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 \n126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n151 152..." }, { "input": "2357 43 65", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "232 71 9", "output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 \n73 74 75 76 77 78 79 80 81 \n82 83 84 85 86 87 88 89 90 \n91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 \n109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 \n136 137 138 139 140 141 142 143 144 \n145 146 147..." }, { "input": "2362 91 62", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4601 59 78", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "4439 74 60", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \n62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3733 89 42", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 \n44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 \n85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 1..." }, { "input": "335 12 28", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 \n30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 \n57 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 \n86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 \n142 141 144 143 146 145 148 147 150 149 152 151 1..." }, { "input": "440 26 17", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \n18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 \n35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 \n103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 \n120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..." }, { "input": "109 37 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 0 0 " }, { "input": "4416 52 85", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5025 75 67", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 \n68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 \n135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4983 89 56", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "950 17 56", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "1637 40 41", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 \n42 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 \n83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 \n124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "1142 52 22", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "907 70 13", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 \n14 15 16 17 18 19 20 21 22 23 24 25 26 \n27 28 29 30 31 32 33 34 35 36 37 38 39 \n40 41 42 43 44 45 46 47 48 49 50 51 52 \n53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 \n79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 \n105 106 107 108 109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 \n144 145 146 147 148 149 1..." }, { "input": "7279 80 91", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1653 87 19", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 \n58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 \n115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 \n134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1..." }, { "input": "15 2 8", "output": "1 2 3 4 5 6 7 8 \n10 9 12 11 14 13 0 15 " }, { "input": "1459 17 86", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "3035 40 76", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 \n153 154..." }, { "input": "3095 50 62", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3055 65 47", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 \n48 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 \n95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 \n142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "2638 80 33", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 \n34 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 \n67 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 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "29 3 11", "output": "1 2 3 4 5 6 7 8 9 10 11 \n12 13 14 15 16 17 18 19 20 21 22 \n23 24 25 26 27 28 29 0 0 0 0 " }, { "input": "16 18 1", "output": "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n0 \n0 " }, { "input": "2240 27 83", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 \n84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1264 55 23", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \n24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 \n47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \n70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 \n116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 \n139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "5400 75 72", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 \n74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153 154..." }, { "input": "46 3 16", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 \n33 34 35 36 37 38 39 40 41 42 43 44 45 46 0 0 " }, { "input": "1512 27 56", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4206 86 12", "output": "-1" }, { "input": "2358 14 56", "output": "-1" }, { "input": "5420 35 96", "output": "-1" }, { "input": "7758 63 41", "output": "-1" }, { "input": "9806 87 93", "output": "-1" }, { "input": "99 1 97", "output": "-1" }, { "input": "1053 25 42", "output": "-1" }, { "input": "4217 49 86", "output": "-1" }, { "input": "2312 77 30", "output": "-1" }, { "input": "74 1 71", "output": "-1" }, { "input": "1 99 100", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "1 57 99", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "4785 55 87", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "4611 53 87", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "9801 99 99", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "8096 92 88", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "5916 68 87", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "8928 93 96", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \n98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "7743 89 87", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "3128 46 68", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3800 40 95", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5368 61 88", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2583 41 63", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4056 52 78", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "3822 42 91", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5358 57 94", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 \n96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2961 47 63", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." } ]
1,458,235,636
116,836
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
# :) l = raw_input().split(" ") n = int(l[0]) a = int(l[1]) b = int(l[2]) Matrix = [[0 for x in range(b)] for x in range(a)] alter = -1 odd_even = [1,2] if a*b < n: print -1, else: for i in range(a): alter += 1 row = i col = 0 while(row>=0 and row<a and col>=0 and col<b): if odd_even[alter%2] <= n: Matrix[row][col] = odd_even[alter%2] odd_even[alter%2] += 2 else: Matrix[row][col] = 0 row -= 1 col += 1 for j in range(1,b): alter += 1 row = a-1 col = j while(row>=0 and row<a and col>=0 and col<b): if odd_even[alter%2] <= n: Matrix[row][col] = odd_even[alter%2] odd_even[alter%2] += 2 else: Matrix[row][col] = 0 row -= 1 col += 1 for i in range(a): for j in range(b): print Matrix[i][j], if i != (a-1): print
Title: Parliament of Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues. Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats. Input Specification: The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. Output Specification: If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them. Demo Input: ['3 2 2\n', '8 4 3\n', '10 2 2\n'] Demo Output: ['0 3\n1 2\n', '7 8 3\n0 1 4\n6 0 5\n0 2 0\n', '-1\n'] Note: In the first sample there are many other possible solutions. For example, and The following assignment is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
```python # :) l = raw_input().split(" ") n = int(l[0]) a = int(l[1]) b = int(l[2]) Matrix = [[0 for x in range(b)] for x in range(a)] alter = -1 odd_even = [1,2] if a*b < n: print -1, else: for i in range(a): alter += 1 row = i col = 0 while(row>=0 and row<a and col>=0 and col<b): if odd_even[alter%2] <= n: Matrix[row][col] = odd_even[alter%2] odd_even[alter%2] += 2 else: Matrix[row][col] = 0 row -= 1 col += 1 for j in range(1,b): alter += 1 row = a-1 col = j while(row>=0 and row<a and col>=0 and col<b): if odd_even[alter%2] <= n: Matrix[row][col] = odd_even[alter%2] odd_even[alter%2] += 2 else: Matrix[row][col] = 0 row -= 1 col += 1 for i in range(a): for j in range(b): print Matrix[i][j], if i != (a-1): print ```
-1
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "input": "9149", "output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..." }, { "input": "2877", "output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..." }, { "input": "2956", "output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..." }, { "input": "3035", "output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..." }, { "input": "3114", "output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..." }, { "input": "3193", "output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..." }, { "input": "3273", "output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..." }, { "input": "7000", "output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..." }, { "input": "7079", "output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..." }, { "input": "4653", "output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..." }, { "input": "9995", "output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..." }, { "input": "9996", "output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..." }, { "input": "9997", "output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..." }, { "input": "9998", "output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..." }, { "input": "9999", "output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..." }, { "input": "10000", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..." } ]
1,643,366,404
2,147,483,647
Python 3
OK
TESTS
22
122
0
import math def main_function(): n = int(input()) current_ = 1 direction_plus = True dif = n - 1 for i in range(n): if i == 0: print(1, end=" ") elif i != n - 1: if direction_plus: print(dif + current_, end=" ") current_ += dif else: print(current_ - dif, end=" ") current_ -= dif dif -= 1 direction_plus = not direction_plus else: if direction_plus: print(dif + current_) current_ += dif else: print(current_ - dif,) current_ -= dif dif -= 1 direction_plus = not direction_plus main_function()
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. Input Specification: The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. Output Specification: Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any. Demo Input: ['2\n', '3\n'] Demo Output: ['1 2 ', '1 3 2 '] Note: none
```python import math def main_function(): n = int(input()) current_ = 1 direction_plus = True dif = n - 1 for i in range(n): if i == 0: print(1, end=" ") elif i != n - 1: if direction_plus: print(dif + current_, end=" ") current_ += dif else: print(current_ - dif, end=" ") current_ -= dif dif -= 1 direction_plus = not direction_plus else: if direction_plus: print(dif + current_) current_ += dif else: print(current_ - dif,) current_ -= dif dif -= 1 direction_plus = not direction_plus main_function() ```
3.9695
691
B
s-palindrome
PROGRAMMING
1,600
[ "implementation", "strings" ]
null
null
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the string is "s-palindrome".
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters.
Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise.
[ "oXoxoXo\n", "bod\n", "ER\n" ]
[ "TAK\n", "TAK\n", "NIE\n" ]
none
0
[ { "input": "oXoxoXo", "output": "TAK" }, { "input": "bod", "output": "TAK" }, { "input": "ER", "output": "NIE" }, { "input": "o", "output": "TAK" }, { "input": "a", "output": "NIE" }, { "input": "opo", "output": "NIE" }, { "input": "HCMoxkgbNb", "output": "NIE" }, { "input": "vMhhXCMWDe", "output": "NIE" }, { "input": "iIcamjTRFH", "output": "NIE" }, { "input": "WvoWvvWovW", "output": "TAK" }, { "input": "WXxAdbAxXW", "output": "TAK" }, { "input": "vqMTUUTMpv", "output": "TAK" }, { "input": "iii", "output": "NIE" }, { "input": "AAWW", "output": "NIE" }, { "input": "ss", "output": "NIE" }, { "input": "i", "output": "NIE" }, { "input": "ii", "output": "NIE" }, { "input": "mm", "output": "NIE" }, { "input": "LJ", "output": "NIE" }, { "input": "m", "output": "NIE" }, { "input": "ioi", "output": "NIE" }, { "input": "OA", "output": "NIE" }, { "input": "aaaiaaa", "output": "NIE" }, { "input": "SS", "output": "NIE" }, { "input": "iiii", "output": "NIE" }, { "input": "ssops", "output": "NIE" }, { "input": "ssss", "output": "NIE" }, { "input": "ll", "output": "NIE" }, { "input": "s", "output": "NIE" }, { "input": "bb", "output": "NIE" }, { "input": "uu", "output": "NIE" }, { "input": "ZoZ", "output": "NIE" }, { "input": "mom", "output": "NIE" }, { "input": "uou", "output": "NIE" }, { "input": "u", "output": "NIE" }, { "input": "JL", "output": "NIE" }, { "input": "mOm", "output": "NIE" }, { "input": "llll", "output": "NIE" }, { "input": "ouo", "output": "NIE" }, { "input": "aa", "output": "NIE" }, { "input": "olo", "output": "NIE" }, { "input": "S", "output": "NIE" }, { "input": "lAl", "output": "NIE" }, { "input": "nnnn", "output": "NIE" }, { "input": "ZzZ", "output": "NIE" }, { "input": "bNd", "output": "NIE" }, { "input": "ZZ", "output": "NIE" }, { "input": "oNoNo", "output": "NIE" }, { "input": "l", "output": "NIE" }, { "input": "zz", "output": "NIE" }, { "input": "NON", "output": "NIE" }, { "input": "nn", "output": "NIE" }, { "input": "NoN", "output": "NIE" }, { "input": "sos", "output": "NIE" }, { "input": "lol", "output": "NIE" }, { "input": "mmm", "output": "NIE" }, { "input": "YAiAY", "output": "NIE" }, { "input": "ipIqi", "output": "NIE" }, { "input": "AAA", "output": "TAK" }, { "input": "uoOou", "output": "NIE" }, { "input": "SOS", "output": "NIE" }, { "input": "NN", "output": "NIE" }, { "input": "n", "output": "NIE" }, { "input": "h", "output": "NIE" }, { "input": "blld", "output": "NIE" }, { "input": "ipOqi", "output": "NIE" }, { "input": "pop", "output": "NIE" }, { "input": "BB", "output": "NIE" }, { "input": "OuO", "output": "NIE" }, { "input": "lxl", "output": "NIE" }, { "input": "Z", "output": "NIE" }, { "input": "vvivv", "output": "NIE" }, { "input": "nnnnnnnnnnnnn", "output": "NIE" }, { "input": "AA", "output": "TAK" }, { "input": "t", "output": "NIE" }, { "input": "z", "output": "NIE" }, { "input": "mmmAmmm", "output": "NIE" }, { "input": "qlililp", "output": "NIE" }, { "input": "mpOqm", "output": "NIE" }, { "input": "iiiiiiiiii", "output": "NIE" }, { "input": "BAAAB", "output": "NIE" }, { "input": "UA", "output": "NIE" }, { "input": "mmmmmmm", "output": "NIE" }, { "input": "NpOqN", "output": "NIE" }, { "input": "uOu", "output": "NIE" }, { "input": "uuu", "output": "NIE" }, { "input": "NAMAN", "output": "NIE" }, { "input": "lllll", "output": "NIE" }, { "input": "T", "output": "TAK" }, { "input": "mmmmmmmmmmmmmmmm", "output": "NIE" }, { "input": "AiiA", "output": "NIE" }, { "input": "iOi", "output": "NIE" }, { "input": "lll", "output": "NIE" }, { "input": "N", "output": "NIE" }, { "input": "viv", "output": "NIE" }, { "input": "oiio", "output": "NIE" }, { "input": "AiiiA", "output": "NIE" }, { "input": "NNNN", "output": "NIE" }, { "input": "ixi", "output": "NIE" }, { "input": "AuuA", "output": "NIE" }, { "input": "AAAANANAAAA", "output": "NIE" }, { "input": "mmmmm", "output": "NIE" }, { "input": "oYo", "output": "TAK" }, { "input": "dd", "output": "NIE" }, { "input": "A", "output": "TAK" }, { "input": "ioh", "output": "NIE" }, { "input": "mmmm", "output": "NIE" }, { "input": "uuuu", "output": "NIE" }, { "input": "puq", "output": "NIE" }, { "input": "rrrrrr", "output": "NIE" }, { "input": "c", "output": "NIE" }, { "input": "AbpA", "output": "NIE" }, { "input": "qAq", "output": "NIE" }, { "input": "tt", "output": "NIE" }, { "input": "mnmnm", "output": "NIE" }, { "input": "sss", "output": "NIE" }, { "input": "yy", "output": "NIE" }, { "input": "bob", "output": "NIE" }, { "input": "NAN", "output": "NIE" }, { "input": "mAm", "output": "NIE" }, { "input": "tAt", "output": "NIE" }, { "input": "yAy", "output": "NIE" }, { "input": "zAz", "output": "NIE" }, { "input": "aZ", "output": "NIE" }, { "input": "hh", "output": "NIE" }, { "input": "bbbb", "output": "NIE" }, { "input": "ZAZ", "output": "NIE" }, { "input": "Y", "output": "TAK" }, { "input": "AAMM", "output": "NIE" }, { "input": "lml", "output": "NIE" }, { "input": "AZA", "output": "NIE" }, { "input": "mXm", "output": "NIE" }, { "input": "bd", "output": "TAK" }, { "input": "H", "output": "TAK" }, { "input": "uvu", "output": "NIE" }, { "input": "dxxd", "output": "NIE" }, { "input": "dp", "output": "NIE" }, { "input": "vV", "output": "NIE" }, { "input": "vMo", "output": "NIE" }, { "input": "O", "output": "TAK" }, { "input": "vYv", "output": "TAK" }, { "input": "fv", "output": "NIE" }, { "input": "U", "output": "TAK" }, { "input": "iAi", "output": "NIE" }, { "input": "I", "output": "TAK" }, { "input": "VxrV", "output": "NIE" }, { "input": "POP", "output": "NIE" }, { "input": "bid", "output": "NIE" }, { "input": "bmd", "output": "NIE" }, { "input": "AiA", "output": "NIE" }, { "input": "mmmmmm", "output": "NIE" }, { "input": "XHX", "output": "TAK" }, { "input": "llllll", "output": "NIE" }, { "input": "aAa", "output": "NIE" }, { "input": "Db", "output": "NIE" }, { "input": "lOl", "output": "NIE" }, { "input": "bzd", "output": "NIE" } ]
1,655,008,376
2,147,483,647
PyPy 3
OK
TESTS
168
93
0
s = str(input()) t = 'AHIMOoTUVvWwXxY' d = {'p' : 'q', 'q' : 'p', 'b' : 'd', 'd' : 'b'} for c in t: d[c] = c for i, c in enumerate(s): if c in d and s[len(s)-1-i] == d[c]: continue else: print('NIE') exit() print('TAK')
Title: s-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the string is "s-palindrome". Input Specification: The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. Output Specification: Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. Demo Input: ['oXoxoXo\n', 'bod\n', 'ER\n'] Demo Output: ['TAK\n', 'TAK\n', 'NIE\n'] Note: none
```python s = str(input()) t = 'AHIMOoTUVvWwXxY' d = {'p' : 'q', 'q' : 'p', 'b' : 'd', 'd' : 'b'} for c in t: d[c] = c for i, c in enumerate(s): if c in d and s[len(s)-1-i] == d[c]: continue else: print('NIE') exit() print('TAK') ```
3
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,683,470,483
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
12,800,000
n = int(input()) a = list(map(int, input().split())) p = [] for i in range(n): if float(a[i]) == (sum(a)-a[i])/(n-1): p.append(i+1) print(len(p)) print(*p) # Sun May 07 2023 17:41:22 GMT+0300 (Moscow Standard Time)
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 n = int(input()) a = list(map(int, input().split())) p = [] for i in range(n): if float(a[i]) == (sum(a)-a[i])/(n-1): p.append(i+1) print(len(p)) print(*p) # Sun May 07 2023 17:41:22 GMT+0300 (Moscow Standard Time) ```
0
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe reposted PoLyCaRp\n" ]
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "output": "2" }, { "input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp", "output": "2" }, { "input": "1\niuNtwVf reposted POlYcarP", "output": "2" }, { "input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS", "output": "11" }, { "input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl", "output": "6" }, { "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj", "output": "9" }, { "input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI", "output": "3" } ]
1,679,136,475
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
102,400
from collections import defaultdict def max_depth(tree, root): if len(tree[root]) == 0: return 1 for child in tree[root]: return max_depth(tree, child) + 1 n = int(input()) tree = defaultdict(list) for _ in range(n): reposter, _ , poster = input().split() parent = poster.lower() child = reposter.lower() #populate tree tree[parent].append(child) height = max_depth(tree, 'polycarp') print(height)
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. Output Specification: Print a single integer — the maximum length of a repost chain. Demo Input: ['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n'] Demo Output: ['6\n', '2\n', '2\n'] Note: none
```python from collections import defaultdict def max_depth(tree, root): if len(tree[root]) == 0: return 1 for child in tree[root]: return max_depth(tree, child) + 1 n = int(input()) tree = defaultdict(list) for _ in range(n): reposter, _ , poster = input().split() parent = poster.lower() child = reposter.lower() #populate tree tree[parent].append(child) height = max_depth(tree, 'polycarp') print(height) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,622,183,942
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
122
0
n=int(input()) l=list(map(int,input().split(' '))) for i in range(n-1): if((l[i+1]-l[i])%2!=0): print(i+2) break
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) l=list(map(int,input().split(' '))) for i in range(n-1): if((l[i+1]-l[i])%2!=0): print(i+2) break ```
0
412
B
Network Configuration
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible?
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer.
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
[ "3 2\n40 20 30\n", "6 4\n100 20 40 20 50 50\n" ]
[ "30\n", "40\n" ]
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
1,000
[ { "input": "3 2\n40 20 30", "output": "30" }, { "input": "6 4\n100 20 40 20 50 50", "output": "40" }, { "input": "1 1\n16", "output": "16" }, { "input": "2 1\n10000 17", "output": "10000" }, { "input": "2 2\n200 300", "output": "200" }, { "input": "3 1\n21 25 16", "output": "25" }, { "input": "3 2\n23 20 26", "output": "23" }, { "input": "3 3\n19 29 28", "output": "19" }, { "input": "100 2\n82 37 88 28 98 30 38 76 90 68 79 29 67 93 19 71 122 103 110 79 20 75 68 101 16 120 114 68 73 71 103 114 99 70 73 18 36 31 32 87 32 79 44 72 58 25 44 72 106 38 47 17 83 41 75 23 49 30 73 67 117 52 22 117 109 89 66 88 75 62 17 35 83 69 63 60 23 120 93 18 112 93 39 72 116 109 106 72 27 123 117 119 87 72 33 73 70 110 43 43", "output": "122" }, { "input": "30 13\n36 82 93 91 48 62 59 96 72 40 45 68 97 70 26 22 35 98 92 83 72 49 70 39 53 94 97 65 37 28", "output": "70" }, { "input": "50 49\n20 77 31 40 18 87 44 64 70 48 29 59 98 33 95 17 69 84 81 17 24 66 37 54 97 55 77 79 42 21 23 42 36 55 81 83 94 45 25 84 20 97 37 95 46 92 73 39 90 71", "output": "17" }, { "input": "40 40\n110 674 669 146 882 590 650 844 427 187 380 711 122 94 38 216 414 874 380 31 895 390 414 557 913 68 665 964 895 708 594 17 24 621 780 509 837 550 630 568", "output": "17" }, { "input": "40 1\n851 110 1523 1572 945 4966 4560 756 2373 4760 144 2579 4022 220 1924 1042 160 2792 2425 4483 2154 4120 319 4617 4686 2502 4797 4941 4590 4478 4705 4355 695 684 1560 684 2780 1090 4995 3113", "output": "4995" }, { "input": "70 12\n6321 2502 557 2734 16524 10133 13931 5045 3897 18993 5745 8687 12344 1724 12071 2345 3852 9312 14432 8615 7461 2439 4751 19872 12266 12997 8276 8155 9502 3047 7226 12754 9447 17349 1888 14564 18257 18099 8924 14199 738 13693 10917 15554 15773 17859 13391 13176 10567 19658 16494 3968 13977 14694 10537 4044 16402 9714 4425 13599 19660 2426 19687 2455 2382 3413 5754 113 7542 8353", "output": "16402" }, { "input": "80 60\n6159 26457 23753 27073 9877 4492 11957 10989 27151 6552 1646 7773 23924 27554 10517 8788 31160 455 12625 22009 22133 15657 14968 31871 15344 16550 27414 876 31213 10895 21508 17516 12747 59 11786 10497 30143 25548 22003 2809 11694 30395 8122 31248 23075 19013 31614 9133 27942 27346 15969 19415 10367 8424 29355 18903 3396 6327 4201 24124 24266 22586 724 1595 3972 17526 2843 20982 23655 12714 18050 15225 2658 7236 27555 13023 729 9022 17386 2585", "output": "8122" }, { "input": "100 1\n199 348 489 76 638 579 982 125 28 401 228 117 195 337 80 914 752 98 679 417 47 225 357 413 849 622 477 620 487 223 321 240 439 393 733 660 652 500 877 40 788 246 376 723 952 601 912 316 598 809 476 932 384 147 982 271 202 695 129 303 304 712 49 306 598 141 833 730 946 708 724 788 202 465 951 118 279 706 214 655 152 976 998 231 487 311 342 317 243 554 977 232 365 643 336 501 761 400 600 528", "output": "998" }, { "input": "80 50\n15160 6853 20254 11358 19535 27691 2983 31650 9219 11833 32053 31695 21511 4320 4384 24843 1454 31543 18796 13815 1546 27926 16276 14315 12542 25370 24890 29647 3584 17867 12446 15072 19852 30207 16361 7964 5343 398 10837 31114 9252 12767 15098 22562 32637 31823 8160 12658 6422 19142 12448 6765 7373 868 31712 24856 23251 29200 8159 16144 27165 4308 13652 12502 4183 7961 3032 26855 8687 12263 24319 7722 19460 30700 29806 1280 21141 25965 25550 26881", "output": "12448" }, { "input": "50 16\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 1\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 2\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 100\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" }, { "input": "100 99\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16", "output": "16" } ]
1,568,996,118
2,147,483,647
PyPy 3
OK
TESTS
34
140
0
n, k = map(int, input().split()) a = list(reversed(sorted(map(int, input().split())))) print(a[k - 1]) # ♥
Title: Network Configuration Time Limit: None seconds Memory Limit: None megabytes Problem Description: The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible? Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer. Output Specification: Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. Demo Input: ['3 2\n40 20 30\n', '6 4\n100 20 40 20 50 50\n'] Demo Output: ['30\n', '40\n'] Note: In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
```python n, k = map(int, input().split()) a = list(reversed(sorted(map(int, input().split())))) print(a[k - 1]) # ♥ ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,614,968,352
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
t=input() x=0 y=0 z=0 for i in range(t): array=map(int,raw_input().split(" ")) x+=array[0] y+=array[1] z+=array[2] print "YES" if (x==0 and y==0 and z==0) else "NO"
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python t=input() x=0 y=0 z=0 for i in range(t): array=map(int,raw_input().split(" ")) x+=array[0] y+=array[1] z+=array[2] print "YES" if (x==0 and y==0 and z==0) else "NO" ```
-1
687
B
Remainders Game
PROGRAMMING
1,800
[ "chinese remainder theorem", "math", "number theory" ]
null
null
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*? Note, that means the remainder of *x* after dividing it by *y*.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
[ "4 5\n2 3 5 12\n", "2 7\n2 3\n" ]
[ "Yes\n", "No\n" ]
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
1,000
[ { "input": "4 5\n2 3 5 12", "output": "Yes" }, { "input": "2 7\n2 3", "output": "No" }, { "input": "1 6\n8", "output": "No" }, { "input": "2 3\n9 4", "output": "Yes" }, { "input": "4 16\n19 16 13 9", "output": "Yes" }, { "input": "5 10\n5 16 19 9 17", "output": "Yes" }, { "input": "11 95\n31 49 8 139 169 121 71 17 43 29 125", "output": "No" }, { "input": "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17", "output": "No" }, { "input": "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71", "output": "No" }, { "input": "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71", "output": "Yes" }, { "input": "2 4\n2 2", "output": "No" }, { "input": "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619", "output": "No" }, { "input": "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766", "output": "No" }, { "input": "1 994619\n216000", "output": "No" }, { "input": "1 651040\n911250", "output": "No" }, { "input": "1 620622\n60060", "output": "No" }, { "input": "1 1\n559872", "output": "Yes" }, { "input": "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967", "output": "No" }, { "input": "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426", "output": "No" }, { "input": "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630", "output": "No" }, { "input": "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043", "output": "No" }, { "input": "1 216000\n648000", "output": "Yes" }, { "input": "2 8\n4 4", "output": "No" }, { "input": "3 8\n4 4 4", "output": "No" }, { "input": "2 8\n2 4", "output": "No" }, { "input": "3 12\n2 2 3", "output": "No" }, { "input": "10 4\n2 2 2 2 2 2 2 2 2 2", "output": "No" }, { "input": "10 1024\n1 2 4 8 16 32 64 128 256 512", "output": "No" }, { "input": "3 24\n2 2 3", "output": "No" }, { "input": "1 8\n2", "output": "No" }, { "input": "2 9\n3 3", "output": "No" }, { "input": "3 4\n2 2 2", "output": "No" }, { "input": "3 4\n1 2 2", "output": "No" }, { "input": "1 4\n2", "output": "No" }, { "input": "1 100003\n2", "output": "No" }, { "input": "1 2\n12", "output": "Yes" }, { "input": "2 988027\n989018 995006", "output": "Yes" }, { "input": "3 9\n3 3 3", "output": "No" }, { "input": "1 49\n7", "output": "No" }, { "input": "2 600000\n200000 300000", "output": "Yes" }, { "input": "3 8\n2 2 2", "output": "No" }, { "input": "7 510510\n524288 531441 390625 823543 161051 371293 83521", "output": "Yes" }, { "input": "2 30\n6 10", "output": "Yes" }, { "input": "2 27000\n5400 4500", "output": "Yes" }, { "input": "3 8\n1 2 4", "output": "No" }, { "input": "4 16\n2 2 2 2", "output": "No" }, { "input": "2 16\n4 8", "output": "No" }, { "input": "2 8\n4 2", "output": "No" }, { "input": "3 4\n2 2 3", "output": "No" }, { "input": "1 8\n4", "output": "No" }, { "input": "1 999983\n2", "output": "No" }, { "input": "3 16\n2 4 8", "output": "No" }, { "input": "2 216\n12 18", "output": "No" }, { "input": "2 16\n8 8", "output": "No" }, { "input": "2 36\n18 12", "output": "Yes" }, { "input": "2 36\n12 18", "output": "Yes" }, { "input": "2 1000000\n1000000 1000000", "output": "Yes" }, { "input": "3 20\n2 2 5", "output": "No" }, { "input": "1 2\n6", "output": "Yes" }, { "input": "4 4\n2 3 6 5", "output": "No" }, { "input": "1 2\n1", "output": "No" }, { "input": "1 6\n6", "output": "Yes" }, { "input": "2 16\n4 4", "output": "No" }, { "input": "2 3779\n1 2", "output": "No" }, { "input": "2 8\n4 12", "output": "No" }, { "input": "2 24\n4 6", "output": "No" }, { "input": "1 1\n5", "output": "Yes" }, { "input": "10 255255\n1000000 700000 300000 110000 130000 170000 190000 230000 290000 310000", "output": "Yes" }, { "input": "2 1000\n500 2", "output": "No" }, { "input": "4 8\n2 2 2 2", "output": "No" }, { "input": "1 666013\n1", "output": "No" }, { "input": "1 999983\n1", "output": "No" }, { "input": "1 125\n5", "output": "No" }, { "input": "2 32\n4 8", "output": "No" }, { "input": "3 32\n2 4 8", "output": "No" }, { "input": "3 8\n2 4 11", "output": "No" }, { "input": "1 32\n2", "output": "No" }, { "input": "4 4\n2 2 2 2", "output": "No" }, { "input": "8 32\n2 2 2 2 2 2 2 2", "output": "No" }, { "input": "3 24\n2 4 3", "output": "No" }, { "input": "2 4\n2 6", "output": "No" }, { "input": "2 24\n6 4", "output": "No" }, { "input": "1 20998\n2", "output": "No" }, { "input": "1 1\n1", "output": "Yes" }, { "input": "2 20998\n2 10499", "output": "Yes" }, { "input": "1 5\n1", "output": "No" }, { "input": "2 25\n5 5", "output": "No" }, { "input": "5 2\n2 2 2 2 2", "output": "Yes" }, { "input": "3 12\n2 3 6", "output": "No" }, { "input": "1 1\n3", "output": "Yes" }, { "input": "2 16\n8 4", "output": "No" }, { "input": "40 10\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", "output": "No" } ]
1,573,821,357
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
10
124
4,710,400
def gcd(a, b): if a % b == 0: return b return gcd(b, a % b) def lcm(c): n = len(c) if n == 1: return c[0] a = lcm(c[:n//2]) b = lcm(c[n//2:]) return a * b // gcd(a, b) def main(): n, k = map(lambda x : int(x), input().split()) c = list(map(lambda x : int(x), input().split())) if gcd(k, lcm(c))==k: print("Yes") else: print("No") main()
Title: Remainders Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*? Note, that means the remainder of *x* after dividing it by *y*. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). Output Specification: Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. Demo Input: ['4 5\n2 3 5 12\n', '2 7\n2 3\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
```python def gcd(a, b): if a % b == 0: return b return gcd(b, a % b) def lcm(c): n = len(c) if n == 1: return c[0] a = lcm(c[:n//2]) b = lcm(c[n//2:]) return a * b // gcd(a, b) def main(): n, k = map(lambda x : int(x), input().split()) c = list(map(lambda x : int(x), input().split())) if gcd(k, lcm(c))==k: print("Yes") else: print("No") main() ```
-1
39
B
Company Income Growth
PROGRAMMING
1,300
[ "greedy" ]
B. Company Income Growth
2
64
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces.
Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
[ "10\n-2 1 1 3 2 3 4 -10 -2 5\n", "3\n-1 -2 -3\n" ]
[ "5\n2002 2005 2006 2007 2010\n", "0\n" ]
none
0
[ { "input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010 " }, { "input": "3\n-1 -2 -3", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-2 0", "output": "0" }, { "input": "2\n3 -3", "output": "0" }, { "input": "3\n1 1 1", "output": "1\n2001 " }, { "input": "3\n-2 -2 1", "output": "1\n2003 " }, { "input": "4\n-4 2 3 -1", "output": "0" }, { "input": "5\n-3 -3 -4 2 -2", "output": "0" }, { "input": "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9", "output": "5\n2020 2036 2044 2077 2083 " }, { "input": "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6", "output": "6\n2021 2042 2060 2062 2068 2089 " }, { "input": "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3", "output": "6\n2006 2048 2053 2057 2064 2083 " }, { "input": "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2", "output": "7\n2005 2047 2052 2067 2075 2083 2089 " }, { "input": "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5", "output": "0" }, { "input": "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4", "output": "4\n2032 2047 2062 2076 " }, { "input": "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31", "output": "0" }, { "input": "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87", "output": "0" }, { "input": "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58", "output": "0" }, { "input": "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30", "output": "1\n2051 " }, { "input": "1\n1", "output": "1\n2001 " }, { "input": "2\n1 2", "output": "2\n2001 2002 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 " }, { "input": "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99", "output": "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 " }, { "input": "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50", "output": "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 " }, { "input": "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50", "output": "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 " }, { "input": "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86", "output": "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 " }, { "input": "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21", "output": "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 " }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n2 3 1 3 3 2 1 2 1 2", "output": "2\n2003 2006 " }, { "input": "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1", "output": "4\n2002 2006 2009 2011 " }, { "input": "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4", "output": "2\n2007 2010 " }, { "input": "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4", "output": "2\n2006 2008 " } ]
1,565,389,762
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import sys n = sys.stdin.readline() arr = sys.stdin.readline().split() arr = [ int(x) for x in arr] res = [] contador = 1 for i in range(len(arr)): print arr[i] if arr[i] == contador: contador += 1 res.append(2000 + i +1) if res: print(' '.join([str(y) for y in res])) else: print(0)
Title: Company Income Growth Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. Output Specification: Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. Demo Input: ['10\n-2 1 1 3 2 3 4 -10 -2 5\n', '3\n-1 -2 -3\n'] Demo Output: ['5\n2002 2005 2006 2007 2010\n', '0\n'] Note: none
```python import sys n = sys.stdin.readline() arr = sys.stdin.readline().split() arr = [ int(x) for x in arr] res = [] contador = 1 for i in range(len(arr)): print arr[i] if arr[i] == contador: contador += 1 res.append(2000 + i +1) if res: print(' '.join([str(y) for y in res])) else: print(0) ```
-1
608
B
Hamming Distance Sum
PROGRAMMING
1,500
[ "combinatorics", "strings" ]
null
null
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2. Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000). The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000). Both strings are guaranteed to consist of characters '0' and '1' only.
Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
[ "01\n00111\n", "0011\n0110\n" ]
[ "3\n", "2\n" ]
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3. The second sample case is described in the statement.
1,000
[ { "input": "01\n00111", "output": "3" }, { "input": "0011\n0110", "output": "2" }, { "input": "0\n0", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "0\n1", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111", "output": "321" }, { "input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010", "output": "316" } ]
1,660,802,172
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
8,806,400
a = list(map(int, input())) b = list(map(int, input())) total = 0 for i in range(len(a)): for j in range(i, i+len(b)-len(a)+1): total += (a[i] + b[j]) % 2 print(total)
Title: Hamming Distance Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2. Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. Input Specification: The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000). The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000). Both strings are guaranteed to consist of characters '0' and '1' only. Output Specification: Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. Demo Input: ['01\n00111\n', '0011\n0110\n'] Demo Output: ['3\n', '2\n'] Note: For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3. The second sample case is described in the statement.
```python a = list(map(int, input())) b = list(map(int, input())) total = 0 for i in range(len(a)): for j in range(i, i+len(b)-len(a)+1): total += (a[i] + b[j]) % 2 print(total) ```
0
629
B
Far Relative’s Problem
PROGRAMMING
1,100
[ "brute force" ]
null
null
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
Print the maximum number of people that may come to Famil Door's party.
[ "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n" ]
[ "2\n", "4\n" ]
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
1,000
[ { "input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2" }, { "input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4" }, { "input": "1\nF 68 307", "output": "0" }, { "input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244\nF 42 339\nM 253 307\nM 128 192\nF 119 328\nM 135 249\nF 303 358\nF 348 352\nF 8 364\nF 126 303\nM 226 346\nF 110 300\nF 47 303\nF 201 311\nF 287 288\nM 270 352\nM 227 351\nF 8 111\nF 39 229\nM 163 315\nF 269 335\nF 147 351\nF 96 143\nM 97 99\nM 177 295", "output": "22" }, { "input": "2\nF 1 1\nM 1 1", "output": "2" }, { "input": "4\nM 1 2\nM 2 3\nF 3 4\nF 4 5", "output": "2" }, { "input": "1\nF 1 2", "output": "0" }, { "input": "18\nF 3 4\nF 3 4\nF 3 4\nF 3 4\nF 5 6\nF 5 6\nM 3 4\nM 3 4\nM 5 6\nM 5 6\nM 5 6\nM 5 6\nF 7 8\nF 7 8\nF 7 8\nM 7 8\nM 7 8\nM 7 8", "output": "6" }, { "input": "2\nM 1 1\nF 1 1", "output": "2" }, { "input": "3\nM 1 1\nF 1 1\nM 1 1", "output": "2" } ]
1,666,718,529
2,147,483,647
PyPy 3-64
OK
TESTS
76
93
1,843,200
from sys import stdin,stdout input=stdin.readline def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n=int(input()) ; female=[0]*368 ; male=[0]*368 ; ans=0 for i in range(n): gen,st,end=input().split() if gen=="F": female[int(st)-1]+=1 female[int(end)]-=1 else: male[int(st)-1]+=1 male[int(end)]-=1 for i in range(367): female[i+1]+=female[i] male[i+1]+=male[i] for i in range(368): ans=max(min(female[i],male[i]),ans) print(ans*2)
Title: Far Relative’s Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive. Output Specification: Print the maximum number of people that may come to Famil Door's party. Demo Input: ['4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n', '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
```python from sys import stdin,stdout input=stdin.readline def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n=int(input()) ; female=[0]*368 ; male=[0]*368 ; ans=0 for i in range(n): gen,st,end=input().split() if gen=="F": female[int(st)-1]+=1 female[int(end)]-=1 else: male[int(st)-1]+=1 male[int(end)]-=1 for i in range(367): female[i+1]+=female[i] male[i+1]+=male[i] for i in range(368): ans=max(min(female[i],male[i]),ans) print(ans*2) ```
3
466
A
Cheap Travel
PROGRAMMING
1,200
[ "implementation" ]
null
null
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10 2 1 1", "output": "5" }, { "input": "1 1000 1 2", "output": "1" }, { "input": "1 1000 3 2", "output": "2" }, { "input": "10 3 1 2", "output": "7" }, { "input": "995 1 2 1", "output": "995" }, { "input": "556 2 16 15", "output": "4170" }, { "input": "477 2 16 14", "output": "3346" }, { "input": "101 110 1 100", "output": "100" }, { "input": "9 3 3 10", "output": "27" }, { "input": "100 8 10 1", "output": "13" }, { "input": "6 4 1 3", "output": "5" }, { "input": "8 5 2 8", "output": "14" }, { "input": "1000 2 1 1000", "output": "1000" } ]
1,690,718,007
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
30
0
n,m,a,b = map(int,input().split()) z=b/m if a<=z: print(n*a) elif b>a or n%m==0: print(int(b*(n//m)+a*(n%m))) else: print(b*(n//m)+1)
Title: Cheap Travel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? Input Specification: The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. Output Specification: Print a single integer — the minimum sum in rubles that Ann will need to spend. Demo Input: ['6 2 1 2\n', '5 2 2 3\n'] Demo Output: ['6\n', '8\n'] Note: In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
```python n,m,a,b = map(int,input().split()) z=b/m if a<=z: print(n*a) elif b>a or n%m==0: print(int(b*(n//m)+a*(n%m))) else: print(b*(n//m)+1) ```
0
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,591,733,210
2,147,483,647
PyPy 3
OK
TESTS
25
280
1,331,200
from math import ceil n,d=map(int,input().split()) p=-1 ans=0 for i in map(int,input().split()): k=ceil((max(p-i+1,0))/d) ans+=k p=i+k*d print(ans)
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 from math import ceil n,d=map(int,input().split()) p=-1 ans=0 for i in map(int,input().split()): k=ceil((max(p-i+1,0))/d) ans+=k p=i+k*d print(ans) ```
3.850082
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,687,956,015
2,147,483,647
Python 3
OK
TESTS
71
92
0
n=int(input()) vm=maxi=0 for i in range(n): a,b=input().split(" ") vm-=int(a) vm+=int(b) maxi=max(maxi,vm) print(maxi)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python n=int(input()) vm=maxi=0 for i in range(n): a,b=input().split(" ") vm-=int(a) vm+=int(b) maxi=max(maxi,vm) print(maxi) ```
3
126
B
Password
PROGRAMMING
1,700
[ "binary search", "dp", "hashing", "string suffix structures", "strings" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
1,000
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
1,543,733,508
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
248
0
s = input() n = len(s) if n==1 or n==2: print("Just a legend") else: lista = [] for i in range(n): lista.append(0) l = 0 i = 1 while i < n: if s[l] == s[i]: lista[i] = l l += 1 i += 1 else: if l != 0: l = lista[l-1] else: lista[i] = 0 i += 1 if (lista[-1] in lista[:-1]) and (lista[-1] != 0): print(s[:value]) elif lista[lista[-1] - 1]==0: print("Just a legend") elif lista[lista[-1] - 1]: print(s[:lista[lista[-1] - 1]]) else: print("Just a legend")
Title: Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. Input Specification: You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Output Specification: Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Demo Input: ['fixprefixsuffix\n', 'abcdabc\n'] Demo Output: ['fix', 'Just a legend'] Note: none
```python s = input() n = len(s) if n==1 or n==2: print("Just a legend") else: lista = [] for i in range(n): lista.append(0) l = 0 i = 1 while i < n: if s[l] == s[i]: lista[i] = l l += 1 i += 1 else: if l != 0: l = lista[l-1] else: lista[i] = 0 i += 1 if (lista[-1] in lista[:-1]) and (lista[-1] != 0): print(s[:value]) elif lista[lista[-1] - 1]==0: print("Just a legend") elif lista[lista[-1] - 1]: print(s[:lista[lista[-1] - 1]]) else: print("Just a legend") ```
-1
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,526,725,639
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
154
0
a,b=input().split() a,b,list1,list2=int(a),int(b),[],[] list1=[int(x) for x in input().split()] list2=[int(x) for x in input().split()] c,d,e=max(list1),min(list2),min(list1) if c>d:print(-1) elif c<d: if 2*e<=c:print(c) else:print(-1)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python a,b=input().split() a,b,list1,list2=int(a),int(b),[],[] list1=[int(x) for x in input().split()] list2=[int(x) for x in input().split()] c,d,e=max(list1),min(list2),min(list1) if c>d:print(-1) elif c<d: if 2*e<=c:print(c) else:print(-1) ```
0
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros.
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "1000000000000000000 1000000000000000000", "output": "0" }, { "input": "1 1000000000000000000", "output": "1712" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 7", "output": "3" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "2" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "3" }, { "input": "3 3", "output": "0" }, { "input": "3 4", "output": "0" }, { "input": "3 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "2" }, { "input": "4 4", "output": "0" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "2" }, { "input": "5 7", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "7 7", "output": "0" }, { "input": "1 8", "output": "3" }, { "input": "6 8", "output": "1" }, { "input": "7 8", "output": "0" }, { "input": "8 8", "output": "0" }, { "input": "1 1022", "output": "45" }, { "input": "1 1023", "output": "45" }, { "input": "1 1024", "output": "45" }, { "input": "1 1025", "output": "45" }, { "input": "1 1026", "output": "45" }, { "input": "509 1022", "output": "11" }, { "input": "510 1022", "output": "10" }, { "input": "511 1022", "output": "9" }, { "input": "512 1022", "output": "9" }, { "input": "513 1022", "output": "9" }, { "input": "509 1023", "output": "11" }, { "input": "510 1023", "output": "10" }, { "input": "511 1023", "output": "9" }, { "input": "512 1023", "output": "9" }, { "input": "513 1023", "output": "9" }, { "input": "509 1024", "output": "11" }, { "input": "510 1024", "output": "10" }, { "input": "511 1024", "output": "9" }, { "input": "512 1024", "output": "9" }, { "input": "513 1024", "output": "9" }, { "input": "509 1025", "output": "11" }, { "input": "510 1025", "output": "10" }, { "input": "511 1025", "output": "9" }, { "input": "512 1025", "output": "9" }, { "input": "513 1025", "output": "9" }, { "input": "1 1000000000", "output": "408" }, { "input": "10000000000 70000000000000000", "output": "961" }, { "input": "1 935829385028502935", "output": "1712" }, { "input": "500000000000000000 1000000000000000000", "output": "58" }, { "input": "500000000000000000 576460752303423488", "output": "57" }, { "input": "576460752303423488 1000000000000000000", "output": "1" }, { "input": "999999999999999999 1000000000000000000", "output": "0" }, { "input": "1124800395214847 36011204832919551", "output": "257" }, { "input": "1124800395214847 36011204832919550", "output": "256" }, { "input": "1124800395214847 36011204832919552", "output": "257" }, { "input": "1124800395214846 36011204832919551", "output": "257" }, { "input": "1124800395214848 36011204832919551", "output": "256" }, { "input": "1 287104476244869119", "output": "1603" }, { "input": "1 287104476244869118", "output": "1602" }, { "input": "1 287104476244869120", "output": "1603" }, { "input": "492581209243647 1000000000000000000", "output": "583" }, { "input": "492581209243646 1000000000000000000", "output": "583" }, { "input": "492581209243648 1000000000000000000", "output": "582" }, { "input": "1099444518911 1099444518911", "output": "1" }, { "input": "1099444518910 1099444518911", "output": "1" }, { "input": "1099444518911 1099444518912", "output": "1" }, { "input": "1099444518910 1099444518912", "output": "1" }, { "input": "864691128455135231 864691128455135231", "output": "1" }, { "input": "864691128455135231 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135232", "output": "1" }, { "input": "864691128455135230 864691128455135231", "output": "1" }, { "input": "864691128455135231 1000000000000000000", "output": "1" }, { "input": "864691128455135232 1000000000000000000", "output": "0" }, { "input": "864691128455135230 1000000000000000000", "output": "1" }, { "input": "576460752303423487 576460752303423487", "output": "0" }, { "input": "1 576460752303423487", "output": "1711" }, { "input": "1 576460752303423486", "output": "1711" }, { "input": "2 1000000000000000000", "output": "1712" }, { "input": "3 1000000000000000000", "output": "1711" }, { "input": "4 1000000000000000000", "output": "1711" }, { "input": "5 1000000000000000000", "output": "1711" }, { "input": "6 1000000000000000000", "output": "1710" }, { "input": "5 6", "output": "2" }, { "input": "1 2", "output": "1" } ]
1,571,426,708
2,147,483,647
Python 3
OK
TESTS
103
109
0
countYears = 0 def newYearCount(startYear, endYear, baseYear, zeros): global countYears if (baseYear > endYear): return None if (startYear <= baseYear and baseYear<= endYear and zeros == 1): countYears += 1 if (zeros == 0): newYearCount(startYear, endYear, baseYear << 1, zeros + 1) newYearCount(startYear, endYear, (baseYear << 1) + 1, zeros) startYear, endYear = map(int, input().split()) newYearCount(startYear, endYear, 1, 0) print(countYears)
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros. Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. Output Specification: Print one integer – the number of years Limak will count in his chosen interval. Demo Input: ['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n'] Demo Output: ['2\n', '1\n', '0\n', '26\n'] Note: In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property.
```python countYears = 0 def newYearCount(startYear, endYear, baseYear, zeros): global countYears if (baseYear > endYear): return None if (startYear <= baseYear and baseYear<= endYear and zeros == 1): countYears += 1 if (zeros == 0): newYearCount(startYear, endYear, baseYear << 1, zeros + 1) newYearCount(startYear, endYear, (baseYear << 1) + 1, zeros) startYear, endYear = map(int, input().split()) newYearCount(startYear, endYear, 1, 0) print(countYears) ```
3
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71", "output": "51" }, { "input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29", "output": "1" }, { "input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24", "output": "2" }, { "input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6", "output": "10" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "99" }, { "input": "7\n1 2 3 3 3 1 2", "output": "3" }, { "input": "5\n1 2 3 4 5", "output": "1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "1" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "11\n1 2 3 4 5 6 7 8 9 1 1", "output": "3" }, { "input": "12\n1 2 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "14" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "16" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "10\n1 1 1 1 2 2 1 1 9 10", "output": "6" }, { "input": "2\n1 1", "output": "2" }, { "input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "56" }, { "input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92", "output": "6" }, { "input": "10\n1 2 2 3 3 3 4 4 4 4", "output": "4" }, { "input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21", "output": "3" }, { "input": "5\n5 5 5 5 1", "output": "4" }, { "input": "6\n2 3 2 5 2 6", "output": "3" }, { "input": "3\n58 59 58", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 8", "output": "2" }, { "input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "97" }, { "input": "3\n95 95 4", "output": "2" }, { "input": "3\n2 2 5", "output": "2" } ]
1,609,938,341
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
# import os t = int(input()) a = list(map(int, input().split())) r = 0 for item in list(set(a)): new = a.count(item) if new > r: r = new print(new) # 03/01 - 1 # 04/01 - 21 # 05/01 - 27 # 06/01 - 4
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 os t = int(input()) a = list(map(int, input().split())) r = 0 for item in list(set(a)): new = a.count(item) if new > r: r = new print(new) # 03/01 - 1 # 04/01 - 21 # 05/01 - 27 # 06/01 - 4 ```
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,642,948,510
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
218
3,788,800
from fractions import Fraction x,y = list(map(int, input().split())) print(Fraction(y/x))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python from fractions import Fraction x,y = list(map(int, input().split())) print(Fraction(y/x)) ```
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,427,808
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
4,505,600
from math import log2, floor from time import time def solve(n): maxPower = floor(log2(n)) negSum = 0 for i in range(maxPower + 1): negSum -= 2 ** i Sum = int(0.5 * n * (1 + n)) Sum += 2 * negSum return Sum if __name__ == "__main__": numInputs = int(input('t?')) for i in range(numInputs): num = int(input('n?')) start = time() print(solve(num)) end = time() print('%.3es' % (end - start))
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 from math import log2, floor from time import time def solve(n): maxPower = floor(log2(n)) negSum = 0 for i in range(maxPower + 1): negSum -= 2 ** i Sum = int(0.5 * n * (1 + n)) Sum += 2 * negSum return Sum if __name__ == "__main__": numInputs = int(input('t?')) for i in range(numInputs): num = int(input('n?')) start = time() print(solve(num)) end = time() print('%.3es' % (end - start)) ```
0
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output": "1 2" }, { "input": "5\n4 24 6 1 15", "output": "3 4" }, { "input": "2\n511 32", "output": "1 2" }, { "input": "3\n907 452 355", "output": "2 3" }, { "input": "4\n303 872 764 401", "output": "4 1" }, { "input": "10\n684 698 429 694 956 812 594 170 937 764", "output": "1 2" }, { "input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695", "output": "7 8" }, { "input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000", "output": "12 13" }, { "input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58", "output": "16 17" }, { "input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000", "output": "1 2" }, { "input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4", "output": "1 2" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "86 87" }, { "input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25", "output": "7 8" }, { "input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964", "output": "1 2" }, { "input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967", "output": "81 82" }, { "input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17", "output": "36 37" } ]
1,676,608,911
2,147,483,647
Python 3
OK
TESTS
20
92
0
x=int(input()) a=list(map(int,input().split())) c=abs(a[1]-a[0]) l=1 y=2 for i in range(1,x): if c>abs(a[i]-a[i-1]): c=abs(a[i]-a[i-1]) l=i+1 y=i if c>abs(a[x-1]-a[0]): c=abs(a[x-1]-a[0]) l=x y=1 print(l,y)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. Output Specification: Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Demo Input: ['5\n10 12 13 15 10\n', '4\n10 20 30 40\n'] Demo Output: ['5 1\n', '1 2\n'] Note: none
```python x=int(input()) a=list(map(int,input().split())) c=abs(a[1]-a[0]) l=1 y=2 for i in range(1,x): if c>abs(a[i]-a[i-1]): c=abs(a[i]-a[i-1]) l=i+1 y=i if c>abs(a[x-1]-a[0]): c=abs(a[x-1]-a[0]) l=x y=1 print(l,y) ```
3.977
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,505,659,530
6,030
Python 3
WRONG_ANSWER
TESTS
30
170
5,529,600
n,k=map(int,input().split()) for i in range(1,100000): m=str(n*i) m=m[len(m)-k:len(m)] if(m=='0'*k): print(n*i) break i+=1 else: print(str(n)+('0'*k))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python n,k=map(int,input().split()) for i in range(1,100000): m=str(n*i) m=m[len(m)-k:len(m)] if(m=='0'*k): print(n*i) break i+=1 else: print(str(n)+('0'*k)) ```
0
652
A
Gabriel and Caterpillar
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=&gt;<=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple. Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by *a* cm per hour by day and slips down by *b* cm per hour by night. In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm. Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=&lt;<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters. The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple. If the caterpillar can't get the apple print the only integer <=-<=1.
[ "10 30\n2 1\n", "10 13\n1 1\n", "10 19\n1 2\n", "1 50\n5 4\n" ]
[ "1\n", "0\n", "-1\n", "1\n" ]
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple. Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
0
[ { "input": "10 30\n2 1", "output": "1" }, { "input": "10 13\n1 1", "output": "0" }, { "input": "10 19\n1 2", "output": "-1" }, { "input": "1 50\n5 4", "output": "1" }, { "input": "1 1000\n2 1", "output": "82" }, { "input": "999 1000\n1 1", "output": "0" }, { "input": "999 1000\n1 1000", "output": "0" }, { "input": "1 1000\n999 1", "output": "0" }, { "input": "1 1000\n100 99", "output": "17" }, { "input": "500 509\n1 1", "output": "-1" }, { "input": "500 555\n6 1", "output": "1" }, { "input": "1 100000\n2 1", "output": "8332" }, { "input": "99990 100000\n1 1", "output": "-1" }, { "input": "90000 100000\n2 1", "output": "832" }, { "input": "10 100000\n1 100000", "output": "-1" }, { "input": "1 41\n5 6", "output": "0" }, { "input": "1 100000\n1 100000", "output": "-1" }, { "input": "1 9\n1 1", "output": "0" }, { "input": "8 16\n1 12", "output": "0" }, { "input": "14 30\n2 1", "output": "0" }, { "input": "7245 77828\n6224 92468", "output": "-1" }, { "input": "43951 66098\n1604 35654", "output": "-1" }, { "input": "1 2\n4 3", "output": "0" }, { "input": "90493 94279\n468 49", "output": "1" }, { "input": "1 50\n3 1", "output": "2" }, { "input": "26300 88310\n7130 351", "output": "1" }, { "input": "1 17\n2 2", "output": "0" }, { "input": "10718 75025\n7083 6958", "output": "6" }, { "input": "1 10\n1 100000", "output": "-1" }, { "input": "1 190\n10 1", "output": "2" }, { "input": "24951 85591\n3090 8945", "output": "-1" }, { "input": "1 25\n3 2", "output": "0" }, { "input": "27043 88418\n7273 7", "output": "1" }, { "input": "35413 75637\n4087 30166", "output": "-1" }, { "input": "1 18\n2 3", "output": "-1" }, { "input": "1 16\n2 2", "output": "0" }, { "input": "1 18\n2 1", "output": "1" }, { "input": "1 10\n2 2", "output": "0" }, { "input": "1 30\n2 1", "output": "2" }, { "input": "1 100000\n10000 100000", "output": "-1" }, { "input": "4444 33425\n2758 44", "output": "1" }, { "input": "1 100000\n10 99910", "output": "-1" }, { "input": "12 100\n6 11", "output": "-1" }, { "input": "100 100000\n10 11", "output": "-1" }, { "input": "28473 80380\n2568 95212", "output": "-1" }, { "input": "10 105\n10 1", "output": "1" }, { "input": "4642 39297\n3760 451", "output": "1" }, { "input": "1 90\n10 1", "output": "1" }, { "input": "2 100\n1 100000", "output": "-1" }, { "input": "1 100000\n1000 100000", "output": "-1" }, { "input": "1 45\n1 100000", "output": "-1" }, { "input": "12 1000\n100 1", "output": "1" }, { "input": "64635 76564\n100 34238", "output": "-1" }, { "input": "10 90\n10 12", "output": "0" }, { "input": "49238 81395\n3512 251", "output": "1" }, { "input": "6497 62133\n309 50077", "output": "-1" }, { "input": "1 100\n1 100000", "output": "-1" }, { "input": "1 10000\n1 10000", "output": "-1" }, { "input": "55674 93249\n846 1", "output": "4" }, { "input": "10 90\n9 10", "output": "-1" }, { "input": "23110 69794\n171 808", "output": "-1" }, { "input": "1 100000\n1 10000", "output": "-1" }, { "input": "1 9\n1 2", "output": "0" }, { "input": "58750 81357\n2 98022", "output": "-1" }, { "input": "82125 89348\n894 91369", "output": "-1" }, { "input": "25401 53663\n957 30449", "output": "-1" }, { "input": "2 12\n1 2", "output": "-1" }, { "input": "1 10000\n1 100000", "output": "-1" }, { "input": "1 100000\n1 99999", "output": "-1" }, { "input": "1 149\n8 2", "output": "2" }, { "input": "3 100\n1 1", "output": "-1" }, { "input": "1 18\n2 2", "output": "-1" }, { "input": "1 77\n9 1", "output": "1" }, { "input": "7330 94486\n968 141", "output": "9" }, { "input": "89778 98176\n863 61", "output": "1" }, { "input": "1 70\n6 5", "output": "2" } ]
1,460,552,891
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
h1, h2 = input().split(" ") a, b = input().split(" ") h1 = int(h1) h2 = int(h2) a = int(a) b = int(b) if a < b: print(-1) exit() hours_elapsed = 0 time = 14 current_hight = h1 while True: if time >= 24: time = 0 if time >= 10 and time <= 22: current_hight += a else: current_hight -= b hours_elapsed += 1 time += 1 if current_hight >= h2: break print(round(hours_elapsed / 24))
Title: Gabriel and Caterpillar Time Limit: None seconds Memory Limit: None megabytes Problem Description: The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=&gt;<=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple. Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by *a* cm per hour by day and slips down by *b* cm per hour by night. In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm. Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple. Input Specification: The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=&lt;<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters. The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour. Output Specification: Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple. If the caterpillar can't get the apple print the only integer <=-<=1. Demo Input: ['10 30\n2 1\n', '10 13\n1 1\n', '10 19\n1 2\n', '1 50\n5 4\n'] Demo Output: ['1\n', '0\n', '-1\n', '1\n'] Note: In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple. Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
```python h1, h2 = input().split(" ") a, b = input().split(" ") h1 = int(h1) h2 = int(h2) a = int(a) b = int(b) if a < b: print(-1) exit() hours_elapsed = 0 time = 14 current_hight = h1 while True: if time >= 24: time = 0 if time >= 10 and time <= 22: current_hight += a else: current_hight -= b hours_elapsed += 1 time += 1 if current_hight >= h2: break print(round(hours_elapsed / 24)) ```
0
797
C
Minimal string
PROGRAMMING
1,700
[ "data structures", "greedy", "strings" ]
null
null
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character. Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal. You should write a program that will help Petya win the game.
First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters.
Print resulting string *u*.
[ "cab\n", "acdb\n" ]
[ "abc\n", "abdc\n" ]
none
0
[ { "input": "cab", "output": "abc" }, { "input": "acdb", "output": "abdc" }, { "input": "a", "output": "a" }, { "input": "ab", "output": "ab" }, { "input": "ba", "output": "ab" }, { "input": "dijee", "output": "deeji" }, { "input": "bhrmc", "output": "bcmrh" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb" }, { "input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg", "output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee" }, { "input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr", "output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn" }, { "input": "bcaeaae", "output": "aaaecbe" }, { "input": "edcadcbcdd", "output": "abccdcddde" }, { "input": "a", "output": "a" }, { "input": "a", "output": "a" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "b", "output": "b" }, { "input": "a", "output": "a" }, { "input": "c", "output": "c" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "c", "output": "c" }, { "input": "b", "output": "b" }, { "input": "a", "output": "a" }, { "input": "e", "output": "e" }, { "input": "b", "output": "b" }, { "input": "b", "output": "b" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "aa", "output": "aa" }, { "input": "bb", "output": "bb" }, { "input": "bb", "output": "bb" }, { "input": "ba", "output": "ab" }, { "input": "ca", "output": "ac" }, { "input": "ab", "output": "ab" }, { "input": "cb", "output": "bc" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "da", "output": "ad" }, { "input": "ab", "output": "ab" }, { "input": "cd", "output": "cd" }, { "input": "aaa", "output": "aaa" }, { "input": "aaa", "output": "aaa" }, { "input": "aaa", "output": "aaa" }, { "input": "aab", "output": "aab" }, { "input": "aaa", "output": "aaa" }, { "input": "baa", "output": "aab" }, { "input": "bab", "output": "abb" }, { "input": "baa", "output": "aab" }, { "input": "ccc", "output": "ccc" }, { "input": "ddd", "output": "ddd" }, { "input": "ccd", "output": "ccd" }, { "input": "bca", "output": "acb" }, { "input": "cde", "output": "cde" }, { "input": "ece", "output": "cee" }, { "input": "bdd", "output": "bdd" }, { "input": "aaaa", "output": "aaaa" }, { "input": "aaaa", "output": "aaaa" }, { "input": "aaaa", "output": "aaaa" }, { "input": "abaa", "output": "aaab" }, { "input": "abab", "output": "aabb" }, { "input": "bbbb", "output": "bbbb" }, { "input": "bbba", "output": "abbb" }, { "input": "caba", "output": "aabc" }, { "input": "ccbb", "output": "bbcc" }, { "input": "abac", "output": "aabc" }, { "input": "daba", "output": "aabd" }, { "input": "cdbb", "output": "bbdc" }, { "input": "bddd", "output": "bddd" }, { "input": "dacb", "output": "abcd" }, { "input": "abcc", "output": "abcc" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "aaaaa", "output": "aaaaa" }, { "input": "baaab", "output": "aaabb" }, { "input": "aabbb", "output": "aabbb" }, { "input": "aabaa", "output": "aaaab" }, { "input": "abcba", "output": "aabcb" }, { "input": "bacbc", "output": "abbcc" }, { "input": "bacba", "output": "aabcb" }, { "input": "bdbda", "output": "adbdb" }, { "input": "accbb", "output": "abbcc" }, { "input": "dbccc", "output": "bcccd" }, { "input": "decca", "output": "acced" }, { "input": "dbbdd", "output": "bbddd" }, { "input": "accec", "output": "accce" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "aaaaaa", "output": "aaaaaa" }, { "input": "bbbbab", "output": "abbbbb" }, { "input": "bbbbab", "output": "abbbbb" }, { "input": "aaaaba", "output": "aaaaab" }, { "input": "cbbbcc", "output": "bbbccc" }, { "input": "aaacac", "output": "aaaacc" }, { "input": "bacbbc", "output": "abbbcc" }, { "input": "cacacc", "output": "aacccc" }, { "input": "badbdc", "output": "abbcdd" }, { "input": "ddadad", "output": "aadddd" }, { "input": "ccdece", "output": "cccede" }, { "input": "eecade", "output": "acdeee" }, { "input": "eabdcb", "output": "abbcde" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaaaaaa", "output": "aaaaaaa" }, { "input": "aaabbaa", "output": "aaaaabb" }, { "input": "baaabab", "output": "aaaabbb" }, { "input": "bbababa", "output": "aaabbbb" }, { "input": "bcccacc", "output": "acccbcc" }, { "input": "cbbcccc", "output": "bbccccc" }, { "input": "abacaaa", "output": "aaaaacb" }, { "input": "ccdbdac", "output": "acdbdcc" }, { "input": "bbacaba", "output": "aaabcbb" }, { "input": "abbaccc", "output": "aabbccc" }, { "input": "bdcbcab", "output": "abcbcdb" }, { "input": "dabcbce", "output": "abbccde" }, { "input": "abaaabe", "output": "aaaabbe" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "aaaaaaaa", "output": "aaaaaaaa" }, { "input": "ababbbba", "output": "aaabbbbb" }, { "input": "aaaaaaba", "output": "aaaaaaab" }, { "input": "babbbaab", "output": "aaabbbbb" }, { "input": "bcaccaab", "output": "aaabcccb" }, { "input": "bbccaabc", "output": "aabccbbc" }, { "input": "cacaaaac", "output": "aaaaaccc" }, { "input": "daacbddc", "output": "aabccddd" }, { "input": "cdbdcdaa", "output": "aadcdbdc" }, { "input": "bccbdacd", "output": "acdbccbd" }, { "input": "abbeaade", "output": "aaadebbe" }, { "input": "ccabecba", "output": "aabcebcc" }, { "input": "ececaead", "output": "aadecece" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aaaaaaaaa", "output": "aaaaaaaaa" }, { "input": "aabaaabbb", "output": "aaaaabbbb" }, { "input": "abbbbbaab", "output": "aaabbbbbb" }, { "input": "bbbaababb", "output": "aaabbbbbb" }, { "input": "babcaaccb", "output": "aaabcccbb" }, { "input": "ccbcabaac", "output": "aaabcbccc" }, { "input": "caaaccccb", "output": "aaabccccc" }, { "input": "abbcdbddb", "output": "abbbbdddc" }, { "input": "dbcaacbbb", "output": "aabbbccbd" }, { "input": "cadcbddac", "output": "aacddbcdc" }, { "input": "ecebadadb", "output": "aabddbece" }, { "input": "bdbeeccdd", "output": "bbccddeed" }, { "input": "daaedecda", "output": "aaadceded" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "abaaaaabbb", "output": "aaaaaabbbb" }, { "input": "bbaaaabaaa", "output": "aaaaaaabbb" }, { "input": "bbabbaaaaa", "output": "aaaaaabbbb" }, { "input": "cbaabcaacc", "output": "aaaacbbccc" }, { "input": "aaaaccccab", "output": "aaaaabcccc" }, { "input": "bccaccaacc", "output": "aaaccccbcc" }, { "input": "dbdccdcacd", "output": "accdccdbdd" }, { "input": "caaddaaccb", "output": "aaaabccddc" }, { "input": "adbbabcbdc", "output": "aabbbbccdd" }, { "input": "cdeabdbbad", "output": "aabbdbdedc" }, { "input": "eeddcbeeec", "output": "bcceeeddee" }, { "input": "bbcebddeba", "output": "abeddbecbb" } ]
1,619,513,343
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
16
171
6,451,200
import sys input=sys.stdin.readline from collections import defaultdict as dc from collections import Counter from bisect import bisect_right, bisect_left import math from operator import itemgetter from heapq import heapify, heappop, heappush from queue import PriorityQueue as pq s=input()[:-1] n=len(s) p=[0] t=[-1]*n for i in range(1,n): if not p: p.append(i) else: while(p and s[p[-1]]>s[i]): x=p.pop(-1) t[x]=i p.append(i) while p: x=p.pop(-1) t[x]=-1 p="" f=dc(int) x=-1 for i in range(n): if t[i]==-1: p+=s[i] f[i]=1 x=i j=x+1 i=x-1 #print(t,s) while(i>=0 and j<n): if f[i]==1 or f[j]==1: if f[i]: i-=1 else: j+=1 else: if s[j]<=s[i]: p+=s[j] j+=1 else: p+=s[i] i-=1 while(i>=0): if f[i]==0: p+=s[i] i-=1 while(j<n): if f[j]==0: p+=s[j] j+=1 print(p)
Title: Minimal string Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character. Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal. You should write a program that will help Petya win the game. Input Specification: First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. Output Specification: Print resulting string *u*. Demo Input: ['cab\n', 'acdb\n'] Demo Output: ['abc\n', 'abdc\n'] Note: none
```python import sys input=sys.stdin.readline from collections import defaultdict as dc from collections import Counter from bisect import bisect_right, bisect_left import math from operator import itemgetter from heapq import heapify, heappop, heappush from queue import PriorityQueue as pq s=input()[:-1] n=len(s) p=[0] t=[-1]*n for i in range(1,n): if not p: p.append(i) else: while(p and s[p[-1]]>s[i]): x=p.pop(-1) t[x]=i p.append(i) while p: x=p.pop(-1) t[x]=-1 p="" f=dc(int) x=-1 for i in range(n): if t[i]==-1: p+=s[i] f[i]=1 x=i j=x+1 i=x-1 #print(t,s) while(i>=0 and j<n): if f[i]==1 or f[j]==1: if f[i]: i-=1 else: j+=1 else: if s[j]<=s[i]: p+=s[j] j+=1 else: p+=s[i] i-=1 while(i>=0): if f[i]==0: p+=s[i] i-=1 while(j<n): if f[j]==0: p+=s[j] j+=1 print(p) ```
0
731
F
Video Cards
PROGRAMMING
1,900
[ "brute force", "data structures", "implementation", "math", "number theory" ]
null
null
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are *n* video cards in the shop, the power of the *i*-th video card is equal to integer value *a**i*. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced. Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of video cards in the shop. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200<=000) — powers of video cards.
The only line of the output should contain one integer value — the maximum possible total power of video cards working together.
[ "4\n3 2 15 9\n", "4\n8 2 2 7\n" ]
[ "27\n", "18\n" ]
In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28. In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.
3,000
[ { "input": "4\n3 2 15 9", "output": "27" }, { "input": "4\n8 2 2 7", "output": "18" }, { "input": "1\n1", "output": "1" }, { "input": "1\n123819", "output": "123819" }, { "input": "10\n9 6 8 5 5 2 8 9 2 2", "output": "52" }, { "input": "100\n17 23 71 25 50 71 85 46 78 72 89 26 23 70 40 59 23 43 86 81 70 89 92 98 85 88 16 10 26 91 61 58 23 13 75 39 48 15 73 79 59 29 48 32 45 44 25 37 58 54 45 67 27 77 20 64 95 41 80 53 69 24 38 97 59 94 50 88 92 47 95 31 66 48 48 56 37 76 42 74 55 34 43 79 65 82 70 52 48 56 36 17 14 65 77 81 88 18 33 40", "output": "5030" }, { "input": "100\n881 479 355 759 257 497 690 598 275 446 439 787 257 326 584 713 322 5 253 781 434 307 164 154 241 381 38 942 680 906 240 11 431 478 628 959 346 74 493 964 455 746 950 41 585 549 892 687 264 41 487 676 63 453 861 980 477 901 80 907 285 506 619 748 773 743 56 925 651 685 845 313 419 504 770 324 2 559 405 851 919 128 318 698 820 409 547 43 777 496 925 918 162 725 481 83 220 203 609 617", "output": "50692" }, { "input": "12\n2 3 5 5 5 5 5 5 5 5 5 5", "output": "50" } ]
1,689,345,926
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689345926.373158")# 1689345926.373172
Title: Video Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are *n* video cards in the shop, the power of the *i*-th video card is equal to integer value *a**i*. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced. Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of video cards in the shop. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200<=000) — powers of video cards. Output Specification: The only line of the output should contain one integer value — the maximum possible total power of video cards working together. Demo Input: ['4\n3 2 15 9\n', '4\n8 2 2 7\n'] Demo Output: ['27\n', '18\n'] Note: In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28. In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.
```python print("_RANDOM_GUESS_1689345926.373158")# 1689345926.373172 ```
0
384
A
Coder
PROGRAMMING
800
[ "implementation" ]
null
null
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
[ "2\n" ]
[ "2\nC.\n.C\n" ]
none
500
[ { "input": "2", "output": "2\nC.\n.C" }, { "input": "3", "output": "5\nC.C\n.C.\nC.C" }, { "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C" }, { "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C" }, { "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C" }, { "input": "100", "output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "101", "output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "500", "output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...." }, { "input": "501", "output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..." }, { "input": "755", "output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "888", "output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "998", "output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "999", "output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1000", "output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1", "output": "1\nC" } ]
1,577,529,630
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n = int(input()) print(n) board = [ ['.'] * n for i in range(n) ] for i in range(n): for j in range(n): if (i + j) % 2 == 0: board[i][j] = 'C' for line in board: print(''.join(line))
Title: Coder Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Demo Input: ['2\n'] Demo Output: ['2\nC.\n.C\n'] Note: none
```python n = int(input()) print(n) board = [ ['.'] * n for i in range(n) ] for i in range(n): for j in range(n): if (i + j) % 2 == 0: board[i][j] = 'C' for line in board: print(''.join(line)) ```
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20 1 80", "output": "1 20 40 60 80 100 " }, { "input": "10\n10 8 6 7 5 3 4 2 9 1", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 " }, { "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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 " }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 1 2 3 4 6 7 7 8 9 " }, { "input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59", "output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 " }, { "input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12", "output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 " }, { "input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84", "output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 " }, { "input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 " }, { "input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52", "output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 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": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 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 " }, { "input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6", "output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 " }, { "input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3", "output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 " }, { "input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32", "output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 " }, { "input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41", "output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 " }, { "input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82", "output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\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 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", "output": "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 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 " }, { "input": "49\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", "output": "1 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 " }, { "input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88", "output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 " }, { "input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 " }, { "input": "10\n100 90 80 70 60 50 40 30 20 10", "output": "10 20 30 40 50 60 70 80 90 100 " }, { "input": "1\n10", "output": "10 " } ]
1,690,568,204
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n = int(input()) s = input().split() lst = [int(w) for w in s] lst2=[] for i in range(1,n+1): while(min(lst)!=lst[0] and len(lst)!=1): lst[1]+=1 lst[0]-=1 lst2.append(str(lst[0])) lst.pop(0) print(" ".join(lst2))
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! Input Specification: The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. Output Specification: Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. Demo Input: ['4\n3 2 1 2\n', '3\n2 3 8\n'] Demo Output: ['1 2 2 3 \n', '2 3 8 \n'] Note: The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
```python n = int(input()) s = input().split() lst = [int(w) for w in s] lst2=[] for i in range(1,n+1): while(min(lst)!=lst[0] and len(lst)!=1): lst[1]+=1 lst[0]-=1 lst2.append(str(lst[0])) lst.pop(0) print(" ".join(lst2)) ```
0
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }, { "input": "3\n1 1 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "5\n1 2 4 3 5", "output": "4" }, { "input": "5\n2 2 2 4 3", "output": "4" }, { "input": "4\n1 2 3 1", "output": "3" }, { "input": "6\n7 3 10 7 3 11", "output": "4" }, { "input": "2\n3 4", "output": "2" }, { "input": "5\n1 1 1 1 1", "output": "3" }, { "input": "4\n1 3 2 3", "output": "3" }, { "input": "2\n2 3", "output": "2" }, { "input": "3\n32 10 23", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "4" }, { "input": "3\n1 2 4", "output": "3" }, { "input": "6\n3 3 3 2 4 4", "output": "4" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "5\n1 3 3 1 1", "output": "3" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "3\n2 2 1", "output": "2" }, { "input": "4\n2 3 3 3", "output": "3" }, { "input": "4\n3 2 3 3", "output": "3" }, { "input": "4\n2 1 1 1", "output": "2" }, { "input": "3\n2 1 4", "output": "3" }, { "input": "2\n6 7", "output": "2" }, { "input": "4\n3 3 4 3", "output": "3" }, { "input": "4\n1 1 2 5", "output": "4" }, { "input": "4\n1 8 7 3", "output": "3" }, { "input": "6\n2 2 2 2 2 3", "output": "4" }, { "input": "3\n2 2 5", "output": "3" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "5\n1 1 2 2 3", "output": "4" }, { "input": "5\n9 5 3 4 8", "output": "3" }, { "input": "3\n3 3 1", "output": "2" }, { "input": "4\n1 2 2 2", "output": "3" }, { "input": "3\n1 3 5", "output": "3" }, { "input": "4\n1 1 3 6", "output": "4" }, { "input": "6\n1 2 1 1 1 1", "output": "3" }, { "input": "3\n3 1 3", "output": "2" }, { "input": "5\n3 4 5 1 2", "output": "3" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "5\n3 1 2 5 2", "output": "4" }, { "input": "4\n1 1 1 4", "output": "4" }, { "input": "4\n2 6 1 10", "output": "4" }, { "input": "4\n2 2 3 2", "output": "3" }, { "input": "4\n4 2 2 1", "output": "2" }, { "input": "6\n1 1 1 1 1 4", "output": "5" }, { "input": "3\n3 2 2", "output": "2" }, { "input": "6\n1 3 5 1 7 4", "output": "5" }, { "input": "5\n1 2 4 8 16", "output": "5" }, { "input": "5\n1 2 4 4 4", "output": "4" }, { "input": "6\n4 2 1 2 3 1", "output": "3" }, { "input": "4\n3 2 1 5", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "3\n2 4 7", "output": "3" }, { "input": "5\n1 1 1 1 3", "output": "4" }, { "input": "3\n3 1 5", "output": "3" }, { "input": "4\n1 2 3 7", "output": "4" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "4\n2 1 2 2", "output": "3" }, { "input": "2\n4 5", "output": "2" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "3\n2 3 6", "output": "3" }, { "input": "6\n1 1 4 1 1 5", "output": "4" }, { "input": "5\n2 2 2 2 1", "output": "3" }, { "input": "2\n5 6", "output": "2" }, { "input": "4\n2 2 1 4", "output": "3" }, { "input": "5\n2 2 3 4 4", "output": "4" }, { "input": "4\n3 1 1 2", "output": "2" }, { "input": "5\n3 4 1 4 5", "output": "4" }, { "input": "4\n1 3 1 6", "output": "4" }, { "input": "5\n1 1 1 2 2", "output": "4" }, { "input": "4\n1 4 2 4", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 8", "output": "9" }, { "input": "4\n1 4 5 1", "output": "3" }, { "input": "5\n1 1 1 1 5", "output": "5" }, { "input": "4\n1 3 4 1", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "4\n2 3 2 4", "output": "3" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "3\n4 3 2", "output": "2" }, { "input": "3\n6 5 2", "output": "2" }, { "input": "69\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", "output": "35" }, { "input": "6\n1 1 1 1 1 2", "output": "4" }, { "input": "5\n1 2 5 4 5", "output": "4" }, { "input": "2\n9 10", "output": "2" }, { "input": "3\n1 1 5", "output": "3" }, { "input": "4\n3 4 3 5", "output": "3" }, { "input": "4\n1 4 3 3", "output": "3" }, { "input": "4\n7 1 3 4", "output": "2" }, { "input": "3\n100 100 1", "output": "2" }, { "input": "4\n5 2 2 2", "output": "2" } ]
1,523,467,456
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
61
6,963,200
n = int(input()) s = [int(x) for x in input().split()] summa = sum(s) q = 0 for i in range(n): q += s[i] if a * 2 >= summa: print(i + 1) exit()
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. Output Specification: Print the index of the day when Polycarp will celebrate the equator. Demo Input: ['4\n1 3 2 1\n', '6\n2 2 2 2 2 2\n'] Demo Output: ['2\n', '3\n'] Note: In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
```python n = int(input()) s = [int(x) for x in input().split()] summa = sum(s) q = 0 for i in range(n): q += s[i] if a * 2 >= summa: print(i + 1) exit() ```
-1
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,675,017,588
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
0
inp = list(map(int, input().split())) inpu = [] res = [] for i in range(inp[0]): inpu.append(input().split()) for i in inpu: if 'C' in i or 'M' in i or 'Y' in i or 'G' in i: res.append('#Color') break if len(res) == 0: res.append('#Black&White') [print(i) for i in res]
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python inp = list(map(int, input().split())) inpu = [] res = [] for i in range(inp[0]): inpu.append(input().split()) for i in inpu: if 'C' in i or 'M' in i or 'Y' in i or 'G' in i: res.append('#Color') break if len(res) == 0: res.append('#Black&White') [print(i) for i in res] ```
0
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,473,527,422
1,522
Python 3
WRONG_ANSWER
PRETESTS
3
62
0
s = input() l = [0]*4 for el in s: if el == 'L': l[0]+=1 if el == 'R': l[1]+=1 if el == 'U': l[2]+=1 if el == 'D': l[3]+=1 if sum(l)%4!=0: print(-1) else: k = sum(l)//4 ans = 0 for el in l: ans+=abs(k-el) print(ans//2)
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 s = input() l = [0]*4 for el in s: if el == 'L': l[0]+=1 if el == 'R': l[1]+=1 if el == 'U': l[2]+=1 if el == 'D': l[3]+=1 if sum(l)%4!=0: print(-1) else: k = sum(l)//4 ans = 0 for el in l: ans+=abs(k-el) print(ans//2) ```
0
373
B
Making Sequences is Fun
PROGRAMMING
1,600
[ "binary search", "implementation", "math" ]
null
null
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence. You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
The first line should contain a single integer — the answer to the problem.
[ "9 1 1\n", "77 7 7\n", "114 5 14\n", "1 1 2\n" ]
[ "9\n", "7\n", "6\n", "0\n" ]
none
1,000
[ { "input": "9 1 1", "output": "9" }, { "input": "77 7 7", "output": "7" }, { "input": "114 5 14", "output": "6" }, { "input": "1 1 2", "output": "0" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "462 183 8", "output": "19" }, { "input": "10000000000000000 1 1", "output": "674074074074073" }, { "input": "2155990066796462 2710473050636183 563261158", "output": "239230" }, { "input": "552719169048748 7822730034794389 374302919", "output": "92291" }, { "input": "6895788044242644 3474119895793364 732614708", "output": "588285" }, { "input": "9230573804495452 8577408935470783 90893866", "output": "6347082" }, { "input": "5363062262667637 2932858345469643 449197576", "output": "746200" }, { "input": "1951414609070432 8979282171178729 260239468", "output": "468658" }, { "input": "6289344232651169 4170875805886064 618522710", "output": "635520" }, { "input": "111984789523940 8017182602114316 976839488", "output": "7164" }, { "input": "3663662721733869 4845943245608254 787880219", "output": "290626" }, { "input": "10000000000000000 10000000000000000 1", "output": "588235294117647" }, { "input": "10000000000000000 9999999999999999 1", "output": "588235294117647" }, { "input": "9999999999999999 1 1", "output": "674074074074073" }, { "input": "3 1 4", "output": "0" }, { "input": "9999999999999998 1 1", "output": "674074074074072" }, { "input": "1 1000000000000000 1", "output": "0" }, { "input": "1 1000000000000000 1000000000", "output": "0" }, { "input": "10000000000000000 10000000000000000 1000000000", "output": "588235" }, { "input": "10000000000000000 10000000000000000 1", "output": "588235294117647" }, { "input": "121212121 3434343434 56", "output": "216450" }, { "input": "1 1 1", "output": "1" }, { "input": "98 55 1", "output": "47" }, { "input": "1 10000000000000000 123456", "output": "0" }, { "input": "10000000000000000 1000000000000001 1000000000", "output": "625000" } ]
1,668,030,397
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
def s(n): s = str(n) return len(s) def solve(w, m , k): f = 0 n = m nb = 0 while f<w: f += s(n)*k n += 1 nb +=1 return nb w, m, k = [int(x) for x in input().split()] print(solve(w,m,k))
Title: Making Sequences is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6. You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence. You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. Input Specification: The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109). Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: The first line should contain a single integer — the answer to the problem. Demo Input: ['9 1 1\n', '77 7 7\n', '114 5 14\n', '1 1 2\n'] Demo Output: ['9\n', '7\n', '6\n', '0\n'] Note: none
```python def s(n): s = str(n) return len(s) def solve(w, m , k): f = 0 n = m nb = 0 while f<w: f += s(n)*k n += 1 nb +=1 return nb w, m, k = [int(x) for x in input().split()] print(solve(w,m,k)) ```
0
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,597,865,259
2,147,483,647
Python 3
OK
TESTS
36
858
409,600
students = int(input()) rating = list(map(int, input().split(" "))) standing = 1 ratingCopy = rating.copy() res = [0] * students ratingCopy.sort() while len(ratingCopy) > 0: bestRating = ratingCopy[len(ratingCopy) - 1] ratingCopy = [i for i in ratingCopy if i != bestRating] counter = 0 for i in range(students): if rating[i] == bestRating: res[i] = standing counter = counter + 1 standing = counter + standing for n in res: print(n)
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python students = int(input()) rating = list(map(int, input().split(" "))) standing = 1 ratingCopy = rating.copy() res = [0] * students ratingCopy.sort() while len(ratingCopy) > 0: bestRating = ratingCopy[len(ratingCopy) - 1] ratingCopy = [i for i in ratingCopy if i != bestRating] counter = 0 for i in range(students): if rating[i] == bestRating: res[i] = standing counter = counter + 1 standing = counter + standing for n in res: print(n) ```
3
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n2 5", "output": "181" }, { "input": "6\n22 9 87 89 57\n1 6", "output": "264" }, { "input": "7\n52 36 31 23 74 78\n2 7", "output": "242" }, { "input": "8\n82 14 24 5 91 49 94\n3 8", "output": "263" }, { "input": "9\n12 40 69 39 59 21 59 5\n4 6", "output": "98" }, { "input": "10\n95 81 32 59 71 30 50 61 100\n1 6", "output": "338" }, { "input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14", "output": "617" }, { "input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17", "output": "399" }, { "input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23", "output": "846" }, { "input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16", "output": "730" }, { "input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35", "output": "1663" }, { "input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26", "output": "862" }, { "input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40", "output": "1061" }, { "input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28", "output": "344" }, { "input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60", "output": "1502" }, { "input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41", "output": "1767" }, { "input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24", "output": "219" }, { "input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44", "output": "1713" }, { "input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15", "output": "570" }, { "input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26", "output": "328" }, { "input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68", "output": "3385" }, { "input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77", "output": "3319" }, { "input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36", "output": "514" }, { "input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92", "output": "2599" }, { "input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27", "output": "618" }, { "input": "2\n3\n1 2", "output": "3" }, { "input": "5\n6 8 22 22\n2 3", "output": "8" }, { "input": "6\n3 12 27 28 28\n3 4", "output": "27" }, { "input": "9\n1 2 2 2 2 3 3 5\n3 7", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 1\n6 8", "output": "2" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17", "output": "23" }, { "input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8", "output": "23" }, { "input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31", "output": "2" }, { "input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45", "output": "30" }, { "input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17", "output": "285" }, { "input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58", "output": "173" }, { "input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65", "output": "126" }, { "input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65", "output": "326" }, { "input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48", "output": "784" }, { "input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93", "output": "1636" }, { "input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96", "output": "898" }, { "input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90", "output": "3016" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n66 95", "output": "29" }, { "input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52", "output": "82" }, { "input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44", "output": "2268" } ]
1,440,614,493
2,147,483,647
Python 3
OK
TESTS
50
124
0
n = int(input()) array = list(map(int, input().split())) a, b = map(int, input().split()) summ = 0 for i in range(a - 1, b - 1): summ += array[i] print(summ)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. Input Specification: The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated. Output Specification: Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. Demo Input: ['3\n5 6\n1 2\n', '3\n5 6\n1 3\n'] Demo Output: ['5\n', '11\n'] Note: none
```python n = int(input()) array = list(map(int, input().split())) a, b = map(int, input().split()) summ = 0 for i in range(a - 1, b - 1): summ += array[i] print(summ) ```
3.969
476
B
Dreamoon and WiFi
PROGRAMMING
1,300
[ "bitmasks", "brute force", "combinatorics", "dp", "math", "probabilities" ]
null
null
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
[ "++-+-\n+-+-+\n", "+-+-\n+-??\n", "+++\n??-\n" ]
[ "1.000000000000\n", "0.500000000000\n", "0.000000000000\n" ]
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
1,500
[ { "input": "++-+-\n+-+-+", "output": "1.000000000000" }, { "input": "+-+-\n+-??", "output": "0.500000000000" }, { "input": "+++\n??-", "output": "0.000000000000" }, { "input": "++++++++++\n+++??++?++", "output": "0.125000000000" }, { "input": "--+++---+-\n??????????", "output": "0.205078125000" }, { "input": "+--+++--+-\n??????????", "output": "0.246093750000" }, { "input": "+\n+", "output": "1.000000000000" }, { "input": "-\n?", "output": "0.500000000000" }, { "input": "+\n-", "output": "0.000000000000" }, { "input": "-\n-", "output": "1.000000000000" }, { "input": "-\n+", "output": "0.000000000000" }, { "input": "+\n?", "output": "0.500000000000" }, { "input": "++++++++++\n++++++++++", "output": "1.000000000000" }, { "input": "++++++++++\n++++-+++++", "output": "0.000000000000" }, { "input": "----------\n++++++++++", "output": "0.000000000000" }, { "input": "++++++++++\n++++??++++", "output": "0.250000000000" }, { "input": "----------\n+++?++++-+", "output": "0.000000000000" }, { "input": "++++++++++\n++++++++?+", "output": "0.500000000000" }, { "input": "--++++--+\n?-+?-??+-", "output": "0.250000000000" }, { "input": "----------\n??????????", "output": "0.000976562500" }, { "input": "+--++\n+--+-", "output": "0.000000000000" }, { "input": "-----++---\n????????+?", "output": "0.017578125000" }, { "input": "------+--+\n??????????", "output": "0.043945312500" }, { "input": "---++--\n???????", "output": "0.164062500000" }, { "input": "-----++\n???????", "output": "0.164062500000" }, { "input": "+---+--\n???????", "output": "0.164062500000" }, { "input": "---+-+\n??????", "output": "0.234375000000" }, { "input": "+++-+\n---++", "output": "0.000000000000" }, { "input": "++-+--+\n?-?+??+", "output": "0.375000000000" }, { "input": "----+++--\n-+?+++?--", "output": "0.000000000000" }, { "input": "+-----\n+?----", "output": "0.500000000000" } ]
1,663,059,325
2,147,483,647
PyPy 3-64
OK
TESTS
31
62
0
from math import comb def main(): s1 = input() s2 = input() orginal = 0 for s in s1: orginal += (1 if s == '+' else -1 ) sofar = 0 unk = 0 for s in s2: if s == '?': unk += 1 continue sofar += (1 if s == '+' else -1) offset = abs(orginal - sofar) total_comb = 1 << unk print(comb(unk,(unk + offset) // 2) / total_comb) main()
Title: Dreamoon and WiFi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? Input Specification: The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10. Output Specification: Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. Demo Input: ['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n'] Demo Output: ['1.000000000000\n', '0.500000000000\n', '0.000000000000\n'] Note: For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
```python from math import comb def main(): s1 = input() s2 = input() orginal = 0 for s in s1: orginal += (1 if s == '+' else -1 ) sofar = 0 unk = 0 for s in s2: if s == '?': unk += 1 continue sofar += (1 if s == '+' else -1) offset = abs(orginal - sofar) total_comb = 1 << unk print(comb(unk,(unk + offset) // 2) / total_comb) main() ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,683,978,061
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) # Initialize the vector sum to the zero vector vector_sum = [0, 0, 0] for i in range(n): # Read the force vector x, y, z = map(int, input().split()) # Add the force vector to the vector sum vector_sum[0] += x vector_sum[1] += y vector_sum[2] += z # Check if the vector sum is zero if vector_sum == [0, 0, 0]: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) # Initialize the vector sum to the zero vector vector_sum = [0, 0, 0] for i in range(n): # Read the force vector x, y, z = map(int, input().split()) # Add the force vector to the vector sum vector_sum[0] += x vector_sum[1] += y vector_sum[2] += z # Check if the vector sum is zero if vector_sum == [0, 0, 0]: print("YES") else: print("NO") ```
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,634,035,567
2,147,483,647
Python 3
OK
TESTS
35
124
6,758,400
M,N = map(int, input().split()) Area = M*N print(Area//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 M,N = map(int, input().split()) Area = M*N print(Area//2) ```
3.956411
328
B
Sheldon and Ice Pieces
PROGRAMMING
1,500
[ "greedy" ]
null
null
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry". Sheldon favourite number is *t*. He wants to have as many instances of *t* as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
The first line contains integer *t* (1<=≤<=*t*<=≤<=10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
Print the required number of instances.
[ "42\n23454\n", "169\n12118999\n" ]
[ "2\n", "1\n" ]
This problem contains very weak pretests.
500
[ { "input": "42\n23454", "output": "2" }, { "input": "169\n12118999", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "7\n777", "output": "3" }, { "input": "18\n8118", "output": "2" }, { "input": "33\n33333333", "output": "4" }, { "input": "1780\n8170880870810081711018110878070777078711", "output": "10" }, { "input": "2\n5255", "output": "4" }, { "input": "5\n22252", "output": "5" }, { "input": "9\n666969", "output": "6" }, { "input": "6\n9669969", "output": "7" }, { "input": "25\n52", "output": "1" }, { "input": "2591\n5291", "output": "1" }, { "input": "9697\n979966799976", "output": "3" }, { "input": "5518\n22882121", "output": "2" }, { "input": "533\n355233333332", "output": "4" }, { "input": "2569\n9592525295556669222269569596622566529699", "output": "10" }, { "input": "2559\n5252555622565626", "output": "4" }, { "input": "555\n225225252222255", "output": "5" }, { "input": "266\n565596629695965699", "output": "6" }, { "input": "22\n25552222222255", "output": "7" }, { "input": "99\n966969969696699969", "output": "9" }, { "input": "2591\n95195222396509125191259289255559161259521226176117", "output": "10" }, { "input": "9697\n76694996266995167659667796999669903799299696697971977966766996767667996967697669766777697969669669297966667776967677699767966667666769699790768276666766", "output": "34" }, { "input": "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454", "output": "23" }, { "input": "100\n11111000000000001010110010101100011011110101000000000001100110007111110010100000011000010011000011000010010000111101000010000000801000100111000410010100100000001011000000000101100010110001001100010001", "output": "63" }, { "input": "2569\n09629965966225566262579565696595696954525955599926383255926955906666526913925296256629966292216925259225261263256229509529259756291959568892569599592218262625256926619266669279659295979299556965525222", "output": "44" }, { "input": "2559\n52555995269265555695922255525995255259555259252562655622526292929555265526255252526255555296956995596262965522222225655655262255226222259622295225295525265995566255556225522559559295225625559595222652", "output": "48" }, { "input": "555\n25225222525252252255252525552255255522522522225252252525225555225552525255255252252225225255225552522252552252252522555255522225555252255555222225252525522252252255522522225252255522525552525225522552", "output": "66" }, { "input": "266\n26266956652996996666662666992669966292555295699956956255562529696222966929669665256625596629565696225696662556996969659952659665522965269529566599526566699292225569566599656596562966965669929996226599", "output": "62" }, { "input": "22\n35354953025524221524235223225255512262254275553262592555522123522225045753552560550228255220622552552252517202252456715552032250226729355222227262525262552362252277292927052612301558753527582221622055", "output": "66" }, { "input": "9\n99669996666966699999666999999666999699966669696969999696666669696967969666969696696696699669696999669669966696699666669996696666996699999696666696996666666969996996696696969666999999996666699966996696", "output": "199" }, { "input": "2569\n2569256925692569256925692569256925692569", "output": "10" }, { "input": "52\n222222222222222", "output": "7" }, { "input": "11\n1", "output": "0" }, { "input": "5\n2", "output": "1" } ]
1,570,036,616
2,147,483,647
PyPy 3
OK
TESTS
36
310
0
# import numpy as np def solution(): number = input() book = {} book_of_repeats = {} for i in number: intermidiate = i if intermidiate == "5": intermidiate = "2" elif intermidiate == "9": intermidiate = "6" book_of_repeats[intermidiate] = 0 if intermidiate in book: book[intermidiate] += 1 else: book[intermidiate] = 1 cubs = input() for i in cubs: intermidiate = i if intermidiate == "5": intermidiate = "2" elif intermidiate == "9": intermidiate = "6" if intermidiate in book_of_repeats: book_of_repeats[intermidiate] += 1 result = len(cubs)//len(number) for i in book: intermidiate = book_of_repeats[i]//book[i] if intermidiate < result: result = intermidiate print(result) def to_mixed_frac(first, second): while True: for i in range(2, first + 1): if first % i == 0 and second % i == 0: first //= i second //= i break else: break return str(first) + "/" + str(second) def array_to_int(array): for i in range(len(array)): array[i] = int(array[i]) return array def join0(array): result = "" for i in array: result += str(i) return result solution() # input-output by console
Title: Sheldon and Ice Pieces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry". Sheldon favourite number is *t*. He wants to have as many instances of *t* as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once. Input Specification: The first line contains integer *t* (1<=≤<=*t*<=≤<=10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9. Output Specification: Print the required number of instances. Demo Input: ['42\n23454\n', '169\n12118999\n'] Demo Output: ['2\n', '1\n'] Note: This problem contains very weak pretests.
```python # import numpy as np def solution(): number = input() book = {} book_of_repeats = {} for i in number: intermidiate = i if intermidiate == "5": intermidiate = "2" elif intermidiate == "9": intermidiate = "6" book_of_repeats[intermidiate] = 0 if intermidiate in book: book[intermidiate] += 1 else: book[intermidiate] = 1 cubs = input() for i in cubs: intermidiate = i if intermidiate == "5": intermidiate = "2" elif intermidiate == "9": intermidiate = "6" if intermidiate in book_of_repeats: book_of_repeats[intermidiate] += 1 result = len(cubs)//len(number) for i in book: intermidiate = book_of_repeats[i]//book[i] if intermidiate < result: result = intermidiate print(result) def to_mixed_frac(first, second): while True: for i in range(2, first + 1): if first % i == 0 and second % i == 0: first //= i second //= i break else: break return str(first) + "/" + str(second) def array_to_int(array): for i in range(len(array)): array[i] = int(array[i]) return array def join0(array): result = "" for i in array: result += str(i) return result solution() # input-output by console ```
3
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200", "output": "YES" }, { "input": "2\n100 200", "output": "NO" }, { "input": "2\n200 100", "output": "NO" }, { "input": "3\n100 100 100", "output": "NO" }, { "input": "3\n200 200 200", "output": "NO" }, { "input": "3\n200 100 200", "output": "NO" }, { "input": "4\n100 100 100 100", "output": "YES" }, { "input": "4\n200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100", "output": "YES" }, { "input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100", "output": "NO" }, { "input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200", "output": "YES" }, { "input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200", "output": "YES" }, { "input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200", "output": "NO" }, { "input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100", "output": "YES" }, { "input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100", "output": "NO" }, { "input": "5\n200 200 200 200 200", "output": "NO" }, { "input": "9\n100 100 100 200 100 100 200 100 200", "output": "YES" }, { "input": "1\n200", "output": "NO" }, { "input": "7\n200 200 200 100 200 200 200", "output": "NO" }, { "input": "4\n100 100 200 200", "output": "YES" }, { "input": "6\n100 100 100 200 200 200", "output": "NO" }, { "input": "4\n200 100 100 200", "output": "YES" }, { "input": "5\n100 100 100 100 200", "output": "YES" } ]
1,667,102,218
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> using namespace std; int main() { int n, a; cin >> n; int c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { cin >> a; if (a == 100) { c1++; } } c2 = n - c1; if (c1 % 2 == 0 && c2 % 2 == 0) { cout << "YES"; } else if (c1 % 2 != 0 && c2 % 2 == 0) { cout << "NO"; } else if (c1 % 2 == 0 && c2 % 2 != 0) { if (c1 == 0) cout << "NO"; else cout << "YES"; } else { cout << "NO"; } }
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. Output Specification: In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). Demo Input: ['3\n100 200 100\n', '4\n100 100 100 200\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
```python #include <iostream> using namespace std; int main() { int n, a; cin >> n; int c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { cin >> a; if (a == 100) { c1++; } } c2 = n - c1; if (c1 % 2 == 0 && c2 % 2 == 0) { cout << "YES"; } else if (c1 % 2 != 0 && c2 % 2 == 0) { cout << "NO"; } else if (c1 % 2 == 0 && c2 % 2 != 0) { if (c1 == 0) cout << "NO"; else cout << "YES"; } else { cout << "NO"; } } ```
-1
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
1,605,054,231
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
26,316,800
n,k = map(int, input().split()) arr = list(map(int, input().split())) def f(): arr.append(arr[k - 1]) arr.pop(0) return False def giveHash(arr): hash = 0 temp = [str(i) for i in arr] return " ".join(temp) count = 0 seen = set() seen.add(giveHash(arr)) while(True): if(len(set(arr)) == 1): print(count) break else: f() curr = giveHash(arr) if(curr in seen): print("-1") break else: seen.add(curr) count += 1
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Output Specification: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Demo Input: ['3 2\n3 1 1\n', '3 1\n3 1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
```python n,k = map(int, input().split()) arr = list(map(int, input().split())) def f(): arr.append(arr[k - 1]) arr.pop(0) return False def giveHash(arr): hash = 0 temp = [str(i) for i in arr] return " ".join(temp) count = 0 seen = set() seen.add(giveHash(arr)) while(True): if(len(set(arr)) == 1): print(count) break else: f() curr = giveHash(arr) if(curr in seen): print("-1") break else: seen.add(curr) count += 1 ```
0