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
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,563,617,762
2,147,483,647
PyPy 3
OK
TESTS
13
310
1,433,600
s = [[0, 0], [0, 0]] for _ in range(int(input())): t, x, y = map(int, input().split()) s[t - 1][0] += x s[t - 1][1] += y for i in range(2): print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]])
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python s = [[0, 0], [0, 0]] for _ in range(int(input())): t, x, y = map(int, input().split()) s[t - 1][0] += x s[t - 1][1] += y for i in range(2): print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]]) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7", "output": "37 37" }, { "input": "40 10\n1 2 3 4 5 6 7 10 10 10", "output": "223 158" }, { "input": "1 1\n6", "output": "6 6" }, { "input": "1 2\n10 9", "output": "10 9" }, { "input": "2 1\n7", "output": "13 13" }, { "input": "2 2\n7 2", "output": "13 3" }, { "input": "3 2\n4 7", "output": "18 9" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "10 10\n3 1 2 2 1 1 2 1 2 3", "output": "20 13" }, { "input": "10 2\n7 3", "output": "34 34" }, { "input": "10 1\n19", "output": "145 145" }, { "input": "100 3\n29 36 35", "output": "1731 1731" }, { "input": "100 5\n3 38 36 35 2", "output": "2019 1941" }, { "input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62", "output": "50279 5479" }, { "input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4", "output": "1501 1501" }, { "input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2", "output": "12204 8871" } ]
1,622,615,343
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
218
0
n,m=map(int,input().split()) a=[int(i) for i in input().split()] b=[i for i in a] b.sort(reverse=True) c=[i for i in a] c.sort() cv=0 s=0 for i in range(n): # if cv==m-1: # cv=0 # print(b[cv]) # print(b) s=s+b[cv] b[cv]-=1 if cv==m-1 and b[m-1]<b[0]: cv=0 elif cv!=m-1: if b[cv]<b[cv+1]: cv+=1 print(s,end=" ") cv=0 s=0 for i in range(n): if c[cv]==0: cv+=1 s=s+c[cv] c[cv]-=1 print(s)
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. Output Specification: Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. Demo Input: ['4 3\n2 1 1\n', '4 3\n2 2 2\n'] Demo Output: ['5 5\n', '7 6\n'] Note: In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
```python n,m=map(int,input().split()) a=[int(i) for i in input().split()] b=[i for i in a] b.sort(reverse=True) c=[i for i in a] c.sort() cv=0 s=0 for i in range(n): # if cv==m-1: # cv=0 # print(b[cv]) # print(b) s=s+b[cv] b[cv]-=1 if cv==m-1 and b[m-1]<b[0]: cv=0 elif cv!=m-1: if b[cv]<b[cv+1]: cv+=1 print(s,end=" ") cv=0 s=0 for i in range(n): if c[cv]==0: cv+=1 s=s+c[cv] c[cv]-=1 print(s) ```
0
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat.
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "0" }, { "input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS", "output": "0" }, { "input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS", "output": "30" }, { "input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..", "output": "80" }, { "input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS", "output": "0" }, { "input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..", "output": "17" }, { "input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS", "output": "0" }, { "input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S", "output": "64" }, { "input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S", "output": "28" }, { "input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S", "output": "10" }, { "input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.", "output": "0" }, { "input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS", "output": "0" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "4 3\n.S.\nS.S\n.S.\nS.S", "output": "0" }, { "input": "2 3\n...\nSSS", "output": "3" }, { "input": "2 4\nS.SS\nS.SS", "output": "2" }, { "input": "2 2\n..\n.S", "output": "3" }, { "input": "3 2\n.S\n.S\nSS", "output": "0" }, { "input": "2 4\nSS.S\n..S.", "output": "0" }, { "input": "2 3\n...\nS..", "output": "5" } ]
1,669,224,565
2,147,483,647
Python 3
OK
TESTS
42
124
0
n,m=map(int,input().split()) a=set() b=set() for i in range(n): s=input() for j in range(m): if s[j]=="S": a.add(i),b.add(j) print((n*m)-(len(a)*len(b)))
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Input Specification: The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. Output Specification: Output the maximum number of cake cells that the cakeminator can eat. Demo Input: ['3 4\nS...\n....\n..S.\n'] Demo Output: ['8\n'] Note: For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
```python n,m=map(int,input().split()) a=set() b=set() for i in range(n): s=input() for j in range(m): if s[j]=="S": a.add(i),b.add(j) print((n*m)-(len(a)*len(b))) ```
3
88
A
Chord
PROGRAMMING
1,200
[ "brute force", "implementation" ]
A. Chord
2
256
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him.
The only line contains 3 space-separated notes in the above-given notation.
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
[ "C E G\n", "C# B F\n", "A B H\n" ]
[ "major\n", "minor\n", "strange\n" ]
none
500
[ { "input": "C E G", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A B H", "output": "strange" }, { "input": "G H E", "output": "minor" }, { "input": "D# B G", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "F H E", "output": "strange" }, { "input": "B F# G", "output": "strange" }, { "input": "F# H C", "output": "strange" }, { "input": "C# F C", "output": "strange" }, { "input": "G# C# E", "output": "minor" }, { "input": "D# H G#", "output": "minor" }, { "input": "C F A", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "G D# B", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "G# C# F", "output": "major" }, { "input": "D# C G#", "output": "major" }, { "input": "C# F B", "output": "minor" }, { "input": "D# C G", "output": "minor" }, { "input": "A D F", "output": "minor" }, { "input": "F# H D", "output": "minor" }, { "input": "D A F", "output": "minor" }, { "input": "D A F#", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A C F", "output": "major" }, { "input": "D F# H", "output": "minor" }, { "input": "H G# D#", "output": "minor" }, { "input": "A D F#", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "D# H F#", "output": "major" }, { "input": "A D F#", "output": "major" }, { "input": "B G D#", "output": "major" }, { "input": "E A C#", "output": "major" }, { "input": "D H G", "output": "major" }, { "input": "H D F#", "output": "minor" }, { "input": "G D# C", "output": "minor" }, { "input": "H D G", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "D# A E", "output": "strange" }, { "input": "A F E", "output": "strange" }, { "input": "C E F", "output": "strange" }, { "input": "A B C", "output": "strange" }, { "input": "E F D#", "output": "strange" }, { "input": "C G# G#", "output": "strange" }, { "input": "F D# G#", "output": "strange" }, { "input": "B G D#", "output": "major" }, { "input": "E E G#", "output": "strange" }, { "input": "A G H", "output": "strange" }, { "input": "F E A", "output": "strange" }, { "input": "D B E", "output": "strange" }, { "input": "G# C# D", "output": "strange" }, { "input": "D# D# F#", "output": "strange" }, { "input": "H B G", "output": "strange" }, { "input": "D C B", "output": "strange" }, { "input": "D B B", "output": "strange" }, { "input": "C A H", "output": "strange" }, { "input": "F# H F#", "output": "strange" }, { "input": "A F F#", "output": "strange" }, { "input": "C D C", "output": "strange" }, { "input": "G F# A", "output": "strange" }, { "input": "C C# D", "output": "strange" }, { "input": "C A E", "output": "minor" }, { "input": "A H B", "output": "strange" }, { "input": "B E F#", "output": "strange" }, { "input": "G# G# A", "output": "strange" }, { "input": "B C# C#", "output": "strange" }, { "input": "C G D#", "output": "minor" }, { "input": "C B D#", "output": "strange" }, { "input": "F H F", "output": "strange" }, { "input": "E G# C", "output": "strange" }, { "input": "F# F# F#", "output": "strange" }, { "input": "F C F", "output": "strange" }, { "input": "A F D", "output": "minor" } ]
1,574,060,659
2,147,483,647
PyPy 3
OK
TESTS
75
310
0
import sys arr = sys.stdin.readline().strip().split() accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] def whatTheAccord(arr): global accords positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])] for i in range(len(accords)): if accords[i] in arr and accords[(i+3)%len(accords)] in arr and accords[(i+7)%len(accords)] in arr: return 'minor' for i in range(len(accords)): if accords[i] in arr and accords[(i+4)%len(accords)] in arr and accords[(i+7)%len(accords)] in arr: return 'major' return 'strange' def findDistance(pos1,pos2): if pos2>pos1: return pos2-pos1 else: return pos1-pos2 print(whatTheAccord(arr))
Title: Chord Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him. Input Specification: The only line contains 3 space-separated notes in the above-given notation. Output Specification: Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. Demo Input: ['C E G\n', 'C# B F\n', 'A B H\n'] Demo Output: ['major\n', 'minor\n', 'strange\n'] Note: none
```python import sys arr = sys.stdin.readline().strip().split() accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] def whatTheAccord(arr): global accords positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])] for i in range(len(accords)): if accords[i] in arr and accords[(i+3)%len(accords)] in arr and accords[(i+7)%len(accords)] in arr: return 'minor' for i in range(len(accords)): if accords[i] in arr and accords[(i+4)%len(accords)] in arr and accords[(i+7)%len(accords)] in arr: return 'major' return 'strange' def findDistance(pos1,pos2): if pos2>pos1: return pos2-pos1 else: return pos1-pos2 print(whatTheAccord(arr)) ```
3.9225
995
A
Tesla
PROGRAMMING
2,100
[ "constructive algorithms", "implementation" ]
null
null
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be represented as a rectangle with $4$ rows and $n$ ($n \le 50$) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having $k$ ($k \le 2n$) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places. However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. Allen knows he will be a very busy man, and will only have time to move cars at most $20000$ times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important.
The first line of the input contains two space-separated integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 2n$), representing the number of columns and the number of cars, respectively. The next four lines will contain $n$ integers each between $0$ and $k$ inclusive, representing the initial state of the parking lot. The rows are numbered $1$ to $4$ from top to bottom and the columns are numbered $1$ to $n$ from left to right. In the first and last line, an integer $1 \le x \le k$ represents a parking spot assigned to car $x$ (you can only move this car to this place), while the integer $0$ represents a empty space (you can't move any car to this place). In the second and third line, an integer $1 \le x \le k$ represents initial position of car $x$, while the integer $0$ represents an empty space (you can move any car to this place). Each $x$ between $1$ and $k$ appears exactly once in the second and third line, and exactly once in the first and fourth line.
If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $20000$ car moves, then print $m$, the number of moves, on the first line. On the following $m$ lines, print the moves (one move per line) in the format $i$ $r$ $c$, which corresponds to Allen moving car $i$ to the neighboring space at row $r$ and column $c$. If it is not possible for Allen to move all the cars to the correct spaces with at most $20000$ car moves, print a single line with the integer $-1$.
[ "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "1 2\n1\n2\n1\n2\n", "1 2\n1\n1\n2\n2\n" ]
[ "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "-1\n", "2\n1 1 1\n2 4 1\n" ]
In the first sample test case, all cars are in front of their spots except car $5$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $20000$ will be accepted. In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.
500
[ { "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2" }, { "input": "1 2\n1\n2\n1\n2", "output": "-1" }, { "input": "1 2\n1\n1\n2\n2", "output": "2\n1 1 1\n2 4 1" }, { "input": "2 2\n1 0\n0 2\n0 1\n0 2", "output": "7\n2 2 1\n1 2 2\n2 3 1\n1 2 1\n2 3 2\n1 1 1\n2 4 2" }, { "input": "7 14\n2 11 1 14 9 8 5\n12 6 7 1 10 2 3\n14 13 9 8 5 4 11\n13 6 4 3 12 7 10", "output": "-1" }, { "input": "10 20\n18 7 3 16 5 8 19 2 20 12\n15 16 7 11 14 3 12 4 8 10\n19 18 20 1 17 9 5 2 6 13\n11 15 13 17 6 9 14 1 10 4", "output": "220\n9 4 6\n17 3 6\n1 3 5\n20 3 4\n18 3 3\n19 3 2\n15 3 1\n16 2 1\n7 2 2\n11 2 3\n14 2 4\n3 2 5\n12 2 6\n4 2 7\n8 2 8\n10 2 9\n13 2 10\n6 3 10\n2 3 9\n5 3 8\n17 3 7\n1 3 6\n20 3 5\n18 3 4\n19 3 3\n15 3 2\n16 3 1\n7 1 2\n11 2 2\n14 2 3\n3 2 4\n12 2 5\n4 2 6\n8 2 7\n10 2 8\n13 2 9\n6 2 10\n2 3 10\n5 3 9\n17 3 8\n1 3 7\n20 3 6\n18 3 5\n19 3 4\n15 4 2\n16 3 2\n11 2 1\n14 2 2\n3 2 3\n12 2 4\n4 2 5\n8 2 6\n10 2 7\n13 2 8\n6 2 9\n2 2 10\n5 3 10\n17 3 9\n1 3 8\n20 3 7\n18 3 6\n19 3 5\n16 3 3\n11 3 1\n14 2 1\n3 1 3..." }, { "input": "2 1\n0 0\n0 0\n0 1\n0 1", "output": "1\n1 4 2" }, { "input": "2 3\n0 2\n0 1\n3 2\n3 1", "output": "7\n1 2 1\n2 2 2\n3 4 1\n1 3 1\n2 1 2\n1 3 2\n1 4 2" }, { "input": "8 12\n9 7 10 5 0 0 8 0\n11 6 5 4 1 10 2 0\n0 8 0 7 0 3 9 12\n6 4 1 2 0 11 12 3", "output": "105\n11 3 1\n6 2 1\n5 2 2\n4 2 3\n1 2 4\n10 2 5\n2 2 6\n12 2 8\n9 3 8\n3 3 7\n7 3 5\n8 3 3\n11 3 2\n6 3 1\n5 2 1\n4 2 2\n1 2 3\n10 2 4\n2 2 5\n12 2 7\n9 2 8\n3 3 8\n7 3 6\n8 3 4\n11 3 3\n6 4 1\n5 3 1\n4 2 1\n1 2 2\n10 2 3\n2 2 4\n12 2 6\n9 2 7\n3 4 8\n7 3 7\n8 3 5\n11 3 4\n5 3 2\n4 3 1\n1 2 1\n10 1 3\n2 2 3\n12 2 5\n9 2 6\n7 3 8\n8 3 6\n11 3 5\n5 3 3\n4 3 2\n1 3 1\n2 2 2\n12 2 4\n9 2 5\n7 2 8\n8 3 7\n11 3 6\n5 3 4\n4 4 2\n1 3 2\n2 2 1\n12 2 3\n9 2 4\n7 2 7\n8 3 8\n11 4 6\n5 3 5\n1 3 3\n2 3 1\n12 2 2\n9 2 3..." }, { "input": "1 1\n0\n1\n0\n1", "output": "2\n1 3 1\n1 4 1" }, { "input": "2 4\n3 4\n2 1\n3 4\n2 1", "output": "-1" }, { "input": "3 5\n2 1 5\n5 3 2\n4 0 1\n0 4 3", "output": "18\n4 3 2\n5 3 1\n3 2 1\n2 2 2\n1 2 3\n4 4 2\n5 3 2\n3 3 1\n2 2 1\n1 2 2\n5 3 3\n3 3 2\n2 1 1\n1 1 2\n5 2 3\n3 3 3\n5 1 3\n3 4 3" }, { "input": "8 15\n15 13 0 14 2 7 4 9\n11 5 14 2 15 12 10 13\n1 9 7 4 3 8 0 6\n3 1 12 6 10 11 8 5", "output": "136\n8 3 7\n3 3 6\n4 3 5\n7 3 4\n9 3 3\n1 3 2\n11 3 1\n5 2 1\n14 2 2\n2 2 3\n15 2 4\n12 2 5\n10 2 6\n13 2 7\n6 2 8\n8 4 7\n3 3 7\n4 3 6\n7 3 5\n9 3 4\n1 4 2\n11 3 2\n5 3 1\n14 2 1\n2 2 2\n15 2 3\n12 2 4\n10 2 5\n13 2 6\n6 2 7\n3 3 8\n4 3 7\n7 3 6\n9 3 5\n11 3 3\n5 3 2\n14 3 1\n2 2 1\n15 2 2\n12 2 3\n10 2 4\n13 2 5\n6 2 6\n3 2 8\n4 3 8\n7 3 7\n9 3 6\n11 3 4\n5 3 3\n14 3 2\n2 3 1\n15 2 1\n12 2 2\n10 2 3\n13 2 4\n6 2 5\n3 2 7\n4 2 8\n7 3 8\n9 3 7\n11 3 5\n5 3 4\n14 3 3\n2 3 2\n15 1 1\n12 2 1\n10 2 2\n13 2 3\n..." }, { "input": "8 14\n12 7 0 5 4 3 13 6\n6 9 7 0 4 12 2 14\n10 8 13 1 5 0 11 3\n2 0 8 10 9 14 1 11", "output": "81\n4 1 5\n12 2 5\n2 2 6\n14 2 7\n3 2 8\n11 3 8\n5 3 6\n1 3 5\n13 3 4\n8 3 3\n10 3 2\n6 3 1\n9 2 1\n7 2 2\n12 2 4\n2 2 5\n14 2 6\n3 2 7\n11 4 8\n5 3 7\n1 3 6\n13 3 5\n8 4 3\n10 3 3\n6 3 2\n9 3 1\n7 1 2\n12 2 3\n2 2 4\n14 2 5\n3 2 6\n5 3 8\n1 3 7\n13 3 6\n10 3 4\n6 3 3\n9 3 2\n12 2 2\n2 2 3\n14 2 4\n3 1 6\n5 2 8\n1 4 7\n13 3 7\n10 4 4\n6 3 4\n9 3 3\n12 2 1\n2 2 2\n14 2 3\n5 2 7\n13 3 8\n6 3 5\n9 3 4\n12 1 1\n2 2 1\n14 2 2\n5 2 6\n13 2 8\n6 3 6\n9 3 5\n2 3 1\n14 2 1\n5 2 5\n13 2 7\n6 3 7\n9 4 5\n2 4 1\n14 3 ..." }, { "input": "10 1\n0 0 1 0 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "output": "1\n1 1 3" }, { "input": "10 10\n0 2 0 9 0 10 6 0 0 0\n0 9 2 0 0 0 4 0 6 0\n0 0 10 0 7 1 5 8 3 0\n1 5 3 4 7 0 8 0 0 0", "output": "116\n9 2 1\n2 2 2\n4 2 6\n6 2 8\n3 3 10\n8 3 9\n5 3 8\n1 3 7\n7 4 5\n10 3 4\n9 3 1\n2 1 2\n4 2 5\n6 2 7\n3 2 10\n8 3 10\n5 3 9\n1 3 8\n10 3 5\n9 3 2\n4 2 4\n6 1 7\n3 2 9\n8 2 10\n5 3 10\n1 3 9\n10 3 6\n9 3 3\n4 2 3\n3 2 8\n8 2 9\n5 2 10\n1 3 10\n10 3 7\n9 3 4\n4 2 2\n3 2 7\n8 2 8\n5 2 9\n1 2 10\n10 3 8\n9 3 5\n4 2 1\n3 2 6\n8 2 7\n5 2 8\n1 2 9\n10 3 9\n9 3 6\n4 3 1\n3 2 5\n8 2 6\n5 2 7\n1 2 8\n10 3 10\n9 3 7\n4 3 2\n3 2 4\n8 2 5\n5 2 6\n1 2 7\n10 2 10\n9 3 8\n4 3 3\n3 2 3\n8 2 4\n5 2 5\n1 2 6\n10 2 9\n9 3 ..." }, { "input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "68\n1 2 17\n1 2 16\n1 2 15\n1 2 14\n1 2 13\n1 2 12\n1 2 11\n1 2 10\n1 2 9\n1 2 8\n1 2 7\n1 2 6\n1 2 5\n1 2 4\n1 2 3\n1 2 2\n1 2 1\n1 3 1\n1 3 2\n1 3 3\n1 3 4\n1 3 5\n1 3 6\n1 3 7\n1 3 8\n1 3 9\n1 3 10\n1 3 11\n1 3 12\n1 3 13\n1 3 14\n1 3 15\n1 3 16\n1 3 17\n1 3 18\n1 3 19\n1 3 20\n1 3 21\n1 3 22\n1 3 23\n1 3 24\n1 3 25\n1 3 26\n1 3 27\n1 3 28\n1 3 29\n1 3 30\n1 3 31\n1 3 32\n1 3 33\n1 3 34\n1 3 35\n1 3 36\n1 3 37\n1 3 38\n1 3 39\n1 3 40\n1 3 41\n1 3 42\n1 3 43\n1 3 44\n1 3 45\n1 3 46\n1 3 47\n1 3 48\n1 3 4..." }, { "input": "40 80\n38 45 18 59 53 44 49 27 46 63 42 61 26 39 29 7 52 79 11 73 24 69 55 43 20 32 37 25 57 19 1 54 4 22 36 16 71 15 65 12\n46 1 52 54 27 3 40 10 8 41 72 17 11 44 28 73 55 65 60 13 12 43 16 26 34 53 50 15 62 35 33 48 58 42 57 80 21 51 64 74\n22 29 4 18 69 36 31 68 77 61 37 6 70 59 78 19 25 71 79 56 30 38 66 2 32 7 47 75 67 39 9 76 49 23 63 24 5 45 20 14\n33 5 50 8 13 17 14 74 10 66 34 58 41 72 2 60 51 77 21 56 70 40 9 35 64 78 68 6 47 23 75 80 28 30 3 76 67 48 62 31", "output": "3360\n56 4 20\n79 3 20\n71 3 19\n25 3 18\n19 3 17\n78 3 16\n59 3 15\n70 3 14\n6 3 13\n37 3 12\n61 3 11\n77 3 10\n68 3 9\n31 3 8\n36 3 7\n69 3 6\n18 3 5\n4 3 4\n29 3 3\n22 3 2\n46 3 1\n1 2 1\n52 2 2\n54 2 3\n27 2 4\n3 2 5\n40 2 6\n10 2 7\n8 2 8\n41 2 9\n72 2 10\n17 2 11\n11 2 12\n44 2 13\n28 2 14\n73 2 15\n55 2 16\n65 2 17\n60 2 18\n13 2 19\n12 2 20\n43 2 21\n16 2 22\n26 2 23\n34 2 24\n53 2 25\n50 2 26\n15 2 27\n62 2 28\n35 2 29\n33 2 30\n48 2 31\n58 2 32\n42 2 33\n57 2 34\n80 2 35\n21 2 36\n51 2 37\n64 2 3..." }, { "input": "40 77\n60 31 50 41 4 12 27 6 65 11 0 34 44 13 42 18 64 15 76 59 36 69 70 71 66 57 37 25 26 2 23 24 45 55 67 29 75 49 33 40\n11 14 65 44 74 51 55 16 19 29 75 41 27 35 69 10 70 2 73 58 45 61 0 7 30 6 23 25 66 63 28 62 24 77 20 43 0 18 50 52\n54 64 60 57 31 8 72 26 76 0 71 48 32 17 12 39 15 67 1 68 36 40 46 49 4 21 56 33 47 3 59 34 9 22 38 53 13 5 37 42\n51 52 30 9 20 62 14 74 38 21 48 0 16 28 43 10 47 72 56 5 17 58 61 53 77 63 0 7 39 54 22 19 3 1 68 46 73 32 8 35", "output": "3200\n7 2 23\n30 2 24\n6 2 25\n23 2 26\n25 1 28\n66 2 28\n63 2 29\n28 2 30\n62 2 31\n24 2 32\n77 2 33\n20 2 34\n43 2 35\n18 2 37\n50 2 38\n52 2 39\n42 2 40\n37 3 40\n5 3 39\n13 3 38\n53 3 37\n38 3 36\n22 3 35\n9 3 34\n34 3 33\n59 3 32\n3 3 31\n47 3 30\n33 3 29\n56 3 28\n21 3 27\n4 3 26\n49 3 25\n46 3 24\n40 3 23\n36 3 22\n68 3 21\n1 3 20\n67 3 19\n15 3 18\n39 3 17\n12 3 16\n17 3 15\n32 3 14\n48 3 13\n71 3 12\n76 3 10\n26 3 9\n72 3 8\n8 3 7\n31 3 6\n57 3 5\n60 3 4\n64 3 3\n54 3 2\n11 3 1\n14 2 1\n65 2 2\n44..." }, { "input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "34\n1 3 27\n1 3 28\n1 3 29\n1 3 30\n1 3 31\n1 3 32\n1 3 33\n1 3 34\n1 3 35\n1 3 36\n1 3 37\n1 3 38\n1 3 39\n1 3 40\n1 3 41\n1 3 42\n1 3 43\n1 3 44\n1 3 45\n1 3 46\n1 3 47\n1 3 48\n1 3 49\n1 3 50\n1 2 50\n1 2 49\n1 2 48\n1 2 47\n1 2 46\n1 2 45\n1 2 44\n1 2 43\n1 2 42\n1 1 42" }, { "input": "37 22\n0 18 0 0 0 16 0 0 0 0 1 21 0 0 0 4 0 15 0 8 0 0 0 0 0 0 0 9 14 0 0 0 22 0 0 3 0\n0 0 0 0 0 21 0 0 2 0 0 0 0 0 0 13 0 0 0 0 0 0 22 12 9 15 11 8 0 16 0 0 0 0 0 0 0\n0 3 1 0 0 0 0 14 0 20 0 7 0 0 0 4 0 6 0 0 5 0 18 0 17 10 0 0 0 0 19 0 0 0 0 0 0\n13 0 2 19 10 0 0 17 0 0 20 0 0 5 11 0 0 6 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0", "output": "852\n21 2 5\n2 2 8\n13 2 15\n22 2 22\n12 2 23\n9 2 24\n15 2 25\n11 2 26\n8 2 27\n16 2 29\n19 3 32\n10 3 27\n17 3 26\n18 3 24\n5 3 22\n6 4 18\n4 3 17\n7 3 13\n20 3 11\n14 3 9\n1 3 4\n3 3 3\n21 2 4\n2 2 7\n13 2 14\n22 2 21\n12 2 22\n9 2 23\n15 2 24\n11 2 25\n8 2 26\n16 2 28\n19 3 33\n10 3 28\n17 3 27\n18 3 25\n5 3 23\n4 3 18\n7 3 14\n20 4 11\n14 3 10\n1 3 5\n3 3 4\n21 2 3\n2 2 6\n13 2 13\n22 2 20\n12 2 21\n9 2 22\n15 2 23\n11 2 24\n8 2 25\n16 2 27\n19 3 34\n10 3 29\n17 3 28\n18 3 26\n5 3 24\n4 3 19\n7 3 15\n..." }, { "input": "37 5\n0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 5 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0", "output": "151\n3 2 12\n5 2 24\n2 3 26\n1 3 22\n4 3 9\n3 2 11\n5 2 23\n2 3 27\n1 3 23\n4 3 10\n3 2 10\n5 2 22\n2 3 28\n1 3 24\n4 3 11\n3 2 9\n5 2 21\n2 3 29\n1 3 25\n4 3 12\n3 2 8\n5 2 20\n2 3 30\n1 3 26\n4 3 13\n3 2 7\n5 2 19\n2 3 31\n1 3 27\n4 3 14\n3 2 6\n5 2 18\n2 3 32\n1 3 28\n4 3 15\n3 2 5\n5 2 17\n2 3 33\n1 3 29\n4 3 16\n3 2 4\n5 2 16\n2 3 34\n1 3 30\n4 3 17\n3 2 3\n5 2 15\n2 3 35\n1 3 31\n4 3 18\n3 2 2\n5 2 14\n2 3 36\n1 3 32\n4 3 19\n3 2 1\n5 2 13\n2 3 37\n1 3 33\n4 3 20\n3 3 1\n5 2 12\n2 2 37\n1 3 34\n4 3 2..." }, { "input": "48 17\n0 0 0 0 0 0 14 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 16 0 0 0 1 0 0 0 3 0 0 15 0 0 0 0 0 0 0 11\n0 0 0 0 0 0 0 0 0 0 17 0 0 0 6 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 13 0 3 10 11 0 0 0 0 0 0 0 0 0\n0 0 0 2 0 0 0 0 0 0 0 0 0 0 4 0 15 0 0 0 0 0 0 0 0 0 0 9 0 0 16 0 0 12 0 0 0 0 0 0 5 0 0 0 0 0 7 14\n0 0 5 13 0 0 0 10 0 0 0 0 17 0 0 0 0 0 0 12 0 0 0 7 0 0 0 0 0 0 9 0 0 0 0 0 6 0 0 0 0 0 4 0 0 0 0 0", "output": "794\n17 2 10\n6 2 14\n8 2 18\n1 1 33\n13 2 34\n3 1 37\n10 2 37\n11 2 38\n14 2 48\n7 3 48\n5 3 42\n12 3 35\n16 3 32\n9 3 29\n15 3 18\n4 3 16\n2 3 5\n17 2 9\n6 2 13\n8 2 17\n13 2 33\n10 2 36\n11 2 37\n14 2 47\n7 2 48\n5 3 43\n12 3 36\n16 3 33\n9 3 30\n15 3 19\n4 3 17\n2 3 6\n17 2 8\n6 2 12\n8 2 16\n13 2 32\n10 2 35\n11 2 36\n14 2 46\n7 2 47\n5 3 44\n12 3 37\n16 3 34\n9 3 31\n15 3 20\n4 3 18\n2 3 7\n17 2 7\n6 2 11\n8 2 15\n13 2 31\n10 2 34\n11 2 35\n14 2 45\n7 2 46\n5 3 45\n12 3 38\n16 3 35\n9 4 31\n15 3 21\n..." }, { "input": "22 2\n0 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 2 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 1 0 0\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 2 0 0 0 0", "output": "65\n2 2 13\n1 3 21\n2 2 12\n1 3 22\n2 2 11\n1 2 22\n2 2 10\n1 2 21\n2 2 9\n1 2 20\n2 2 8\n1 2 19\n2 2 7\n1 2 18\n2 2 6\n1 2 17\n2 2 5\n1 2 16\n2 2 4\n1 2 15\n2 2 3\n1 2 14\n2 2 2\n1 2 13\n2 2 1\n1 2 12\n2 3 1\n1 2 11\n2 3 2\n1 2 10\n2 3 3\n1 2 9\n2 3 4\n1 2 8\n2 3 5\n1 2 7\n2 3 6\n1 2 6\n2 3 7\n1 2 5\n2 3 8\n1 2 4\n2 3 9\n1 2 3\n2 3 10\n1 2 2\n2 3 11\n1 2 1\n2 3 12\n1 3 1\n2 3 13\n1 3 2\n2 3 14\n1 3 3\n2 3 15\n1 3 4\n2 3 16\n1 3 5\n2 3 17\n1 3 6\n2 3 18\n1 3 7\n2 4 18\n1 3 8\n1 4 8" }, { "input": "12 3\n0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0\n2 0 0 0 0 3 0 0 0 1 0 0\n0 0 0 0 0 0 0 1 3 0 2 0", "output": "38\n1 3 11\n3 3 7\n2 3 2\n1 3 12\n3 3 8\n2 3 3\n1 2 12\n3 3 9\n2 3 4\n1 2 11\n3 4 9\n2 3 5\n1 2 10\n2 3 6\n1 2 9\n2 3 7\n1 2 8\n2 3 8\n1 2 7\n2 3 9\n1 2 6\n2 3 10\n1 2 5\n2 3 11\n1 2 4\n2 4 11\n1 2 3\n1 2 2\n1 2 1\n1 3 1\n1 3 2\n1 3 3\n1 3 4\n1 3 5\n1 3 6\n1 3 7\n1 3 8\n1 4 8" }, { "input": "10 20\n18 9 4 5 12 14 16 1 15 20\n11 13 16 6 18 5 20 17 4 3\n12 9 15 14 8 10 2 19 1 7\n6 11 13 2 7 19 10 3 8 17", "output": "-1" }, { "input": "10 20\n1 12 11 7 4 2 13 10 20 9\n18 9 1 5 16 15 8 20 7 13\n2 10 4 12 14 19 3 11 17 6\n3 18 8 6 15 19 16 14 17 5", "output": "200\n17 4 9\n11 3 9\n3 3 8\n19 4 6\n14 3 6\n12 3 5\n4 3 4\n10 3 3\n2 3 2\n18 3 1\n9 2 1\n1 2 2\n5 2 3\n16 2 4\n15 2 5\n8 2 6\n20 2 7\n7 2 8\n13 2 9\n6 2 10\n11 3 10\n3 3 9\n14 3 7\n12 3 6\n4 3 5\n10 3 4\n2 3 3\n18 3 2\n9 3 1\n1 2 1\n5 2 2\n16 2 3\n15 2 4\n8 2 5\n20 2 6\n7 2 7\n13 2 8\n6 2 9\n11 2 10\n3 3 10\n14 3 8\n12 3 7\n4 3 6\n10 3 5\n2 3 4\n18 4 2\n9 3 2\n1 1 1\n5 2 1\n16 2 2\n15 2 3\n8 2 4\n20 2 5\n7 2 6\n13 2 7\n6 2 8\n11 2 9\n3 2 10\n14 4 8\n12 3 8\n4 3 7\n10 3 6\n2 3 5\n9 3 3\n5 3 1\n16 2 1\n15 2 ..." }, { "input": "15 30\n20 24 17 13 26 8 5 6 27 14 18 22 25 2 15\n4 12 6 25 3 5 28 11 15 21 9 26 7 17 13\n19 20 24 16 2 23 8 29 22 30 1 27 10 14 18\n9 29 3 7 12 28 10 16 23 19 21 1 30 11 4", "output": "-1" }, { "input": "40 20\n15 0 0 0 0 0 0 0 7 3 0 0 18 0 0 0 4 0 1 0 0 0 11 0 0 0 0 0 0 0 0 0 5 0 0 14 2 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 12 18 17 0 0 0 0 20 0 6 0 0 14 13 0 19 2 0 0 4 0 0 0 0\n15 0 0 0 0 0 9 0 7 0 0 16 8 5 0 0 0 0 0 0 0 0 0 0 0 10 0 0 11 0 0 0 0 0 0 3 0 0 0 0\n0 16 0 0 0 0 0 17 0 0 0 0 6 0 0 0 8 0 0 0 0 0 0 0 13 10 0 0 19 0 0 0 0 12 9 20 0 0 0 0", "output": "895\n1 2 11\n12 2 16\n18 2 17\n17 2 18\n20 2 23\n6 2 25\n14 2 28\n13 2 29\n19 2 31\n2 2 32\n4 2 35\n3 3 37\n11 3 30\n10 4 26\n5 3 15\n8 3 14\n16 3 13\n7 3 10\n9 3 8\n15 3 2\n1 2 10\n12 2 15\n18 2 16\n17 2 17\n20 2 22\n6 2 24\n14 2 27\n13 2 28\n19 2 30\n2 2 31\n4 2 34\n3 3 38\n11 3 31\n5 3 16\n8 3 15\n16 3 14\n7 3 11\n9 3 9\n15 3 3\n1 2 9\n12 2 14\n18 2 15\n17 2 16\n20 2 21\n6 2 23\n14 2 26\n13 2 27\n19 2 29\n2 2 30\n4 2 33\n3 3 39\n11 3 32\n5 3 17\n8 3 16\n16 3 15\n7 3 12\n9 3 10\n15 3 4\n1 2 8\n12 2 13\n1..." } ]
1,544,712,164
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
1,126,400
def f(p, v = -10): global a if v == -10: return a[p[0]][p[1]] else: a[p[0]][p[1]] = v def ins(i, x, y): global mov, cnt mov[cnt][0] = i mov[cnt][1] = x + 1 cnt += 1 mov[cnt][2] = y + 1 def move_in(i): global A, B, tot if f(B[i]) == f(A[i]): f(A[i], 0) ins(f(B[i]), B[i][0], B[i][1]) tot += 1 def move(i): global n, A j = (i + 1) % (n * 2) x = f(A[j]) if x: f(A[i], x) ins(f(A[i]), A[i][0], A[i][1]) f(A[j], 0) move_in(i) mov = [[0 for i in range(3)] for j in range(20010)] n, k = map(int, input().strip().split(' ')) cnt, tot = 0, 0 a = [] for i in range(4): a.append(list(map(int, input().strip().split(' ')))) A, B = [], [] for i in range(n * 2): A.append((1 if i < n else 2, i if i < n else n * 2 - i - 1)) B.append((0 if i < n else 3, A[i][1])) if f(A[i]): move_in(i) o = 0 while o < n * 2 and f(A[o]): o += 1 if o == n * 2: print(-1) else: while tot < k: move(o) o = (o + 1) % (n * 2) print(cnt) print('\n'.join(' '.join(map(str, i)) for i in mov[:cnt]))
Title: Tesla Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. Allen's future parking lot can be represented as a rectangle with $4$ rows and $n$ ($n \le 50$) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having $k$ ($k \le 2n$) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places. However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. Allen knows he will be a very busy man, and will only have time to move cars at most $20000$ times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important. Input Specification: The first line of the input contains two space-separated integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 2n$), representing the number of columns and the number of cars, respectively. The next four lines will contain $n$ integers each between $0$ and $k$ inclusive, representing the initial state of the parking lot. The rows are numbered $1$ to $4$ from top to bottom and the columns are numbered $1$ to $n$ from left to right. In the first and last line, an integer $1 \le x \le k$ represents a parking spot assigned to car $x$ (you can only move this car to this place), while the integer $0$ represents a empty space (you can't move any car to this place). In the second and third line, an integer $1 \le x \le k$ represents initial position of car $x$, while the integer $0$ represents an empty space (you can move any car to this place). Each $x$ between $1$ and $k$ appears exactly once in the second and third line, and exactly once in the first and fourth line. Output Specification: If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $20000$ car moves, then print $m$, the number of moves, on the first line. On the following $m$ lines, print the moves (one move per line) in the format $i$ $r$ $c$, which corresponds to Allen moving car $i$ to the neighboring space at row $r$ and column $c$. If it is not possible for Allen to move all the cars to the correct spaces with at most $20000$ car moves, print a single line with the integer $-1$. Demo Input: ['4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n', '1 2\n1\n2\n1\n2\n', '1 2\n1\n1\n2\n2\n'] Demo Output: ['6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n', '-1\n', '2\n1 1 1\n2 4 1\n'] Note: In the first sample test case, all cars are in front of their spots except car $5$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $20000$ will be accepted. In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.
```python def f(p, v = -10): global a if v == -10: return a[p[0]][p[1]] else: a[p[0]][p[1]] = v def ins(i, x, y): global mov, cnt mov[cnt][0] = i mov[cnt][1] = x + 1 cnt += 1 mov[cnt][2] = y + 1 def move_in(i): global A, B, tot if f(B[i]) == f(A[i]): f(A[i], 0) ins(f(B[i]), B[i][0], B[i][1]) tot += 1 def move(i): global n, A j = (i + 1) % (n * 2) x = f(A[j]) if x: f(A[i], x) ins(f(A[i]), A[i][0], A[i][1]) f(A[j], 0) move_in(i) mov = [[0 for i in range(3)] for j in range(20010)] n, k = map(int, input().strip().split(' ')) cnt, tot = 0, 0 a = [] for i in range(4): a.append(list(map(int, input().strip().split(' ')))) A, B = [], [] for i in range(n * 2): A.append((1 if i < n else 2, i if i < n else n * 2 - i - 1)) B.append((0 if i < n else 3, A[i][1])) if f(A[i]): move_in(i) o = 0 while o < n * 2 and f(A[o]): o += 1 if o == n * 2: print(-1) else: while tot < k: move(o) o = (o + 1) % (n * 2) print(cnt) print('\n'.join(' '.join(map(str, i)) for i in mov[:cnt])) ```
0
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", "output": "3" }, { "input": "3\n0 53372 -20572", "output": "2" }, { "input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899", "output": "13" }, { "input": "5\n806 0 1308 1954 683", "output": "4" }, { "input": "8\n-26 0 -249 -289 -126 -206 288 -11", "output": "7" }, { "input": "10\n2 2 2 1 2 -1 0 2 -1 1", "output": "3" }, { "input": "1\n8", "output": "1" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "5\n2 0 -1 0 0", "output": "2" }, { "input": "2\n0 0", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n-1 0", "output": "1" }, { "input": "4\n0 0 0 0", "output": "0" }, { "input": "8\n10 9 -1 0 0 3 2 3", "output": "5" }, { "input": "5\n5 0 1 2 3", "output": "4" }, { "input": "3\n1 1 0", "output": "1" }, { "input": "1\n-1", "output": "1" }, { "input": "5\n1 2 0 0 0", "output": "2" }, { "input": "5\n1 0 0 0 0", "output": "1" }, { "input": "5\n4 5 6 0 0", "output": "3" }, { "input": "4\n-1 0 0 1", "output": "2" }, { "input": "5\n3 0 0 4 5", "output": "3" }, { "input": "3\n0 0 2", "output": "1" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "4\n0 0 0 4", "output": "1" }, { "input": "5\n-1 0 0 0 0", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n5", "output": "1" }, { "input": "10\n0 0 0 0 0 1 2 3 0 0", "output": "3" }, { "input": "4\n0 1 2 3", "output": "3" }, { "input": "3\n0 1 2", "output": "2" }, { "input": "4\n2 0 0 -1", "output": "2" } ]
1,641,495,400
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
l = int(input('L : ')) temp = [] for i in range(l): n = int(input('n : ')) if n not in temp and n != 0: temp.append(n) print(len(temp))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. Output Specification: Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. Demo Input: ['5\n1 1 1 1 1\n', '3\n2 0 -1\n', '4\n5 -6 -5 1\n'] Demo Output: ['1\n', '2\n', '4\n'] Note: In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
```python l = int(input('L : ')) temp = [] for i in range(l): n = int(input('n : ')) if n not in temp and n != 0: temp.append(n) print(len(temp)) ```
-1
165
B
Burning Midnight Oil
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ... The expression is regarded as the integral part from dividing number *a* by number *b*. The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished. Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep.
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
[ "7 2\n", "59 9\n" ]
[ "4\n", "54\n" ]
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59.
1,000
[ { "input": "7 2", "output": "4" }, { "input": "59 9", "output": "54" }, { "input": "1 9", "output": "1" }, { "input": "11 2", "output": "7" }, { "input": "747 2", "output": "376" }, { "input": "6578 2", "output": "3293" }, { "input": "37212 2", "output": "18609" }, { "input": "12357 2", "output": "6181" }, { "input": "7998332 2", "output": "3999172" }, { "input": "86275251 2", "output": "43137632" }, { "input": "75584551 2", "output": "37792280" }, { "input": "6 3", "output": "5" }, { "input": "43 4", "output": "33" }, { "input": "811 3", "output": "543" }, { "input": "3410 4", "output": "2560" }, { "input": "21341 4", "output": "16009" }, { "input": "696485 4", "output": "522368" }, { "input": "8856748 3", "output": "5904504" }, { "input": "2959379 4", "output": "2219538" }, { "input": "831410263 3", "output": "554273516" }, { "input": "2 5", "output": "2" }, { "input": "19 6", "output": "17" }, { "input": "715 7", "output": "615" }, { "input": "9122 5", "output": "7300" }, { "input": "89117 6", "output": "74268" }, { "input": "689973 7", "output": "591408" }, { "input": "3024524 5", "output": "2419624" }, { "input": "67127156 6", "output": "55939302" }, { "input": "412262167 7", "output": "353367574" }, { "input": "6 8", "output": "6" }, { "input": "59 9", "output": "54" }, { "input": "246 10", "output": "222" }, { "input": "5314 8", "output": "4651" }, { "input": "15309 9", "output": "13609" }, { "input": "35648 10", "output": "32085" }, { "input": "3018012 8", "output": "2640764" }, { "input": "92153348 9", "output": "81914089" }, { "input": "177583558 10", "output": "159825206" }, { "input": "1000000000 2", "output": "500000008" }, { "input": "1000000000 3", "output": "666666672" }, { "input": "1000000000 4", "output": "750000005" }, { "input": "1000000000 5", "output": "800000003" }, { "input": "1000000000 6", "output": "833333338" }, { "input": "1000000000 7", "output": "857142861" }, { "input": "1000000000 8", "output": "875000004" }, { "input": "1000000000 9", "output": "888888894" }, { "input": "1000000000 10", "output": "900000001" }, { "input": "1 4", "output": "1" }, { "input": "2 10", "output": "2" }, { "input": "1 2", "output": "1" }, { "input": "6 8", "output": "6" }, { "input": "987862820 9", "output": "878100288" }, { "input": "979591791 9", "output": "870748262" }, { "input": "948889213 9", "output": "843457081" }, { "input": "8 9", "output": "8" }, { "input": "999999999 10", "output": "900000000" } ]
1,676,241,837
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
154
0
n, k = map(int, input().split()) curMin = float('inf') v = n r = n//2 def calc(v): count = 0 for i in range(n+1): count += v // k**i if v // k**i == 0: if count >= n: return True else: return False while(r>=0): ans = calc(v) if ans: curMin = min(curMin, v) v-=r else: v+=r if r == 0: break r = r//2 print(curMin)
Title: Burning Midnight Oil Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ... The expression is regarded as the integral part from dividing number *a* by number *b*. The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished. Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep. Input Specification: The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. Output Specification: Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. Demo Input: ['7 2\n', '59 9\n'] Demo Output: ['4\n', '54\n'] Note: In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59.
```python n, k = map(int, input().split()) curMin = float('inf') v = n r = n//2 def calc(v): count = 0 for i in range(n+1): count += v // k**i if v // k**i == 0: if count >= n: return True else: return False while(r>=0): ans = calc(v) if ans: curMin = min(curMin, v) v-=r else: v+=r if r == 0: break r = r//2 print(curMin) ```
0
747
A
Display Size
PROGRAMMING
800
[ "brute force", "math" ]
null
null
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Print two integers — the number of rows and columns on the display.
[ "8\n", "64\n", "5\n", "999999\n" ]
[ "2 4\n", "8 8\n", "1 5\n", "999 1001\n" ]
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
500
[ { "input": "8", "output": "2 4" }, { "input": "64", "output": "8 8" }, { "input": "5", "output": "1 5" }, { "input": "999999", "output": "999 1001" }, { "input": "716539", "output": "97 7387" }, { "input": "1", "output": "1 1" }, { "input": "2", "output": "1 2" }, { "input": "3", "output": "1 3" }, { "input": "4", "output": "2 2" }, { "input": "6", "output": "2 3" }, { "input": "7", "output": "1 7" }, { "input": "9", "output": "3 3" }, { "input": "10", "output": "2 5" }, { "input": "11", "output": "1 11" }, { "input": "12", "output": "3 4" }, { "input": "15", "output": "3 5" }, { "input": "100", "output": "10 10" }, { "input": "101", "output": "1 101" }, { "input": "169", "output": "13 13" }, { "input": "179", "output": "1 179" }, { "input": "190", "output": "10 19" }, { "input": "1000", "output": "25 40" }, { "input": "10000", "output": "100 100" }, { "input": "10001", "output": "73 137" }, { "input": "100000", "output": "250 400" }, { "input": "100001", "output": "11 9091" }, { "input": "1000000", "output": "1000 1000" }, { "input": "999983", "output": "1 999983" }, { "input": "524288", "output": "512 1024" }, { "input": "954493", "output": "971 983" }, { "input": "966289", "output": "983 983" }, { "input": "944663", "output": "961 983" }, { "input": "912673", "output": "97 9409" }, { "input": "732641", "output": "679 1079" }, { "input": "232897", "output": "343 679" }, { "input": "16807", "output": "49 343" }, { "input": "999958", "output": "2 499979" }, { "input": "990151", "output": "1 990151" }, { "input": "997002", "output": "998 999" }, { "input": "20", "output": "4 5" }, { "input": "20261", "output": "1 20261" }, { "input": "999123", "output": "3 333041" }, { "input": "901841", "output": "1 901841" } ]
1,562,523,917
2,147,483,647
Python 3
OK
TESTS
43
124
0
n = int(input()) a = 1 ans = 10**18 while a*a <= n: if n%a == 0: b = n//a if b-a < ans: ans = b-a ans_a = a a+=1 print(ans_a, n//ans_a)
Title: Display Size Time Limit: None seconds Memory Limit: None megabytes Problem Description: A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. Input Specification: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. Output Specification: Print two integers — the number of rows and columns on the display. Demo Input: ['8\n', '64\n', '5\n', '999999\n'] Demo Output: ['2 4\n', '8 8\n', '1 5\n', '999 1001\n'] Note: In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
```python n = int(input()) a = 1 ans = 10**18 while a*a <= n: if n%a == 0: b = n//a if b-a < ans: ans = b-a ans_a = a a+=1 print(ans_a, n//ans_a) ```
3
218
A
Mountain Scenery
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting the point (*i*,<=*y**i*) and the point (*i*<=+<=1,<=*y**i*<=+<=1). For any even *i* (2<=≤<=*i*<=≤<=2*n*) the following condition holds: *y**i*<=-<=1<=&lt;<=*y**i* and *y**i*<=&gt;<=*y**i*<=+<=1. We shall call a vertex of a polyline with an even *x* coordinate a mountain peak. Bolek fancied a little mischief. He chose exactly *k* mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the *y* coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1,<=*r*1), (2,<=*r*2), ..., (2*n*<=+<=1,<=*r*2*n*<=+<=1). Given Bolek's final picture, restore the initial one.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
[ "3 2\n0 5 3 5 1 5 2\n", "1 1\n0 2 0\n" ]
[ "0 5 3 4 1 4 2 \n", "0 1 0 \n" ]
none
500
[ { "input": "3 2\n0 5 3 5 1 5 2", "output": "0 5 3 4 1 4 2 " }, { "input": "1 1\n0 2 0", "output": "0 1 0 " }, { "input": "1 1\n1 100 0", "output": "1 99 0 " }, { "input": "3 1\n0 1 0 1 0 2 0", "output": "0 1 0 1 0 1 0 " }, { "input": "3 1\n0 1 0 2 0 1 0", "output": "0 1 0 1 0 1 0 " }, { "input": "3 3\n0 100 35 67 40 60 3", "output": "0 99 35 66 40 59 3 " }, { "input": "7 3\n1 2 1 3 1 2 1 2 1 3 1 3 1 2 1", "output": "1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 " }, { "input": "100 100\n1 3 1 3 1 3 0 2 0 3 1 3 1 3 1 3 0 3 1 3 0 2 0 2 0 3 0 2 0 2 0 3 1 3 1 3 1 3 1 3 0 2 0 3 1 3 0 2 0 2 0 2 0 2 0 2 0 3 0 3 0 3 0 3 0 2 0 3 1 3 1 3 1 3 0 3 0 2 0 2 0 2 0 2 0 3 0 3 1 3 0 3 1 3 1 3 0 3 1 3 0 3 1 3 1 3 0 3 1 3 0 3 1 3 0 2 0 3 1 3 0 3 1 3 0 2 0 3 1 3 0 3 0 2 0 3 1 3 0 3 0 3 0 2 0 2 0 2 0 3 0 3 1 3 1 3 0 3 1 3 1 3 1 3 0 2 0 3 0 2 0 3 1 3 0 3 0 3 1 3 0 2 0 3 0 2 0 2 0 2 0 2 0 3 1 3 0 3 1 3 1", "output": "1 2 1 2 1 2 0 1 0 2 1 2 1 2 1 2 0 2 1 2 0 1 0 1 0 2 0 1 0 1 0 2 1 2 1 2 1 2 1 2 0 1 0 2 1 2 0 1 0 1 0 1 0 1 0 1 0 2 0 2 0 2 0 2 0 1 0 2 1 2 1 2 1 2 0 2 0 1 0 1 0 1 0 1 0 2 0 2 1 2 0 2 1 2 1 2 0 2 1 2 0 2 1 2 1 2 0 2 1 2 0 2 1 2 0 1 0 2 1 2 0 2 1 2 0 1 0 2 1 2 0 2 0 1 0 2 1 2 0 2 0 2 0 1 0 1 0 1 0 2 0 2 1 2 1 2 0 2 1 2 1 2 1 2 0 1 0 2 0 1 0 2 1 2 0 2 0 2 1 2 0 1 0 2 0 1 0 1 0 1 0 1 0 2 1 2 0 2 1 2 1 " }, { "input": "30 20\n1 3 1 3 0 2 0 4 1 3 0 3 1 3 1 4 2 3 1 2 0 4 2 4 0 4 1 3 0 4 1 4 2 4 2 4 0 3 1 2 1 4 0 3 0 4 1 3 1 4 1 3 0 1 0 4 0 3 2 3 1", "output": "1 3 1 3 0 2 0 4 1 2 0 2 1 2 1 3 2 3 1 2 0 3 2 3 0 3 1 2 0 3 1 3 2 3 2 3 0 2 1 2 1 3 0 2 0 3 1 2 1 3 1 2 0 1 0 3 0 3 2 3 1 " }, { "input": "10 6\n0 5 2 4 1 5 2 5 2 4 2 5 3 5 0 2 0 1 0 1 0", "output": "0 5 2 4 1 4 2 4 2 3 2 4 3 4 0 1 0 1 0 1 0 " }, { "input": "11 6\n3 5 1 4 3 5 0 2 0 2 0 4 0 3 0 4 1 5 2 4 0 4 0", "output": "3 5 1 4 3 5 0 2 0 2 0 3 0 2 0 3 1 4 2 3 0 3 0 " }, { "input": "12 6\n1 2 1 5 0 2 0 4 1 3 1 4 2 4 0 4 0 4 2 4 0 4 0 5 3", "output": "1 2 1 5 0 2 0 4 1 3 1 4 2 3 0 3 0 3 2 3 0 3 0 4 3 " }, { "input": "13 6\n3 5 2 5 0 3 0 1 0 2 0 1 0 1 0 2 1 4 3 5 1 3 1 3 2 3 1", "output": "3 4 2 4 0 2 0 1 0 1 0 1 0 1 0 2 1 4 3 4 1 2 1 3 2 3 1 " }, { "input": "24 7\n3 4 2 4 1 4 3 4 3 5 1 3 1 3 0 3 0 3 1 4 0 3 0 1 0 1 0 3 2 3 2 3 1 2 1 3 2 5 1 3 0 1 0 2 0 3 1 3 1", "output": "3 4 2 4 1 4 3 4 3 5 1 3 1 3 0 3 0 3 1 3 0 2 0 1 0 1 0 3 2 3 2 3 1 2 1 3 2 4 1 2 0 1 0 1 0 2 1 2 1 " }, { "input": "25 8\n3 5 2 4 2 4 0 1 0 1 0 1 0 2 1 5 2 4 2 4 2 3 1 2 0 1 0 2 0 3 2 5 3 5 0 4 2 3 2 4 1 4 0 4 1 4 0 1 0 4 2", "output": "3 5 2 4 2 4 0 1 0 1 0 1 0 2 1 5 2 4 2 4 2 3 1 2 0 1 0 2 0 3 2 4 3 4 0 3 2 3 2 3 1 3 0 3 1 3 0 1 0 3 2 " }, { "input": "26 9\n3 4 2 3 1 3 1 3 2 4 0 1 0 2 1 3 1 3 0 5 1 4 3 5 0 5 2 3 0 3 1 4 1 3 1 4 2 3 1 4 3 4 1 3 2 4 1 3 2 5 1 2 0", "output": "3 4 2 3 1 3 1 3 2 4 0 1 0 2 1 3 1 3 0 4 1 4 3 4 0 4 2 3 0 2 1 3 1 2 1 3 2 3 1 4 3 4 1 3 2 3 1 3 2 4 1 2 0 " }, { "input": "27 10\n3 5 3 5 3 4 1 3 1 3 1 3 2 3 2 3 2 4 2 3 0 4 2 5 3 4 3 4 1 5 3 4 1 2 1 5 0 3 0 5 0 5 3 4 0 1 0 2 0 2 1 4 0 2 1", "output": "3 5 3 5 3 4 1 3 1 3 1 3 2 3 2 3 2 3 2 3 0 3 2 4 3 4 3 4 1 4 3 4 1 2 1 4 0 2 0 4 0 4 3 4 0 1 0 1 0 2 1 3 0 2 1 " }, { "input": "40 1\n0 2 1 2 0 2 1 2 1 2 1 2 1 2 1 3 0 1 0 1 0 1 0 2 0 2 1 2 0 2 1 2 1 2 1 2 1 2 0 2 1 2 1 2 0 1 0 2 0 2 0 1 0 1 0 1 0 1 0 1 0 2 0 2 0 2 0 1 0 2 0 1 0 2 0 1 0 2 1 2 0", "output": "0 2 1 2 0 2 1 2 1 2 1 2 1 2 1 3 0 1 0 1 0 1 0 2 0 2 1 2 0 2 1 2 1 2 1 2 1 2 0 2 1 2 1 2 0 1 0 2 0 2 0 1 0 1 0 1 0 1 0 1 0 2 0 2 0 2 0 1 0 2 0 1 0 1 0 1 0 2 1 2 0 " }, { "input": "40 2\n0 3 1 2 1 2 0 1 0 2 1 3 0 2 0 3 0 3 0 1 0 2 0 3 1 2 0 2 1 2 0 2 0 1 0 1 0 2 0 2 1 3 0 2 0 1 0 1 0 1 0 3 1 3 1 2 1 2 0 3 0 1 0 3 0 2 1 2 0 1 0 2 0 3 1 2 1 3 1 3 0", "output": "0 3 1 2 1 2 0 1 0 2 1 3 0 2 0 3 0 3 0 1 0 2 0 3 1 2 0 2 1 2 0 2 0 1 0 1 0 2 0 2 1 3 0 2 0 1 0 1 0 1 0 3 1 3 1 2 1 2 0 3 0 1 0 3 0 2 1 2 0 1 0 2 0 3 1 2 1 2 1 2 0 " }, { "input": "40 3\n1 3 1 2 0 4 1 2 0 1 0 1 0 3 0 3 2 3 0 3 1 3 0 4 1 3 2 3 0 2 1 3 0 2 0 1 0 3 1 3 2 3 2 3 0 1 0 2 0 1 0 1 0 3 1 3 0 3 1 3 1 2 0 1 0 3 0 2 0 3 0 1 0 2 0 3 1 2 0 3 0", "output": "1 3 1 2 0 4 1 2 0 1 0 1 0 3 0 3 2 3 0 3 1 3 0 4 1 3 2 3 0 2 1 3 0 2 0 1 0 3 1 3 2 3 2 3 0 1 0 2 0 1 0 1 0 3 1 3 0 3 1 3 1 2 0 1 0 3 0 2 0 3 0 1 0 1 0 2 1 2 0 2 0 " }, { "input": "50 40\n1 4 2 4 1 2 1 4 1 4 2 3 1 2 1 4 1 3 0 2 1 4 0 1 0 3 1 3 1 3 0 4 2 4 2 4 2 4 2 4 2 4 2 4 0 4 1 3 1 3 0 4 1 4 2 3 2 3 0 3 0 3 0 4 1 4 1 3 1 4 1 3 0 4 0 3 0 2 0 2 0 4 1 4 0 2 0 4 1 4 0 3 0 2 1 3 0 2 0 4 0", "output": "1 4 2 4 1 2 1 3 1 3 2 3 1 2 1 3 1 2 0 2 1 3 0 1 0 2 1 2 1 2 0 3 2 3 2 3 2 3 2 3 2 3 2 3 0 3 1 2 1 2 0 3 1 3 2 3 2 3 0 2 0 2 0 3 1 3 1 2 1 3 1 2 0 3 0 2 0 1 0 1 0 3 1 3 0 1 0 3 1 3 0 2 0 2 1 2 0 1 0 3 0 " }, { "input": "100 2\n1 3 1 2 1 3 2 3 1 3 1 3 1 3 1 2 0 3 0 2 0 3 2 3 0 3 1 2 1 2 0 3 0 1 0 1 0 3 2 3 1 2 0 1 0 2 0 1 0 2 1 3 1 2 1 3 2 3 1 3 1 2 0 3 2 3 0 2 1 3 1 2 0 3 2 3 1 3 2 3 0 4 0 3 0 1 0 3 0 1 0 1 0 2 0 2 1 3 1 2 1 2 0 2 0 1 0 2 0 2 1 3 1 3 2 3 0 2 1 2 0 3 0 1 0 2 0 3 2 3 1 3 0 3 1 2 0 1 0 3 0 1 0 1 0 1 0 2 0 1 0 2 1 2 1 2 1 3 0 1 0 2 1 3 0 2 1 3 0 2 1 2 0 3 1 3 1 3 0 2 1 2 1 3 0 2 1 3 2 3 1 2 0 3 1 2 0 3 1 2 0", "output": "1 3 1 2 1 3 2 3 1 3 1 3 1 3 1 2 0 3 0 2 0 3 2 3 0 3 1 2 1 2 0 3 0 1 0 1 0 3 2 3 1 2 0 1 0 2 0 1 0 2 1 3 1 2 1 3 2 3 1 3 1 2 0 3 2 3 0 2 1 3 1 2 0 3 2 3 1 3 2 3 0 4 0 3 0 1 0 3 0 1 0 1 0 2 0 2 1 3 1 2 1 2 0 2 0 1 0 2 0 2 1 3 1 3 2 3 0 2 1 2 0 3 0 1 0 2 0 3 2 3 1 3 0 3 1 2 0 1 0 3 0 1 0 1 0 1 0 2 0 1 0 2 1 2 1 2 1 3 0 1 0 2 1 3 0 2 1 3 0 2 1 2 0 3 1 3 1 3 0 2 1 2 1 3 0 2 1 3 2 3 1 2 0 2 1 2 0 2 1 2 0 " }, { "input": "100 3\n0 2 1 2 0 1 0 1 0 3 0 2 1 3 1 3 2 3 0 2 0 1 0 2 0 1 0 3 2 3 2 3 1 2 1 3 1 2 1 3 2 3 2 3 0 3 2 3 2 3 2 3 0 2 0 3 0 3 2 3 2 3 2 3 2 3 0 3 0 1 0 2 1 3 0 2 1 2 0 3 2 3 2 3 1 3 0 3 1 3 0 3 0 1 0 1 0 2 0 2 1 2 0 3 1 3 0 3 2 3 2 3 2 3 2 3 0 1 0 1 0 1 0 2 1 2 0 2 1 3 2 3 0 1 0 1 0 1 0 1 0 2 0 1 0 3 1 2 1 2 1 3 1 2 0 3 0 2 1 2 1 3 2 3 1 3 2 3 0 1 0 1 0 1 0 1 0 3 0 1 0 2 1 2 0 3 1 3 2 3 0 3 1 2 1 3 1 3 1 3 0", "output": "0 2 1 2 0 1 0 1 0 3 0 2 1 3 1 3 2 3 0 2 0 1 0 2 0 1 0 3 2 3 2 3 1 2 1 3 1 2 1 3 2 3 2 3 0 3 2 3 2 3 2 3 0 2 0 3 0 3 2 3 2 3 2 3 2 3 0 3 0 1 0 2 1 3 0 2 1 2 0 3 2 3 2 3 1 3 0 3 1 3 0 3 0 1 0 1 0 2 0 2 1 2 0 3 1 3 0 3 2 3 2 3 2 3 2 3 0 1 0 1 0 1 0 2 1 2 0 2 1 3 2 3 0 1 0 1 0 1 0 1 0 2 0 1 0 3 1 2 1 2 1 3 1 2 0 3 0 2 1 2 1 3 2 3 1 3 2 3 0 1 0 1 0 1 0 1 0 3 0 1 0 2 1 2 0 3 1 3 2 3 0 3 1 2 1 2 1 2 1 2 0 " }, { "input": "100 20\n0 1 0 3 0 3 2 3 2 4 0 2 0 3 1 3 0 2 0 2 0 3 0 1 0 3 2 4 0 1 0 2 0 2 1 2 1 4 2 4 1 2 0 1 0 2 1 3 0 2 1 3 2 3 1 2 0 2 1 4 0 3 0 2 0 1 0 1 0 1 0 2 1 3 2 3 2 3 2 3 0 1 0 1 0 4 2 3 2 3 0 3 1 2 0 2 0 2 1 3 2 3 1 4 0 1 0 2 1 2 0 2 0 3 2 3 0 2 0 2 1 4 2 3 1 3 0 3 0 2 0 2 1 2 1 3 0 3 1 2 1 3 1 3 1 2 1 2 0 2 1 3 0 2 0 3 0 1 0 3 0 3 0 1 0 4 1 3 0 1 0 1 0 2 1 2 0 2 1 4 1 3 0 2 1 3 1 3 1 3 0 3 0 2 0 1 0 2 1 2 1", "output": "0 1 0 3 0 3 2 3 2 4 0 2 0 3 1 3 0 2 0 2 0 3 0 1 0 3 2 4 0 1 0 2 0 2 1 2 1 4 2 4 1 2 0 1 0 2 1 3 0 2 1 3 2 3 1 2 0 2 1 4 0 3 0 2 0 1 0 1 0 1 0 2 1 3 2 3 2 3 2 3 0 1 0 1 0 4 2 3 2 3 0 3 1 2 0 2 0 2 1 3 2 3 1 4 0 1 0 2 1 2 0 2 0 3 2 3 0 2 0 2 1 4 2 3 1 3 0 2 0 1 0 2 1 2 1 2 0 2 1 2 1 2 1 2 1 2 1 2 0 2 1 2 0 1 0 2 0 1 0 2 0 2 0 1 0 3 1 2 0 1 0 1 0 2 1 2 0 2 1 3 1 2 0 2 1 2 1 2 1 2 0 2 0 1 0 1 0 2 1 2 1 " }, { "input": "100 20\n2 3 0 4 0 1 0 6 3 4 3 6 4 6 0 9 0 6 2 7 3 8 7 10 2 9 3 9 5 6 5 10 3 7 1 5 2 8 3 7 2 3 1 6 0 8 3 8 0 4 1 8 3 7 1 9 5 9 5 8 7 8 5 6 5 8 1 9 8 9 8 10 7 10 5 8 6 10 2 6 3 9 2 6 3 10 5 9 3 10 1 3 2 11 8 9 8 10 1 8 7 11 0 9 5 8 4 5 0 7 3 7 5 9 5 10 1 7 1 9 1 6 3 8 2 4 1 4 2 6 0 4 2 4 2 7 6 9 0 1 0 4 0 4 0 9 2 7 6 7 2 8 0 8 2 7 5 10 1 2 0 2 0 4 3 5 4 7 0 10 2 10 3 6 3 7 1 4 0 9 1 4 3 8 1 10 1 10 0 3 2 5 3 9 0 7 4 5 0 1 0", "output": "2 3 0 4 0 1 0 6 3 4 3 6 4 6 0 9 0 6 2 7 3 8 7 10 2 9 3 9 5 6 5 10 3 7 1 5 2 8 3 7 2 3 1 6 0 8 3 8 0 4 1 8 3 7 1 9 5 9 5 8 7 8 5 6 5 8 1 9 8 9 8 10 7 10 5 8 6 10 2 6 3 9 2 6 3 10 5 9 3 10 1 3 2 11 8 9 8 10 1 8 7 11 0 9 5 8 4 5 0 7 3 7 5 9 5 10 1 7 1 9 1 6 3 8 2 4 1 4 2 6 0 4 2 4 2 7 6 9 0 1 0 4 0 3 0 8 2 7 6 7 2 7 0 7 2 6 5 9 1 2 0 1 0 4 3 5 4 6 0 9 2 9 3 5 3 6 1 3 0 8 1 4 3 7 1 9 1 9 0 3 2 4 3 8 0 6 4 5 0 1 0 " }, { "input": "98 3\n1 2 1 2 0 2 0 2 1 2 0 1 0 2 1 2 0 2 1 2 1 2 0 1 0 2 1 2 1 2 0 2 1 2 0 2 0 2 0 1 0 1 0 1 0 2 1 3 1 2 1 2 1 2 1 2 1 2 1 2 0 2 0 2 1 2 1 2 0 2 1 2 0 1 0 1 0 1 0 1 0 2 0 1 0 2 0 2 1 2 1 2 1 2 0 1 0 1 0 1 0 2 1 2 0 2 1 2 0 2 0 1 0 2 1 2 0 1 0 2 1 2 1 2 1 2 0 2 1 2 1 2 1 2 0 2 1 2 1 2 0 1 0 2 0 2 0 1 0 2 0 2 0 1 0 1 0 1 0 2 0 2 1 2 0 1 0 2 0 2 0 1 0 2 1 2 1 2 1 2 0 2 1 2 1 2 1 2 0 1 0 1 0 2 0 2 0", "output": "1 2 1 2 0 2 0 2 1 2 0 1 0 2 1 2 0 2 1 2 1 2 0 1 0 2 1 2 1 2 0 2 1 2 0 2 0 2 0 1 0 1 0 1 0 2 1 3 1 2 1 2 1 2 1 2 1 2 1 2 0 2 0 2 1 2 1 2 0 2 1 2 0 1 0 1 0 1 0 1 0 2 0 1 0 2 0 2 1 2 1 2 1 2 0 1 0 1 0 1 0 2 1 2 0 2 1 2 0 2 0 1 0 2 1 2 0 1 0 2 1 2 1 2 1 2 0 2 1 2 1 2 1 2 0 2 1 2 1 2 0 1 0 2 0 2 0 1 0 2 0 2 0 1 0 1 0 1 0 2 0 2 1 2 0 1 0 2 0 1 0 1 0 2 1 2 1 2 1 2 0 2 1 2 1 2 1 2 0 1 0 1 0 1 0 1 0 " }, { "input": "2 1\n0 2 1 4 1", "output": "0 2 1 3 1 " }, { "input": "2 1\n0 2 1 5 1", "output": "0 2 1 4 1 " }, { "input": "3 3\n1 12 9 11 6 8 1", "output": "1 11 9 10 6 7 1 " }, { "input": "3 2\n0 7 4 7 1 3 2", "output": "0 6 4 6 1 3 2 " }, { "input": "2 1\n1 3 2 4 1", "output": "1 3 2 3 1 " }, { "input": "4 1\n5 6 5 6 5 6 1 3 1", "output": "5 6 5 6 5 6 1 2 1 " }, { "input": "2 1\n0 2 1 3 0", "output": "0 2 1 2 0 " }, { "input": "2 2\n98 100 1 7 2", "output": "98 99 1 6 2 " }, { "input": "3 1\n8 10 9 10 3 5 1", "output": "8 10 9 10 3 4 1 " }, { "input": "3 2\n0 4 3 5 2 5 2", "output": "0 4 3 4 2 4 2 " }, { "input": "2 1\n4 5 2 4 2", "output": "4 5 2 3 2 " }, { "input": "3 1\n0 2 1 2 0 2 0", "output": "0 2 1 2 0 1 0 " }, { "input": "1 1\n5 7 2", "output": "5 6 2 " }, { "input": "2 1\n3 4 1 3 1", "output": "3 4 1 2 1 " }, { "input": "3 1\n0 4 3 5 0 5 0", "output": "0 4 3 5 0 4 0 " }, { "input": "3 1\n1 3 2 3 1 3 1", "output": "1 3 2 3 1 2 1 " }, { "input": "2 1\n0 8 7 100 0", "output": "0 8 7 99 0 " }, { "input": "2 1\n1 3 2 5 1", "output": "1 3 2 4 1 " } ]
1,656,334,880
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
2
154
31,744,000
x=input() x=x.split(" ") z=input() z=z.split(" ") b=1 for i in range(int(x[1])): z[b]=chr(ord(z[b])-1) b+=2 for k in z: print(k,end=" ")
Title: Mountain Scenery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting the point (*i*,<=*y**i*) and the point (*i*<=+<=1,<=*y**i*<=+<=1). For any even *i* (2<=≤<=*i*<=≤<=2*n*) the following condition holds: *y**i*<=-<=1<=&lt;<=*y**i* and *y**i*<=&gt;<=*y**i*<=+<=1. We shall call a vertex of a polyline with an even *x* coordinate a mountain peak. Bolek fancied a little mischief. He chose exactly *k* mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the *y* coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1,<=*r*1), (2,<=*r*2), ..., (2*n*<=+<=1,<=*r*2*n*<=+<=1). Given Bolek's final picture, restore the initial one. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Specification: Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Demo Input: ['3 2\n0 5 3 5 1 5 2\n', '1 1\n0 2 0\n'] Demo Output: ['0 5 3 4 1 4 2 \n', '0 1 0 \n'] Note: none
```python x=input() x=x.split(" ") z=input() z=z.split(" ") b=1 for i in range(int(x[1])): z[b]=chr(ord(z[b])-1) b+=2 for k in z: print(k,end=" ") ```
-1
0
none
none
none
0
[ "none" ]
null
null
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second.
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
[ "3\n7 1 3\n1 2 1\n", "4\n5 10 3 2\n2 3 2 4\n" ]
[ "2.000000000000\n", "1.400000000000\n" ]
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
0
[ { "input": "3\n7 1 3\n1 2 1", "output": "2.000000000000" }, { "input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000" }, { "input": "3\n1 1000000000 2\n1 2 1000000000", "output": "333333332.999999999971" }, { "input": "2\n4 5\n10 8", "output": "0.055555555556" }, { "input": "4\n14 12 10 17\n8 6 5 10", "output": "0.466666666667" }, { "input": "5\n1 15 61 29 43\n15 11 19 19 19", "output": "1.764705882353" }, { "input": "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13", "output": "1.750000000000" }, { "input": "2\n1000000000 1000000000\n1 1", "output": "0.000000000000" }, { "input": "3\n1 1 1\n1 1 1", "output": "0.000000000000" } ]
1,643,830,088
2,147,483,647
Python 3
OK
TESTS
46
2,121
6,553,600
# cook your dish heret n=int(input()) x=[int(x) for x in input().split()] v=[int(v) for v in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t) for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t) for i in range(n)]) def is_feasible(k): return leftmost_right_ep(k)>=rightmost_left_ep(k) L,R=0.0,1e9 while abs(R-L)>1e-6: mid=(R+L)/2 if(is_feasible(mid)):R=mid else: L=mid print(mid)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second. Output Specification: Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. Demo Input: ['3\n7 1 3\n1 2 1\n', '4\n5 10 3 2\n2 3 2 4\n'] Demo Output: ['2.000000000000\n', '1.400000000000\n'] Note: In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
```python # cook your dish heret n=int(input()) x=[int(x) for x in input().split()] v=[int(v) for v in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t) for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t) for i in range(n)]) def is_feasible(k): return leftmost_right_ep(k)>=rightmost_left_ep(k) L,R=0.0,1e9 while abs(R-L)>1e-6: mid=(R+L)/2 if(is_feasible(mid)):R=mid else: L=mid print(mid) ```
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "10 240", "output": "0" }, { "input": "9 240", "output": "0" }, { "input": "9 1", "output": "9" }, { "input": "9 235", "output": "1" }, { "input": "9 236", "output": "0" }, { "input": "5 225", "output": "2" }, { "input": "5 226", "output": "1" }, { "input": "4 210", "output": "3" }, { "input": "4 211", "output": "2" }, { "input": "4 191", "output": "3" }, { "input": "10 165", "output": "5" }, { "input": "10 166", "output": "4" }, { "input": "8 100", "output": "7" }, { "input": "8 101", "output": "6" }, { "input": "8 60", "output": "8" }, { "input": "8 61", "output": "7" }, { "input": "10 15", "output": "9" }, { "input": "10 16", "output": "8" }, { "input": "4 100", "output": "4" }, { "input": "4 101", "output": "4" }, { "input": "7 167", "output": "4" }, { "input": "10 164", "output": "5" }, { "input": "9 170", "output": "4" }, { "input": "8 160", "output": "5" }, { "input": "1 100", "output": "1" }, { "input": "8 123", "output": "6" }, { "input": "2 99", "output": "2" }, { "input": "10 88", "output": "7" }, { "input": "1 235", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "4 240", "output": "0" }, { "input": "1 55", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "3 240", "output": "0" }, { "input": "10 240", "output": "0" }, { "input": "2 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "9 1", "output": "9" }, { "input": "2 236", "output": "0" }, { "input": "10 2", "output": "9" }, { "input": "3 239", "output": "0" }, { "input": "1 237", "output": "0" }, { "input": "7 8", "output": "7" }, { "input": "10 235", "output": "1" } ]
1,675,178,120
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
n,m=map(int,input().split()) minu=0 sot=0 o=0 t=0 for i in range(1,n+1): t=t+i*5 if m+t<=240: print(n) elif m+t>240: o=m+t-(i*5) print(n-1)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? Input Specification: The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. Output Specification: Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. Demo Input: ['3 222\n', '4 190\n', '7 1\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
```python n,m=map(int,input().split()) minu=0 sot=0 o=0 t=0 for i in range(1,n+1): t=t+i*5 if m+t<=240: print(n) elif m+t>240: o=m+t-(i*5) print(n-1) ```
0
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n10", "output": "2" }, { "input": "2\n11", "output": "2" }, { "input": "10\n0000000000", "output": "1" }, { "input": "20\n11111111110110001100", "output": "11" }, { "input": "50\n01011110100010000001010000100001001101001101101011", "output": "1" }, { "input": "60\n111111111101111111111111111111111111111111111111111111111111", "output": "11" }, { "input": "60\n111111111111111111111111111111111111111111111111111111111111", "output": "60" }, { "input": "66\n111111010010011001110011000111000100011110011001111110011111111101", "output": "7" }, { "input": "90\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "91\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "2" }, { "input": "92\n11111111101011111011111111111111111111111011101111111111011111111111111101111111101011111101", "output": "10" }, { "input": "100\n0001011110100011001100100010111001000001111101101001001001001011110100101101010000000110100101110010", "output": "1" }, { "input": "100\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1011001110001000011111110011000100001110010110111101110110011011011000010100110001111100000010110010", "output": "2" }, { "input": "100\n1101111011001111111111110011110111101110111111111111111111111111111111011111111111110111111111111111", "output": "3" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101", "output": "99" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000", "output": "96" }, { "input": "100\n1111111111111111111111111111111110011000110110001010101100100100001000010010010010000100110000010101", "output": "34" } ]
1,569,919,711
2,147,483,647
Python 3
OK
TESTS
29
155
819,200
import re cv=0 s2='' n=int(input()) s1=input() for x in range(n): if int(s1[x])==1: s2=s2+'0' else: s2=s2+'1' s2=s2+s1[x+1:n] break; for x in range(n): if re.match(s1[x],s2[x]): cv=cv+1 print(n-cv)
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. Output Specification: Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. Demo Input: ['4\n1100\n', '4\n1111\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample the cell ends up with value 0010, in the second sample — with 0000.
```python import re cv=0 s2='' n=int(input()) s1=input() for x in range(n): if int(s1[x])==1: s2=s2+'0' else: s2=s2+'1' s2=s2+s1[x+1:n] break; for x in range(n): if re.match(s1[x],s2[x]): cv=cv+1 print(n-cv) ```
3
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,527,173,573
2,147,483,647
Python 3
OK
TESTS
37
186
0
# python 3 """ Note that after applying the operations of the exchange, we can get any permutation of the elements of the array. It is not difficult to understand that the answer would be "YES" if there were at least another different number between the same-valued number, and this means that at most the same-valued number would appear (n+1)/2 times. Thus, if the most seen number appear C times, it must fulfill the condition C <= (n+1) / 2. """ def yaroslav_and_permutations(n_int: int, numbers_list: list) -> str: times = dict() for each in numbers_list: if times.get(each, -1) == -1: times[each] = 1 else: times[each] += 1 max_seen = 0 for (number, seen_time) in times.items(): if seen_time > max_seen: max_seen = seen_time if max_seen <= (n_int + 1) // 2: return "YES" else: return "NO" if __name__ == "__main__": """ Inside of this is the test. Outside is the API """ n = int(input()) numbers = list(map(int, input().split())) print(yaroslav_and_permutations(n, numbers))
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 # python 3 """ Note that after applying the operations of the exchange, we can get any permutation of the elements of the array. It is not difficult to understand that the answer would be "YES" if there were at least another different number between the same-valued number, and this means that at most the same-valued number would appear (n+1)/2 times. Thus, if the most seen number appear C times, it must fulfill the condition C <= (n+1) / 2. """ def yaroslav_and_permutations(n_int: int, numbers_list: list) -> str: times = dict() for each in numbers_list: if times.get(each, -1) == -1: times[each] = 1 else: times[each] += 1 max_seen = 0 for (number, seen_time) in times.items(): if seen_time > max_seen: max_seen = seen_time if max_seen <= (n_int + 1) // 2: return "YES" else: return "NO" if __name__ == "__main__": """ Inside of this is the test. Outside is the API """ n = int(input()) numbers = list(map(int, input().split())) print(yaroslav_and_permutations(n, numbers)) ```
3
593
A
2Char
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters. Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Print a single integer — the maximum possible total length of words in Andrew's article.
[ "4\nabb\ncacc\naaa\nbbb\n", "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n" ]
[ "9", "6" ]
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}. In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
250
[ { "input": "4\nabb\ncacc\naaa\nbbb", "output": "9" }, { "input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa", "output": "6" }, { "input": "1\na", "output": "1" }, { "input": "2\nz\nz", "output": "2" }, { "input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy", "output": "0" }, { "input": "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg", "output": "36" }, { "input": "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab", "output": "36" }, { "input": "1\nabc", "output": "0" }, { "input": "2\nabc\nbca", "output": "0" }, { "input": "3\nab\nba\nzzz", "output": "4" }, { "input": "3\nab\nba\nzzzzz", "output": "5" }, { "input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "37" }, { "input": "26\nq\nw\ne\nr\nt\ny\nu\ni\no\np\na\ns\nd\nf\ng\nh\nj\nk\nl\nz\nx\nc\nv\nb\nn\nm", "output": "2" }, { "input": "5\nzzz\nzzzz\nzz\nz\naaaaaaaaaaaaaaaaaaaaaaaaaaaf", "output": "28" }, { "input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba", "output": "0" }, { "input": "31\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml\nfml", "output": "0" }, { "input": "5\nzloyfreid\ngraciocode\nschooldiary\nkazakov\nevgesha", "output": "0" }, { "input": "4\nurkop\nvisualac\ngnutl\nwtf", "output": "0" }, { "input": "3\naa\nb\nccc", "output": "5" }, { "input": "3\na\nbd\ncaaaaaaa", "output": "9" }, { "input": "4\naa\nax\nay\nxxxx", "output": "8" }, { "input": "5\nc\nbb\ne\ndd\nf", "output": "4" }, { "input": "2\naaaaa\naaaaa", "output": "10" } ]
1,446,657,893
2,393
Python 3
WRONG_ANSWER
PRETESTS
11
62
307,200
n = int(input()) s = [] one = dict() two = dict() for i in range(n): f = input() q = set() for j in f: if j not in q: q.add(j) if len(q) > 2: break else: if len(q) == 1: if ''.join(sorted(list(q))) in one: one[''.join(sorted(list(q)))] += len(f) else: one[''.join(sorted(list(q)))] = len(f) else: if ''.join(sorted(list(q))) in two: two[''.join(sorted(list(q)))] += len(f) else: two[''.join(sorted(list(q)))] = len(f) ans = 0 for i in two: if i[0] in one: two[i] += one[i[0]] if i[1] in one: two[i] += one[i[1]] if ans < two[i]: ans = two[i] for i in one: if one[i] > ans: ans = one[i] print(ans)
Title: 2Char Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters. Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length. Input Specification: The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input. Output Specification: Print a single integer — the maximum possible total length of words in Andrew's article. Demo Input: ['4\nabb\ncacc\naaa\nbbb\n', '5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n'] Demo Output: ['9', '6'] Note: In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}. In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
```python n = int(input()) s = [] one = dict() two = dict() for i in range(n): f = input() q = set() for j in f: if j not in q: q.add(j) if len(q) > 2: break else: if len(q) == 1: if ''.join(sorted(list(q))) in one: one[''.join(sorted(list(q)))] += len(f) else: one[''.join(sorted(list(q)))] = len(f) else: if ''.join(sorted(list(q))) in two: two[''.join(sorted(list(q)))] += len(f) else: two[''.join(sorted(list(q)))] = len(f) ans = 0 for i in two: if i[0] in one: two[i] += one[i[0]] if i[1] in one: two[i] += one[i[1]] if ans < two[i]: ans = two[i] for i in one: if one[i] > ans: ans = one[i] print(ans) ```
0
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314", "output": "1762894" }, { "input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585", "output": "2960349" }, { "input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933", "output": "99140444" }, { "input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686", "output": "301124161" }, { "input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495", "output": "30125295" }, { "input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165", "output": "136422" }, { "input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348", "output": "2578628" }, { "input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338", "output": "9168707" }, { "input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657", "output": "144901921" }, { "input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860", "output": "809931" }, { "input": "a\n0\n5 1 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": "5" }, { "input": "lol\n3\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", "output": "21" } ]
1,595,173,643
2,147,483,647
PyPy 3
OK
TESTS
24
140
20,172,800
s = input() k = int(input()) l = list(map(int, input().split())) m = max(l) c = 0 f = 0 for i in s: f+=1 c += l[ord(i)-97] * (f) for i in range(k): f+=1 c += m * f print(c)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? Input Specification: The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. Output Specification: Print a single integer — the largest possible value of the resulting string DZY could get. Demo Input: ['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n'] Demo Output: ['41\n'] Note: In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
```python s = input() k = int(input()) l = list(map(int, input().split())) m = max(l) c = 0 f = 0 for i in s: f+=1 c += l[ord(i)-97] * (f) for i in range(k): f+=1 c += m * f print(c) ```
3
939
B
Hamster Farm
PROGRAMMING
1,000
[ "implementation" ]
null
null
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory produces boxes of *K* kinds, boxes of the *i*-th kind can contain in themselves *a**i* hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount. Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm. Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters.
The first line contains two integers *N* and *K* (0<=≤<=*N*<=≤<=1018, 1<=≤<=*K*<=≤<=105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≤<=*a**i*<=≤<=1018 for all *i*) — the capacities of boxes.
Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input. If there are many correct answers, output any of them.
[ "19 3\n5 4 10\n", "28 3\n5 6 30\n" ]
[ "2 4\n", "1 5\n" ]
none
1,000
[ { "input": "19 3\n5 4 10", "output": "2 4" }, { "input": "28 3\n5 6 30", "output": "1 5" }, { "input": "1 1\n1", "output": "1 1" }, { "input": "0 2\n2 3", "output": "1 0" }, { "input": "30 4\n4 5 5 4", "output": "2 6" }, { "input": "120 7\n109 92 38 38 49 38 92", "output": "3 3" }, { "input": "357 40\n12 10 12 11 12 12 12 10 10 10 12 12 12 12 12 10 12 10 10 10 11 10 12 10 12 10 12 10 10 12 12 12 12 10 10 10 12 12 12 12", "output": "4 32" }, { "input": "587 100\n92 92 76 95 61 60 64 79 64 96 63 92 60 61 95 71 60 61 65 63 84 76 98 63 90 61 61 71 63 61 95 90 79 71 77 67 63 61 63 60 100 71 98 88 67 95 60 61 79 76 70 61 64 65 64 77 96 95 84 100 67 60 84 92 70 100 63 79 61 77 92 74 60 90 84 80 76 61 88 79 64 61 79 60 61 67 98 98 92 76 61 60 80 77 77 76 63 88 99 70", "output": "19 9" }, { "input": "98765 30\n89 841 599 240 356 599 92 305 305 536 356 92 622 1000 751 522 89 149 356 598 305 518 996 92 622 536 356 91 779 770", "output": "28 1085" }, { "input": "947264836 50\n977141206 956777871 186433588 538218068 759102378 327484438 88827268 266300062 670616672 756092978 414181331 913675814 898008516 343057716 99416265 236586817 52751842 550467703 684435578 844649988 917709231 550467703 493542638 707106470 414181331 198095018 913675814 99416265 550467703 679553907 186433588 355713982 670616672 977141206 504598561 327484438 414181331 463431413 546229641 132582931 463431413 759102378 273063720 683939057 924604119 759102378 463431413 52751842 552131077 903126340", "output": "16 4" }, { "input": "600003000040000507 10\n334302557805985467 334302557805985467 681026146296527968 157006854340095780 188330644415015186 803011712275585087 638039699540420111 638039699540420111 600874219702299205 923891462598005659", "output": "5 3" }, { "input": "666 2\n1 300", "output": "1 666" }, { "input": "899999999999999991 1\n199999999999999998", "output": "1 4" }, { "input": "10 1\n11", "output": "1 0" }, { "input": "999999999999999999 1\n500000000000000000", "output": "1 1" }, { "input": "2 1\n2", "output": "1 1" }, { "input": "199999999999999999 1\n100000000000000000", "output": "1 1" }, { "input": "999999999999999999 1\n1000000000000000000", "output": "1 0" }, { "input": "1000000000000000000 1\n500000000000000001", "output": "1 1" }, { "input": "1000000000000000000 1\n2", "output": "1 500000000000000000" }, { "input": "1000000000000000000 5\n500000000000000010 500000000000000010 500000000000000010 500000000000000010 500000000000000030", "output": "5 1" }, { "input": "1000000000000000000 1\n900000000000000000", "output": "1 1" } ]
1,696,337,196
2,147,483,647
PyPy 3-64
OK
TESTS
33
93
14,950,400
n, k = map(int, input().split()) a = list(map(int, input().split())) max_total = -1 maxAmnt = 0 index = 0 for i in range(len(a)): local_ans = (n // a[i]) closest_value = local_ans * a[i] if closest_value > max_total: max_total = closest_value maxAmnt = local_ans index = i+1 print(index, maxAmnt)
Title: Hamster Farm Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory produces boxes of *K* kinds, boxes of the *i*-th kind can contain in themselves *a**i* hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount. Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm. Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters. Input Specification: The first line contains two integers *N* and *K* (0<=≤<=*N*<=≤<=1018, 1<=≤<=*K*<=≤<=105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≤<=*a**i*<=≤<=1018 for all *i*) — the capacities of boxes. Output Specification: Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input. If there are many correct answers, output any of them. Demo Input: ['19 3\n5 4 10\n', '28 3\n5 6 30\n'] Demo Output: ['2 4\n', '1 5\n'] Note: none
```python n, k = map(int, input().split()) a = list(map(int, input().split())) max_total = -1 maxAmnt = 0 index = 0 for i in range(len(a)): local_ans = (n // a[i]) closest_value = local_ans * a[i] if closest_value > max_total: max_total = closest_value maxAmnt = local_ans index = i+1 print(index, maxAmnt) ```
3
21
A
Jabber ID
PROGRAMMING
1,900
[ "implementation", "strings" ]
A. Jabber ID
0
256
Jabber ID on the national Berland service «Babber» has a form &lt;username&gt;@&lt;hostname&gt;[/resource], where - &lt;username&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of &lt;username&gt; is between 1 and 16, inclusive. - &lt;hostname&gt; — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for &lt;username&gt;, the length of each word is between 1 and 16, inclusive. The length of &lt;hostname&gt; is between 1 and 32, inclusive. - &lt;resource&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of &lt;resource&gt; is between 1 and 16, inclusive. The content of square brackets is optional — it can be present or can be absent. There are the samples of correct Jabber IDs: [[email protected]](/cdn-cgi/l/email-protection), [[email protected]](/cdn-cgi/l/email-protection)/contest. Your task is to write program which checks if given string is a correct Jabber ID.
The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.
Print YES or NO.
[ "[email protected]\n", "[email protected]/contest.icpc/12\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]/contest.icpc/12", "output": "NO" }, { "input": "[email protected]/abacaba", "output": "YES" }, { "input": "@ops", "output": "NO" }, { "input": "this-is-the-test", "output": "NO" }, { "input": "[email protected]@codeforces.com", "output": "NO" }, { "input": "oooop/oooop", "output": "NO" }, { "input": "w@S8/XU.5._R7fHq.@../e.WP!54Ey1L.9jv", "output": "NO" }, { "input": "[email protected]!_!CcAOEEx.0z.aiW/S430sbQT", "output": "NO" }, { "input": "@/YTd.K1@lD", "output": "NO" }, { "input": "[email protected]./MzuI", "output": "NO" }, { "input": "_TlPy65w/@[email protected]", "output": "NO" }, { "input": "xpS@._s8.e0lJci/.LdiT", "output": "NO" }, { "input": "lGwo[email protected]", "output": "NO" }, { "input": "Ccz9T5rKZQuEerGo@6l.", "output": "NO" }, { "input": "Y@[email protected]_MK7.g_..0.", "output": "NO" }, { "input": "Q2/6y!SP9s[email protected]_nR8.", "output": "NO" }, { "input": "eWfLL@gW!BEJUxF[email protected]/2.Pr7a/5O6zXdAkikjCEDrb", "output": "NO" }, { "input": "8oI/a@Q", "output": "NO" }, { "input": "J@Y9Gz550l@PqVZdQ!u", "output": "NO" }, { "input": "VTE6aTTta@[email protected]@.l..3Bs", "output": "NO" }, { "input": "[email protected]!Tg..wGN5YOi68U.oP2Yl3/", "output": "NO" }, { "input": "[email protected]@g.9u.v.A..XNH/1/tloIceXydZf3", "output": "NO" }, { "input": "4@@..f3ZT./oUGZ@", "output": "NO" }, { "input": "[email protected]!KtpX4tzs/0yQGzZCPJPJoda", "output": "NO" }, { "input": "[email protected]/VE7gjf", "output": "NO" }, { "input": "bgko@1../xwSj_J", "output": "NO" }, { "input": "[email protected]../.", "output": "NO" }, { "input": "zr.KB_6ZMSwI2GA5@R/4iP1ZKHpszW!YN/", "output": "NO" }, { "input": "@alK@pR", "output": "NO" }, { "input": "al_Y2I4IKp@A_N.ruCw0VL/hRzJtx.S7sp/r!c.n9ffh", "output": "NO" }, { "input": "C1rE26_rTAVzLm@[email protected]./kkBEVlcU", "output": "NO" }, { "input": "feGSXP@eyUfr8.x4Re.JL.6B.r/fX_", "output": "NO" }, { "input": "[email protected]@.", "output": "NO" }, { "input": "[email protected]", "output": "NO" }, { "input": "MiWPE8@fc./IViqq4T4PSUuMdhH", "output": "NO" }, { "input": "[email protected]!.Ntz/QEh_sl", "output": "NO" }, { "input": "s@mH@RO_/iWD", "output": "NO" }, { "input": "UP51i49wX@pvx@2LWm8w/G4M3J./9L6Szy", "output": "NO" }, { "input": "xC_5Vx8NgF..[email protected]@/PQYPeq@_y8!h_iF", "output": "NO" }, { "input": "qG3@LKp", "output": "YES" }, { "input": "flTq1knyb@2!Mtfss", "output": "NO" }, { "input": "/pqi7WXQPJFM4q1@hxUyUy/_pWo0n", "output": "NO" }, { "input": "[email protected]", "output": "NO" }, { "input": "o3EaAnc3K6@h", "output": "YES" }, { "input": "G/AZdVMTzRLV4Ucm@eQ!..pq!..tRTi5.Ejkqa/HGpFYk", "output": "NO" }, { "input": "[email protected]!AFAEk7glM[email protected]/OLKoJpZlac", "output": "NO" }, { "input": "WKxNIM79u@I.RM", "output": "NO" }, { "input": "[email protected]/M_jTHS_6!", "output": "NO" }, { "input": "pbRIiuA@[email protected]", "output": "NO" }, { "input": "[email protected]/juNlxB", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]_.38./zgVGNjpldr", "output": "NO" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]/0EY3XmYatfY", "output": "YES" }, { "input": "[email protected].", "output": "NO" }, { "input": "xLEctap0T@22U9W_fA/7iQeJGFu1lSgMZ", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "BPxNVANhtEh@Oh_go.", "output": "NO" }, { "input": "mGIY@cHRNC8GlJ/2pcl3LYxpi3PaKGs", "output": "YES" }, { "input": "[email protected]/UXC", "output": "NO" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]/i8cnKHT", "output": "YES" }, { "input": "[email protected]/4TBzLWf724zE1r", "output": "YES" }, { "input": "[email protected]/0sN", "output": "NO" }, { "input": "nrKbWV@P0irxQoRxDsNvG/69WxCwCsfB", "output": "YES" }, { "input": "[email protected]/tT5d36", "output": "NO" }, { "input": "[email protected]/_97Ltj3", "output": "YES" }, { "input": "[email protected]_TQ2.z/qfi5CZrH", "output": "YES" }, { "input": "bdHl525me@XzR_iO23v.YFXbnHUybbgw.i/WVEhm", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]./FJ4X", "output": "NO" }, { "input": "[email protected].", "output": "NO" }, { "input": "[email protected]", "output": "YES" }, { "input": "[email protected]/iUij1x7", "output": "YES" }, { "input": "Yesx@9_KiJq2cBI6.", "output": "NO" }, { "input": "Zu5VFUtSbIw@ner5e", "output": "YES" }, { "input": "test@test.", "output": "NO" }, { "input": "[email protected]", "output": "NO" }, { "input": "est.@test", "output": "NO" }, { "input": "[email protected]/", "output": "NO" }, { "input": "asd@asd@", "output": "NO" }, { "input": "@", "output": "NO" }, { "input": "/", "output": "NO" }, { "input": ".", "output": "NO" }, { "input": "mike@", "output": "NO" }, { "input": "@mike", "output": "NO" }, { "input": "@mail.ru", "output": "NO" }, { "input": "test.me", "output": "NO" }, { "input": "$@ru", "output": "NO" }, { "input": "[email protected]/ooooo", "output": "YES" }, { "input": "oooop/oooop", "output": "NO" }, { "input": "mail.ru/a", "output": "NO" }, { "input": "[email protected]/aaa", "output": "YES" }, { "input": "[email protected]", "output": "YES" } ]
1,669,182,821
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#coding=utf-8 import os import sys def isOk(ch): if (ch.isalpha() or ch.isdigit() or ch == '_'): return True return False # solve def solve(): str = raw_input() # judge username pos = str.find('@') if pos <= 0 or str.count('@') != 1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" # judge hostname str = str[pos+1:] if len(str) == 0: return "NO" while True: pos = str.find('.') if pos == -1: if str.find('/') != -1: break for i in str: if not isOk(i): return "NO" break if pos == 0 or pos == len(str)-1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" str = str[pos+1:] # judge resource pos = str.find('/') if pos != -1: if pos == 0: return "NO" str = str[pos+1:] if len(str) == 0: return "NO" for i in str: if not isOk(i): return "NO" return "YES" # main if __name__ == "__main__": print solve()
Title: Jabber ID Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: Jabber ID on the national Berland service «Babber» has a form &lt;username&gt;@&lt;hostname&gt;[/resource], where - &lt;username&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of &lt;username&gt; is between 1 and 16, inclusive. - &lt;hostname&gt; — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for &lt;username&gt;, the length of each word is between 1 and 16, inclusive. The length of &lt;hostname&gt; is between 1 and 32, inclusive. - &lt;resource&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of &lt;resource&gt; is between 1 and 16, inclusive. The content of square brackets is optional — it can be present or can be absent. There are the samples of correct Jabber IDs: [[email protected]](/cdn-cgi/l/email-protection), [[email protected]](/cdn-cgi/l/email-protection)/contest. Your task is to write program which checks if given string is a correct Jabber ID. Input Specification: The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. Output Specification: Print YES or NO. Demo Input: ['[email\xa0protected]\n', '[email\xa0protected]/contest.icpc/12\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python #coding=utf-8 import os import sys def isOk(ch): if (ch.isalpha() or ch.isdigit() or ch == '_'): return True return False # solve def solve(): str = raw_input() # judge username pos = str.find('@') if pos <= 0 or str.count('@') != 1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" # judge hostname str = str[pos+1:] if len(str) == 0: return "NO" while True: pos = str.find('.') if pos == -1: if str.find('/') != -1: break for i in str: if not isOk(i): return "NO" break if pos == 0 or pos == len(str)-1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" str = str[pos+1:] # judge resource pos = str.find('/') if pos != -1: if pos == 0: return "NO" str = str[pos+1:] if len(str) == 0: return "NO" for i in str: if not isOk(i): return "NO" return "YES" # main if __name__ == "__main__": print solve() ```
-1
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,680,637,844
2,147,483,647
Python 3
OK
TESTS
33
358
16,076,800
num = int(input()) aux1 = [0] * num aux2 = [0] * num aux3 = [0] * num list1 = [int(x) for x in input().split()] list2 = [int(x) for x in input().split()] list3 = [int(x) for x in input().split()] for i in range(len(list1)): aux1[i] = list1[i] for i in range(len(list2)): aux2[i] = list2[i] for i in range(len(list3)): aux3[i] = list3[i] aux1.sort(reverse=True) aux2.sort(reverse=True) aux3.sort(reverse=True) for i in range(num): if aux1[i] != aux2[i]: print(aux1[i]) break for i in range(num-1): if aux3[i] != aux2[i]: print(aux2[i]) break
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 num = int(input()) aux1 = [0] * num aux2 = [0] * num aux3 = [0] * num list1 = [int(x) for x in input().split()] list2 = [int(x) for x in input().split()] list3 = [int(x) for x in input().split()] for i in range(len(list1)): aux1[i] = list1[i] for i in range(len(list2)): aux2[i] = list2[i] for i in range(len(list3)): aux3[i] = list3[i] aux1.sort(reverse=True) aux2.sort(reverse=True) aux3.sort(reverse=True) for i in range(num): if aux1[i] != aux2[i]: print(aux1[i]) break for i in range(num-1): if aux3[i] != aux2[i]: print(aux2[i]) break ```
3
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
1,620,288,728
2,147,483,647
Python 3
OK
TESTS
49
154
6,758,400
n=int(input()) x=list(map(int,input().split())) i=0 while n>x[i]: n-=x[i] i=(i+1)%7 print(i+1)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python n=int(input()) x=list(map(int,input().split())) i=0 while n>x[i]: n-=x[i] i=(i+1)%7 print(i+1) ```
3
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output": "12" }, { "input": "3555165 6693472\n1499112 556941 3075290", "output": "3089339" }, { "input": "0 0\n1000000000 1000000000 1000000000", "output": "7000000000" }, { "input": "1 1\n0 1 0", "output": "0" }, { "input": "117708228 562858833\n118004008 360437130 154015822", "output": "738362681" }, { "input": "999998118 700178721\n822106746 82987112 547955384", "output": "1753877029" }, { "input": "566568710 765371101\n60614022 80126928 809950465", "output": "1744607222" }, { "input": "448858599 829062060\n764716760 97644201 203890025", "output": "1178219122" }, { "input": "626115781 966381948\n395190569 820194184 229233367", "output": "1525971878" }, { "input": "803372962 103701834\n394260597 837711458 623172928", "output": "3426388098" }, { "input": "980630143 241021722\n24734406 928857659 312079781", "output": "1624075280" }, { "input": "862920032 378341609\n360240924 241342224 337423122", "output": "974174021" }, { "input": "40177212 515661496\n64343660 963892207 731362684", "output": "3694721078" }, { "input": "217434393 579352456\n694817470 981409480 756706026", "output": "4825785129" }, { "input": "394691574 716672343\n398920207 72555681 150645586", "output": "475704521" }, { "input": "276981463 853992230\n29394015 90072954 839552440", "output": "1754738044" }, { "input": "843552056 919184611\n341530221 423649259 101547519", "output": "263157645" }, { "input": "20809236 56504497\n972004030 441166533 495487081", "output": "4235488636" }, { "input": "198066417 825228166\n602477839 532312735 520830423", "output": "2808777834" }, { "input": "80356306 962548053\n601547868 549830008 914769984", "output": "4004161345" }, { "input": "257613487 394835231\n642087093 567347282 308709545", "output": "2692548667" }, { "input": "139903376 532155119\n641157122 289897263 629020178", "output": "3077110809" }, { "input": "612127849 669475006\n271630930 676010757 22959739", "output": "682559736" }, { "input": "0 0\n0 0 0", "output": "0" }, { "input": "1000000000 1000000000\n499999998 4 333333332", "output": "0" }, { "input": "1000000000 1000000000\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4 3\n1 0 1", "output": "0" }, { "input": "4 12\n1 2 3", "output": "0" }, { "input": "4 20\n1 2 1", "output": "0" }, { "input": "100 10\n2 3 4", "output": "5" }, { "input": "6 0\n1 1 1", "output": "4" }, { "input": "25 5\n3 3 3", "output": "7" }, { "input": "48 27\n22 39 20", "output": "107" }, { "input": "4 0\n1 1 1", "output": "4" } ]
1,535,948,210
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
A, B = input().split() A = int(A) B = int(B) x, y, z = input().split() x = int(x) y = int(y) z = int(z) reqYellowCrystal = 2*x + y reqBlueCrystal = y + 3*z output = (reqYellowCrystal-A) + (reqBlueCrystal-B) print (output)
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. Input Specification: The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. Output Specification: Print a single integer — the minimum number of crystals that Grisha should acquire in addition. Demo Input: ['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n'] Demo Output: ['2\n', '1\n', '2147483648\n'] Note: In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
```python A, B = input().split() A = int(A) B = int(B) x, y, z = input().split() x = int(x) y = int(y) z = int(z) reqYellowCrystal = 2*x + y reqBlueCrystal = y + 3*z output = (reqYellowCrystal-A) + (reqBlueCrystal-B) print (output) ```
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1" } ]
1,689,334,812
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1689334812.225019")# 1689334812.225037
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python print("_RANDOM_GUESS_1689334812.225019")# 1689334812.225037 ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,696,492,452
2,147,483,647
Python 3
OK
TESTS
20
46
0
'''def thanhtung(x,y,n,m): so_hit=0 sat_thuong=x mau=m while n>0: so_hit=so_hit+1 mau=mau-sat_thuong if mau <= 0: sat_thuong = sat_thuong+y mau =m n =n-1 return so_hit x,y,n,m = map(int,input().split()) ket_qua=thanhtung(x,y,n,m) print(ket_qua)''' '''w=int(input()) if w==2: print("NO") elif w%2==0: print("YES") else: print("NO")''' n=int(input()) a=[] for i in range(n): a.append(input()) for i in a: if len(i) <=10: print(i) else: print(i[0]+str(len(i)-2)+i[-1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python '''def thanhtung(x,y,n,m): so_hit=0 sat_thuong=x mau=m while n>0: so_hit=so_hit+1 mau=mau-sat_thuong if mau <= 0: sat_thuong = sat_thuong+y mau =m n =n-1 return so_hit x,y,n,m = map(int,input().split()) ket_qua=thanhtung(x,y,n,m) print(ket_qua)''' '''w=int(input()) if w==2: print("NO") elif w%2==0: print("YES") else: print("NO")''' n=int(input()) a=[] for i in range(n): a.append(input()) for i in a: if len(i) <=10: print(i) else: print(i[0]+str(len(i)-2)+i[-1]) ```
3.977
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations. After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.
The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976", "output": "999975" }, { "input": "25\n13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7", "output": "0" }, { "input": "10\n17 11 7 13 18 12 14 5 16 2", "output": "0" }, { "input": "22\n22 14 23 20 11 21 4 12 3 8 7 9 19 10 13 17 15 1 5 18 16 2", "output": "0" }, { "input": "21\n6 21 24 3 10 23 14 2 26 12 8 1 15 13 9 5 19 20 4 16 22", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n100 60", "output": "75" }, { "input": "4\n999 581 787 236", "output": "974" }, { "input": "6\n198 397 732 1234 309 827", "output": "1209" }, { "input": "11\n6494 3961 1858 4351 8056 780 7720 6211 1961 8192 3621", "output": "8167" }, { "input": "14\n18809 9534 11652 6493 8929 9370 4125 23888 16403 3559 23649 19243 14289 17852", "output": "23863" }, { "input": "18\n24939 35558 47058 70307 26221 12866 3453 40422 47557 36322 40698 64060 10825 77777 48645 26124 4859 64222", "output": "77752" }, { "input": "24\n633483 654321 122445 481150 347578 37803 525083 151084 211073 358699 339420 452023 219553 119727 74852 66750 371279 405099 618894 649977 235337 607819 81649 649804", "output": "654296" }, { "input": "25\n58115 794098 753382 484882 238434 674285 690118 858677 196185 173301 349729 918792 600745 636016 122678 366783 137179 377098 917081 369620 449039 379412 503678 1000000 292099", "output": "999975" }, { "input": "2\n26 27", "output": "2" }, { "input": "3\n40 30 35", "output": "15" }, { "input": "2\n46 45", "output": "21" }, { "input": "3\n1 25 90", "output": "65" }, { "input": "5\n14 15 16 30 92", "output": "67" }, { "input": "2\n1000 1001", "output": "976" }, { "input": "25\n3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2", "output": "3" } ]
1,668,786,621
2,147,483,647
PyPy 3-64
OK
TESTS
25
61
0
k=int(input()) a=[int(i) for i in input().split()] a.sort() if a[-1]<=25: print(0) else : print(a[-1]-25)
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations. After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round. Input Specification: The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. Output Specification: Print the minimum possible number of contestants that declined the invitation to compete onsite. Demo Input: ['25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n', '5\n16 23 8 15 4\n', '3\n14 15 92\n'] Demo Output: ['3\n', '0\n', '67\n'] Note: In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
```python k=int(input()) a=[int(i) for i in input().split()] a.sort() if a[-1]<=25: print(0) else : print(a[-1]-25) ```
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, { "input": "3\n1\n5", "output": "20" }, { "input": "6\n7\n1", "output": "48" }, { "input": "1\n8\n3", "output": "27" }, { "input": "9\n7\n2", "output": "126" }, { "input": "1\n1\n10", "output": "20" }, { "input": "9\n1\n1", "output": "18" }, { "input": "10\n5\n6", "output": "300" }, { "input": "8\n9\n7", "output": "504" }, { "input": "4\n2\n10", "output": "80" }, { "input": "2\n8\n3", "output": "48" }, { "input": "3\n5\n7", "output": "105" }, { "input": "1\n10\n1", "output": "12" }, { "input": "2\n2\n2", "output": "8" }, { "input": "5\n6\n1", "output": "35" }, { "input": "10\n1\n1", "output": "20" }, { "input": "1\n6\n1", "output": "8" }, { "input": "1\n9\n1", "output": "11" }, { "input": "2\n1\n2", "output": "6" }, { "input": "2\n6\n1", "output": "14" }, { "input": "9\n2\n1", "output": "27" }, { "input": "1\n9\n2", "output": "20" }, { "input": "1\n3\n1", "output": "5" }, { "input": "2\n1\n1", "output": "4" } ]
1,694,160,268
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
import math a=int(input()) b=int(input()) c=int(input()) l=[a*(b+c),(a*b)+c,a*b*c,a+b*c,(a+b)*c] m=max(l) print(m)
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python import math a=int(input()) b=int(input()) c=int(input()) l=[a*(b+c),(a*b)+c,a*b*c,a+b*c,(a+b)*c] m=max(l) print(m) ```
0
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "197" }, { "input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87", "output": "0" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
1,686,922,482
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<stdio.h> int main() { int n,t=0,i; scanf("%d", &n); int a[n]; for(i=0; i<n; i++) { scanf("%d", &a[i]); } int mx=0,mn=101,pos1,pos2,temp; for (i=0; i<n; i++) { if (mx<=a[i]) { mx=a[i]; pos1=i; } } for (i=pos1; i>0; i--) { temp=a[i]; a[i]=a[i-1]; a[i-1]=temp; t++; } for (i=0; i<n; i++) { if (mn>=a[i]) { mn=a[i]; pos2=i; } } for (i=pos2; i<n-1; i++) { temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; t++; } printf("%d", t); }
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. Input Specification: The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. Output Specification: Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. Demo Input: ['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n'] Demo Output: ['2\n', '10\n'] Note: In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
```python #include<stdio.h> int main() { int n,t=0,i; scanf("%d", &n); int a[n]; for(i=0; i<n; i++) { scanf("%d", &a[i]); } int mx=0,mn=101,pos1,pos2,temp; for (i=0; i<n; i++) { if (mx<=a[i]) { mx=a[i]; pos1=i; } } for (i=pos1; i>0; i--) { temp=a[i]; a[i]=a[i-1]; a[i-1]=temp; t++; } for (i=0; i<n; i++) { if (mn>=a[i]) { mn=a[i]; pos2=i; } } for (i=pos2; i<n-1; i++) { temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; t++; } printf("%d", t); } ```
-1
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,672,384,367
2,147,483,647
Python 3
OK
TESTS
102
62
409,600
#!/usr/bin/env python import math,collections,re from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque input = stdin.readline def inp(): return(int(input())) def inplst(nospaces=False): if nospaces: return list(map(int,list(input().rstrip()))) return(list(map(int,input().split()))) def inpstr(): return(input().rstrip()) def inpvar(): return(map(int,input().split())) def out(char,joinChar=" "): if isinstance(char,tuple) or isinstance(char,list): char = joinChar.join(map(str,char)) stdout.write(str(char)+"\n") return DATAPATH = "~/datasets/" ## ---- Main ---- ## one,two = inplst(True), inplst(True) three = [0]*len(one) for i in range(len(one)): if one[i]!=two[i]: three[i]=1 out(three,"")
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 #!/usr/bin/env python import math,collections,re from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque input = stdin.readline def inp(): return(int(input())) def inplst(nospaces=False): if nospaces: return list(map(int,list(input().rstrip()))) return(list(map(int,input().split()))) def inpstr(): return(input().rstrip()) def inpvar(): return(map(int,input().split())) def out(char,joinChar=" "): if isinstance(char,tuple) or isinstance(char,list): char = joinChar.join(map(str,char)) stdout.write(str(char)+"\n") return DATAPATH = "~/datasets/" ## ---- Main ---- ## one,two = inplst(True), inplst(True) three = [0]*len(one) for i in range(len(one)): if one[i]!=two[i]: three[i]=1 out(three,"") ```
3.983737
505
A
Mr. Kitayuta's Gift
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
500
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "input": "fft", "output": "tfft" }, { "input": "shuseki", "output": "NA" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "ewcdcwerp", "output": "NA" }, { "input": "noon", "output": "nooon" }, { "input": "add", "output": "adda" }, { "input": "iq", "output": "qiq" }, { "input": "hogloid", "output": "NA" }, { "input": "yosupo", "output": "NA" }, { "input": "stat", "output": "stats" }, { "input": "level", "output": "levvel" }, { "input": "iwiwi", "output": "iwiiwi" }, { "input": "racecar", "output": "raceecar" }, { "input": "dog", "output": "NA" }, { "input": "squirrel", "output": "NA" }, { "input": "slime", "output": "NA" }, { "input": "palindrome", "output": "NA" }, { "input": "nqwcvcwqn", "output": "nqwcvvcwqn" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "jewiiwefj", "output": "jfewiiwefj" }, { "input": "vnwmvvmonv", "output": "NA" }, { "input": "zennyuu", "output": "NA" }, { "input": "mrtoudai", "output": "NA" }, { "input": "z", "output": "zz" }, { "input": "babccba", "output": "babccbab" }, { "input": "battaba", "output": "abattaba" }, { "input": "bbb", "output": "bbbb" }, { "input": "zaa", "output": "zaaz" }, { "input": "abbabab", "output": "NA" }, { "input": "racecar", "output": "raceecar" }, { "input": "zzz", "output": "zzzz" }, { "input": "eviver", "output": "reviver" }, { "input": "aaaaa", "output": "aaaaaa" }, { "input": "eee", "output": "eeee" } ]
1,593,629,522
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
93
307,200
s = input() li = list(s) length = len(s) if s[::] == s[::-1]: if length & 1 == 0: li.insert(length//2,'a') else: li.insert((length//2)+1,li[length//2]) else: for i in range(length//2): if li[i] != li[length - 1 - i]: if length - i > length: li.append(li[i]) else: li.insert(length-i,li[i]) break if ''.join(li) == ''.join(li[::-1]): print(''.join(li)) else: print("NA")
Title: Mr. Kitayuta's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them. Input Specification: The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. Output Specification: If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. Demo Input: ['revive\n', 'ee\n', 'kitayuta\n'] Demo Output: ['reviver\n', 'eye', 'NA\n'] Note: For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
```python s = input() li = list(s) length = len(s) if s[::] == s[::-1]: if length & 1 == 0: li.insert(length//2,'a') else: li.insert((length//2)+1,li[length//2]) else: for i in range(length//2): if li[i] != li[length - 1 - i]: if length - i > length: li.append(li[i]) else: li.insert(length-i,li[i]) break if ''.join(li) == ''.join(li[::-1]): print(''.join(li)) else: print("NA") ```
0
626
A
Robot Sequence
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.
The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.
Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.
[ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n" ]
[ "2\n", "0\n", "12\n" ]
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
500
[ { "input": "6\nURLLDR", "output": "2" }, { "input": "4\nDLUU", "output": "0" }, { "input": "7\nRLRLRLR", "output": "12" }, { "input": "1\nR", "output": "0" }, { "input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL", "output": "1225" }, { "input": "200\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "100" }, { "input": "20\nLDURLDURRLRUDLRRUDLU", "output": "29" }, { "input": "140\nDLDLULULDRDDDLLUDRRDLLUULLDDLDLUURLDLDRDUDDLRRDURUUUUURLDUDDLLRRLLDRRRDDDDDUDUULLURRDLDULUDLLUUDRRLUDULUDUDULULUURURRDUURRDLULLURUDDDDRDRDRD", "output": "125" }, { "input": "194\nULLLDLLDRUUDURRULLRLUUURDRLLURDUDDUDLULRLDRUDURLDLRDLLLLUDDRRRULULULUDDULRURURLLDLDLDRUDUUDULRULDDRRLRDRULLDRULLLLRRDDLLLLULDRLUULRUUULDUUDLDLDUUUDDLDDRULDRRLUURRULLDULRRDLLRDURDLUUDUDLLUDDULDDD", "output": "282" }, { "input": "200\nDDDURLLUUULUDDURRDLLDDLLRLUULUULDDDLRRDLRRDUDURDUDRRLLDRDUDDLDDRDLURRRLLRDRRLLLRDDDRDRRLLRRLULRUULRLDLUDRRRDDUUURLLUDRLDUDRLLRLRRLUDLRULDUDDRRLLRLURDLRUDDDURLRDUDUUURLLULULRDRLDLDRURDDDLLRUDDRDUDDDLRU", "output": "408" }, { "input": "197\nDUUDUDUDUDUUDUUDUUUDDDDUUUDUUUDUUUUUDUUUDDUDDDUUDUDDDUUDDUUUUUUUDUDDDDDUUUUUDDDDDDUUUUDDUDDUDDDUDUUUDUUDUDUDUUUDUDDDDUUDDUDDDDUDDDUDUUUDUUDUUUDDDDUUUDUUDDUUUUUDDDDUUDUUDDDDUDDUUDUUUDDDDUDUUUDDDUUDU", "output": "1995" }, { "input": "200\nLLLLRLLRLLRRRRLLRRLRRLRRRLLLRRLRRRRLLRRLLRRRLRLRLRRLLRLLRRLLLRRRRLRLLRLLLRLLLRRLLLRLRLRRRRRRRLRRRLRLRLLLLRLRRRRRLRRLRLLLLRLLLRRLRRLLRLRLLLRRLLRRLRRRRRLRLRRLRLLRLLLLRLRRRLRRLRLLRLRRLRRRRRLRRLLLRRRRRLLR", "output": "1368" }, { "input": "184\nUUUDDUDDDDDUDDDDUDDUUUUUDDDUUDDUDUUDUUUDDUDDDDDDDDDDUDUDDUUDDDUUDDUDUDDDUUDUDUUUUDDUDUUUDDUDUUUUDUUDDUUDUUUDUDUDDUDUDDDUUDDDDUUUUUDDDUDUDUDUDUDUUUDUDDUUDDUDUUDUDUUUDUUDDDDUDDDDUDUUDUUD", "output": "1243" }, { "input": "187\nRLLRLRRLLRRLRRRRLLRLLRLLLLRRRLLLRLLLLRRLRLRRRRRRLLRRLRLLRRRLLRRLLLRRLRRLRLLLLRRRRLRRLLRRLRRRRLLLLRRLRLRLRRRRRLLRLRLRLRLRLRLLLRLLLLLRRRLLRLRRRLLLRRLLLLLRLLRLLLRRRLLLRRLRRRLLLRRLRLLRRLRLRLR", "output": "1501" }, { "input": "190\nUULLLUUULLLULLUULUUUUULUUULLULLULUULLUULLUUULULUULLUULLUUULULLLLLLULLLLLULUULLULLULLLUULUULLLUUUULLLLUUULLUUULLLULULUULULLUULULULUUULLUUUULLUUULULUULLLLULLLLLUULLUULULLULUUUUUULULLLULLUULUUU", "output": "0" }, { "input": "46\nULUURRRRLDRDRDDDURRRLLLDDULLRRRRRLUDDLRDRULLLL", "output": "23" }, { "input": "70\nUUDRLDRDRUDLLURURULRDULRRDULDUDDRUULLDDDDDRLLRDURRDULRDLRUUUDDLRUURRLD", "output": "86" }, { "input": "198\nURLLUDRDUUDRDLLRURULLRRLRRUULRLULUUDRRURLRUURRDRUUDRLRURLLULRDDDDDRDDRRRLRUDULLDDLLLUDRLDRUDRDLDUULLUUUULULLRLDDRDURDRURLULDRURLLDDULURULDLUUUUULDLURRLLDLULLDULRUURRLDLLUUURDLDDUDUULRLUDULLULDRDRLRL", "output": "160" }, { "input": "22\nDUDDDURURUDURRUDRDULUL", "output": "10" }, { "input": "200\nUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUD", "output": "10000" }, { "input": "4\nRRDR", "output": "0" }, { "input": "6\nUULLLL", "output": "0" }, { "input": "2\nDU", "output": "1" }, { "input": "6\nUURRRR", "output": "0" }, { "input": "101\nRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", "output": "0" } ]
1,571,176,799
2,147,483,647
PyPy 3
OK
TESTS
25
156
4,300,800
tam = int(input()) string = input() total = 0 substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)] #print(substrings) multiplas = [] for sub in substrings: if len(sub) % 2 == 0: multiplas.append(sub) #print(multiplas) for palavra in multiplas: countD = 0 countU = 0 countR = 0 countL = 0 for letra in palavra: if(letra == 'D'): countD += 1 elif(letra == 'U'): countU += 1 elif(letra == 'R'): countR += 1 elif(letra == 'L'): countL += 1 if(countD == countU and countL == countR): total += 1 print(total) ''' Input 6 URLLDR Output 2 Input 4 DLUU Output 0 Input 7 RLRLRLR Output 12 '''
Title: Robot Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices. Input Specification: The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code. Output Specification: Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square. Demo Input: ['6\nURLLDR\n', '4\nDLUU\n', '7\nRLRLRLR\n'] Demo Output: ['2\n', '0\n', '12\n'] Note: In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
```python tam = int(input()) string = input() total = 0 substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)] #print(substrings) multiplas = [] for sub in substrings: if len(sub) % 2 == 0: multiplas.append(sub) #print(multiplas) for palavra in multiplas: countD = 0 countU = 0 countR = 0 countL = 0 for letra in palavra: if(letra == 'D'): countD += 1 elif(letra == 'U'): countU += 1 elif(letra == 'R'): countR += 1 elif(letra == 'L'): countL += 1 if(countD == countU and countL == countR): total += 1 print(total) ''' Input 6 URLLDR Output 2 Input 4 DLUU Output 0 Input 7 RLRLRLR Output 12 ''' ```
3
219
A
k-String
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
[ "2\naazz\n", "3\nabcabcabz\n" ]
[ "azaz\n", "-1\n" ]
none
500
[ { "input": "2\naazz", "output": "azaz" }, { "input": "3\nabcabcabz", "output": "-1" }, { "input": "1\na", "output": "a" }, { "input": "2\nabba", "output": "abab" }, { "input": "2\naaab", "output": "-1" }, { "input": "7\nabacaba", "output": "-1" }, { "input": "5\naaaaa", "output": "aaaaa" }, { "input": "3\naabaaaaabb", "output": "-1" }, { "input": "2\naaab", "output": "-1" }, { "input": "2\nbabac", "output": "-1" }, { "input": "3\nbbbccc", "output": "bcbcbc" }, { "input": "2\naa", "output": "aa" }, { "input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece", "output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece" }, { "input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa", "output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc" }, { "input": "1\naaa", "output": "aaa" }, { "input": "1\naabaab", "output": "aaaabb" }, { "input": "2\naabbbbccccccdddddddd", "output": "abbcccddddabbcccdddd" }, { "input": "3\naaaaaaaaacccdddddd", "output": "aaacddaaacddaaacdd" }, { "input": "3\naaaaaaaaacccbbbbbb", "output": "aaabbcaaabbcaaabbc" }, { "input": "2\naazzzz", "output": "azzazz" }, { "input": "2\naaaa", "output": "aaaa" }, { "input": "2\naaaazz", "output": "aazaaz" }, { "input": "2\naaaabb", "output": "aabaab" }, { "input": "2\naabbbb", "output": "abbabb" }, { "input": "2\naaaazzzz", "output": "aazzaazz" }, { "input": "2\naaazz", "output": "-1" }, { "input": "2\nbbbbaa", "output": "abbabb" }, { "input": "2\naaaaaabbbb", "output": "aaabbaaabb" }, { "input": "2\naaaaaazz", "output": "aaazaaaz" }, { "input": "2\naaaabbbb", "output": "aabbaabb" }, { "input": "2\naabaab", "output": "aabaab" }, { "input": "1\naaaaa", "output": "aaaaa" }, { "input": "2\nbbaaaa", "output": "aabaab" }, { "input": "2\nacaccc", "output": "accacc" } ]
1,691,590,883
2,147,483,647
PyPy 3-64
OK
TESTS
42
154
0
k = int(input()) s = input() if len(s) % k != 0: print(-1) else: d = {} for i in s: d[i] = d.get(i, 0) + 1 string = "" score = 0 for m in list(d.values()): if m % k != 0: score = -1 break if score == 0: for l in range(k): for j in d: string += j*(d[j]//k) print(string) else: print(-1)
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. Input Specification: The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. Output Specification: Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes). Demo Input: ['2\naazz\n', '3\nabcabcabz\n'] Demo Output: ['azaz\n', '-1\n'] Note: none
```python k = int(input()) s = input() if len(s) % k != 0: print(-1) else: d = {} for i in s: d[i] = d.get(i, 0) + 1 string = "" score = 0 for m in list(d.values()): if m % k != 0: score = -1 break if score == 0: for l in range(k): for j in d: string += j*(d[j]//k) print(string) else: print(-1) ```
3
358
B
Dima and Text Messages
PROGRAMMING
1,500
[ "brute force", "strings" ]
null
null
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
[ "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n" ]
[ "yes\n", "no\n" ]
Please note that Dima got a good old kick in the pants for the second sample from the statement.
1,000
[ { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes" }, { "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "output": "yes" }, { "input": "4\na\nb\nc\nd\n<3a<3b<3c<3d", "output": "no" }, { "input": "4\na\nb\nc\nd\na<3b<3c<3d<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<3you<3", "output": "yes" }, { "input": "1\na\na", "output": "no" }, { "input": "1\na\n<3a<3b", "output": "yes" }, { "input": "1\naa\n<3a<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww", "output": "yes" }, { "input": "3\ni\nlove\nyou\n<3ilove<23you<3", "output": "no" }, { "input": "2\na\ni\n<3ai<3", "output": "no" } ]
1,556,876,042
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
124
0
n = int(input()) s = ''.join([input() for _ in range(n)]) k = input() i = 0; j = len(k)-1 while(k[i] in '<>0123456789'): i += 1 while(k[j] in '<>0123456789'): j -= 1 t1 = k[:i]; t2 = k[j+1:] def r(t): return t.find('<') > -1 and t.find('<') < t.rfind('3') if not r(t1) or not r(t2): print('no'); exit() t = ''.join([i for i in k if i not in '<>0123456789']) print('yes' if t == s else 'no')
Title: Dima and Text Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. Output Specification: In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. Demo Input: ['3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n', '7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n'] Demo Output: ['yes\n', 'no\n'] Note: Please note that Dima got a good old kick in the pants for the second sample from the statement.
```python n = int(input()) s = ''.join([input() for _ in range(n)]) k = input() i = 0; j = len(k)-1 while(k[i] in '<>0123456789'): i += 1 while(k[j] in '<>0123456789'): j -= 1 t1 = k[:i]; t2 = k[j+1:] def r(t): return t.find('<') > -1 and t.find('<') < t.rfind('3') if not r(t1) or not r(t2): print('no'); exit() t = ''.join([i for i in k if i not in '<>0123456789']) print('yes' if t == s else 'no') ```
0
761
B
Dasha and friends
PROGRAMMING
1,300
[ "brute force", "implementation", "math" ]
null
null
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the *n* barriers. Thus, each of them wrote *n* integers in the ascending order, each of them was between 0 and *L*<=-<=1, inclusively. There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.
The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length. The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to *L*<=-<=1 inclusively. The second line contains *n* distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to *L*<=-<=1 inclusively.
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).
[ "3 8\n2 4 6\n1 5 7\n", "4 9\n2 3 5 8\n0 1 3 6\n", "2 4\n1 3\n1 2\n" ]
[ "YES\n", "YES\n", "NO\n" ]
The first test is analyzed in the statement.
1,000
[ { "input": "3 8\n2 4 6\n1 5 7", "output": "YES" }, { "input": "4 9\n2 3 5 8\n0 1 3 6", "output": "YES" }, { "input": "2 4\n1 3\n1 2", "output": "NO" }, { "input": "5 9\n0 2 5 6 7\n1 3 6 7 8", "output": "YES" }, { "input": "5 60\n7 26 27 40 59\n14 22 41 42 55", "output": "YES" }, { "input": "20 29\n0 1 2 4 5 8 9 12 14 15 17 19 20 21 22 23 25 26 27 28\n0 2 4 5 6 7 8 10 11 12 13 14 15 16 18 19 22 23 26 28", "output": "YES" }, { "input": "35 41\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 18 19 20 21 22 23 24 25 26 28 30 31 32 33 34 35 36 37 38 39 40\n0 1 2 3 4 5 7 8 9 10 11 12 16 17 18 19 20 21 22 23 24 26 28 29 30 31 32 33 34 35 36 37 38 39 40", "output": "YES" }, { "input": "40 63\n0 2 3 4 5 6 9 10 12 15 17 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62", "output": "NO" }, { "input": "50 97\n1 2 3 4 6 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96", "output": "NO" }, { "input": "50 100\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99", "output": "YES" }, { "input": "1 2\n0\n0", "output": "YES" }, { "input": "1 2\n0\n1", "output": "YES" }, { "input": "1 2\n1\n0", "output": "YES" }, { "input": "1 2\n1\n1", "output": "YES" }, { "input": "1 1\n0\n0", "output": "YES" }, { "input": "5 12\n2 3 4 8 10\n2 3 4 8 10", "output": "YES" }, { "input": "1 18\n3\n10", "output": "YES" }, { "input": "1 75\n65\n8", "output": "YES" }, { "input": "2 16\n4 13\n2 11", "output": "YES" }, { "input": "2 95\n45 59\n3 84", "output": "YES" }, { "input": "3 53\n29 43 50\n29 43 50", "output": "YES" }, { "input": "3 60\n39 46 51\n43 50 55", "output": "YES" }, { "input": "4 4\n0 1 2 3\n0 1 2 3", "output": "YES" }, { "input": "4 93\n45 48 50 90\n20 68 71 73", "output": "YES" }, { "input": "6 18\n0 3 8 11 15 16\n2 7 10 14 15 17", "output": "YES" }, { "input": "6 87\n0 1 21 31 34 66\n11 12 32 42 45 77", "output": "YES" }, { "input": "7 26\n0 3 9 13 14 19 20\n4 7 13 17 18 23 24", "output": "YES" }, { "input": "7 81\n0 12 19 24 25 35 59\n1 8 13 14 24 48 70", "output": "YES" }, { "input": "8 20\n0 1 2 3 5 6 14 15\n1 2 10 11 16 17 18 19", "output": "YES" }, { "input": "8 94\n0 8 11 27 38 54 57 89\n1 33 38 46 49 65 76 92", "output": "YES" }, { "input": "9 18\n1 3 6 8 11 12 13 16 17\n0 2 5 6 7 10 11 13 15", "output": "YES" }, { "input": "9 90\n10 11 27 33 34 55 63 84 87\n9 12 25 26 42 48 49 70 78", "output": "YES" }, { "input": "10 42\n4 9 10 14 15 16 19 33 36 40\n0 14 17 21 27 32 33 37 38 39", "output": "YES" }, { "input": "10 73\n4 5 15 19 20 25 28 42 57 58\n3 4 9 12 26 41 42 61 62 72", "output": "YES" }, { "input": "11 11\n0 1 2 3 4 5 6 7 8 9 10\n0 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "11 57\n1 4 27 30 31 35 37 41 50 52 56\n22 25 26 30 32 36 45 47 51 53 56", "output": "YES" }, { "input": "12 73\n5 9 11 20 25 36 40 41 44 48 56 60\n12 16 18 27 32 43 47 48 51 55 63 67", "output": "YES" }, { "input": "12 95\n1 37 42 46 56 58 59 62 64 71 76 80\n2 18 54 59 63 73 75 76 79 81 88 93", "output": "YES" }, { "input": "13 29\n2 5 6 9 12 17 18 19 20 21 22 24 27\n0 3 6 11 12 13 14 15 16 18 21 25 28", "output": "YES" }, { "input": "13 90\n9 18 23 30 31 36 39 44 58 59 74 82 87\n1 6 18 27 32 39 40 45 48 53 67 68 83", "output": "YES" }, { "input": "14 29\n1 2 3 4 5 7 9 12 13 20 21 22 23 24\n0 3 4 11 12 13 14 15 21 22 23 24 25 27", "output": "YES" }, { "input": "14 94\n7 8 9 21 34 35 36 37 38 43 46 52 84 93\n2 3 4 16 29 30 31 32 33 38 41 47 79 88", "output": "YES" }, { "input": "15 19\n1 2 3 4 5 6 7 8 9 10 11 13 14 16 17\n0 1 2 3 4 5 6 7 8 9 10 12 13 15 16", "output": "YES" }, { "input": "15 27\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26", "output": "YES" }, { "input": "16 28\n3 5 6 7 9 10 11 12 13 14 17 19 20 25 26 27\n0 5 6 7 11 13 14 15 17 18 19 20 21 22 25 27", "output": "YES" }, { "input": "16 93\n5 6 10 11 13 14 41 43 46 61 63 70 74 79 83 92\n0 9 15 16 20 21 23 24 51 53 56 71 73 80 84 89", "output": "YES" }, { "input": "17 49\n2 5 11 12 16 18 19 21 22 24 36 37 38 39 40 44 47\n1 7 8 12 14 15 17 18 20 32 33 34 35 36 40 43 47", "output": "YES" }, { "input": "17 86\n16 17 25 33 39 41 50 51 54 56 66 70 72 73 77 80 85\n3 9 11 20 21 24 26 36 40 42 43 47 50 55 72 73 81", "output": "YES" }, { "input": "18 20\n0 1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n0 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19", "output": "YES" }, { "input": "18 82\n0 5 10 13 14 16 21 28 29 30 44 46 61 64 69 71 77 78\n0 5 8 9 11 16 23 24 25 39 41 56 59 64 66 72 73 77", "output": "YES" }, { "input": "19 25\n0 1 2 3 5 7 9 10 12 13 16 17 18 19 20 21 22 23 24\n0 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 21 22 24", "output": "YES" }, { "input": "19 91\n5 17 18 20 22 25 26 31 32 33 43 47 54 61 62 64 77 80 87\n4 5 6 16 20 27 34 35 37 50 53 60 69 81 82 84 86 89 90", "output": "YES" }, { "input": "20 53\n2 6 8 9 16 17 20 21 22 23 25 26 35 36 38 39 44 46 47 50\n4 5 8 9 10 11 13 14 23 24 26 27 32 34 35 38 43 47 49 50", "output": "YES" }, { "input": "21 44\n0 1 3 4 6 7 8 9 10 11 12 15 17 18 21 22 27 29 34 36 42\n1 7 9 10 12 13 15 16 17 18 19 20 21 24 26 27 30 31 36 38 43", "output": "YES" }, { "input": "21 94\n3 5 6 8 9 15 16 20 28 31 35 39 49 50 53 61 71 82 85 89 90\n6 17 20 24 25 32 34 35 37 38 44 45 49 57 60 64 68 78 79 82 90", "output": "YES" }, { "input": "22 24\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23", "output": "YES" }, { "input": "22 85\n3 5 7 14 18 21 25 32 38 41 53 58 61 62 66 70 71 73 75 76 79 83\n3 6 18 23 26 27 31 35 36 38 40 41 44 48 53 55 57 64 68 71 75 82", "output": "YES" }, { "input": "23 38\n0 2 4 5 7 8 12 13 14 16 17 18 21 22 24 27 28 30 31 32 35 36 37\n0 1 2 3 5 7 8 10 11 15 16 17 19 20 21 24 25 27 30 31 33 34 35", "output": "YES" }, { "input": "23 93\n1 3 5 10 19 22 26 27 30 35 39 53 55 60 66 67 75 76 77 80 82 89 90\n9 11 16 22 23 31 32 33 36 38 45 46 50 52 54 59 68 71 75 76 79 84 88", "output": "YES" }, { "input": "24 37\n1 4 5 6 8 11 12 13 15 16 17 19 20 21 23 26 27 28 30 31 33 34 35 36\n0 3 4 5 7 8 10 11 12 13 15 18 19 20 22 25 26 27 29 30 31 33 34 35", "output": "YES" }, { "input": "24 94\n9 10 13 14 16 18 19 22 24 29 32 35 48 55 57 63 64 69 72 77 78 85 90 92\n1 7 8 13 16 21 22 29 34 36 47 48 51 52 54 56 57 60 62 67 70 73 86 93", "output": "YES" }, { "input": "25 45\n0 1 2 4 6 7 8 9 13 14 17 19 21 22 23 25 28 29 30 31 34 36 38 39 42\n1 3 4 5 7 10 11 12 13 16 18 20 21 24 27 28 29 31 33 34 35 36 40 41 44", "output": "YES" }, { "input": "25 72\n1 2 6 8 9 11 15 18 19 20 26 29 31 33 34 40 41 43 45 48 58 60 68 69 71\n0 6 9 11 13 14 20 21 23 25 28 38 40 48 49 51 53 54 58 60 61 63 67 70 71", "output": "YES" }, { "input": "26 47\n0 2 5 7 8 9 10 12 13 14 20 22 23 25 27 29 31 32 33 35 36 37 38 42 44 45\n0 2 4 6 8 9 10 12 13 14 15 19 21 22 24 26 29 31 32 33 34 36 37 38 44 46", "output": "YES" }, { "input": "26 99\n0 1 13 20 21 22 25 26 27 28 32 39 44 47 56 58 60 62 71 81 83 87 89 93 94 98\n6 8 12 14 18 19 23 24 25 37 44 45 46 49 50 51 52 56 63 68 71 80 82 84 86 95", "output": "YES" }, { "input": "27 35\n0 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 19 20 21 23 26 27 29 30 31 32 33\n0 1 2 3 5 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 24 25 26 28 31 32 34", "output": "YES" }, { "input": "27 51\n1 2 4 7 8 11 13 17 20 21 23 24 25 28 29 30 34 35 37 38 40 43 45 46 47 48 50\n0 1 2 4 6 7 9 12 13 16 18 22 25 26 28 29 30 33 34 35 39 40 42 43 45 48 50", "output": "YES" }, { "input": "28 38\n1 4 5 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 28 29 30 32 33 35 36 37\n0 1 2 3 4 5 6 9 10 11 13 14 16 17 18 20 23 24 26 27 28 29 30 31 33 34 35 37", "output": "YES" }, { "input": "28 67\n0 1 2 3 6 9 10 15 18 22 24 25 30 35 36 38 39 47 48 49 51 53 55 56 58 62 63 64\n4 7 11 13 14 19 24 25 27 28 36 37 38 40 42 44 45 47 51 52 53 56 57 58 59 62 65 66", "output": "YES" }, { "input": "29 29\n0 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\n0 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", "output": "YES" }, { "input": "29 93\n1 2 11 13 18 21 27 28 30 38 41 42 46 54 55 56 60 61 63 64 66 69 71 72 77 81 83 89 90\n2 10 11 12 16 17 19 20 22 25 27 28 33 37 39 45 46 50 51 60 62 67 70 76 77 79 87 90 91", "output": "YES" }, { "input": "30 63\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61", "output": "YES" }, { "input": "30 91\n1 2 3 7 8 9 13 16 17 19 27 29 38 45 47 52 53 55 61 62 66 77 78 79 80 81 82 84 88 89\n3 4 5 9 12 13 15 23 25 34 41 43 48 49 51 57 58 62 73 74 75 76 77 78 80 84 85 88 89 90", "output": "YES" }, { "input": "31 39\n0 1 2 3 4 5 6 7 8 10 11 13 14 17 18 20 21 23 24 25 27 28 29 30 31 33 34 35 36 37 38\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 21 22 25 26 28 29 31 32 33 35 36 37 38", "output": "YES" }, { "input": "31 95\n9 12 14 15 21 23 26 28 30 36 37 42 47 51 54 56 59 62 64 65 66 70 72 74 75 79 82 85 87 91 93\n0 2 3 7 10 13 15 19 21 32 35 37 38 44 46 49 51 53 59 60 65 70 74 77 79 82 85 87 88 89 93", "output": "YES" }, { "input": "32 61\n0 2 3 5 7 10 13 14 15 18 19 20 21 22 23 24 26 32 33 34 36 38 43 46 47 51 54 55 56 57 58 59\n1 2 4 6 9 12 13 14 17 18 19 20 21 22 23 25 31 32 33 35 37 42 45 46 50 53 54 55 56 57 58 60", "output": "YES" }, { "input": "32 86\n5 7 9 10 13 17 18 19 25 26 28 32 33 37 38 43 45 47 50 53 57 58 60 69 73 74 75 77 80 82 83 85\n7 11 12 13 15 18 20 21 23 29 31 33 34 37 41 42 43 49 50 52 56 57 61 62 67 69 71 74 77 81 82 84", "output": "YES" }, { "input": "33 44\n0 1 2 3 5 9 10 11 12 13 14 15 17 18 20 21 22 23 24 25 26 27 28 30 31 32 35 36 38 39 41 42 43\n0 2 3 4 7 8 10 11 13 14 15 16 17 18 19 21 25 26 27 28 29 30 31 33 34 36 37 38 39 40 41 42 43", "output": "YES" }, { "input": "33 73\n3 6 7 8 9 10 11 13 14 15 17 19 22 23 26 27 28 31 33 34 35 37 42 44 48 52 54 57 62 63 64 67 68\n2 3 4 7 8 16 19 20 21 22 23 24 26 27 28 30 32 35 36 39 40 41 44 46 47 48 50 55 57 61 65 67 70", "output": "YES" }, { "input": "34 52\n1 2 3 4 5 6 8 9 10 12 13 14 15 16 17 19 21 24 26 27 28 29 31 33 35 36 37 39 40 45 46 49 50 51\n0 1 2 3 4 6 7 8 10 11 12 13 14 15 17 19 22 24 25 26 27 29 31 33 34 35 37 38 43 44 47 48 49 51", "output": "YES" }, { "input": "34 68\n0 7 9 10 11 14 15 16 20 21 22 24 26 32 34 35 37 38 40 41 42 43 44 45 47 50 53 55 57 58 59 62 64 65\n0 1 2 3 5 8 11 13 15 16 17 20 22 23 26 33 35 36 37 40 41 42 46 47 48 50 52 58 60 61 63 64 66 67", "output": "YES" }, { "input": "35 90\n4 5 7 8 10 11 12 13 14 22 27 29 31 33 34 38 46 49 52 53 54 55 56 57 60 61 64 69 77 81 83 86 87 88 89\n4 7 10 11 12 13 14 15 18 19 22 27 35 39 41 44 45 46 47 52 53 55 56 58 59 60 61 62 70 75 77 79 81 82 86", "output": "YES" }, { "input": "36 43\n1 2 3 4 6 7 8 9 10 11 14 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 42\n0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 21 23 24 25 26 28 29 30 31 32 33 36 38 39 40 41 42", "output": "YES" }, { "input": "36 84\n1 3 6 13 15 16 17 18 19 21 23 26 29 33 38 40 42 45 49 50 53 54 57 58 60 61 64 65 67 70 73 76 78 79 81 83\n0 2 5 8 12 17 19 21 24 28 29 32 33 36 37 39 40 43 44 46 49 52 55 57 58 60 62 64 66 69 76 78 79 80 81 82", "output": "YES" }, { "input": "37 46\n0 1 3 6 7 8 9 10 12 13 14 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 39 40 41 42 43 44\n0 3 4 5 6 7 9 10 11 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 36 37 38 39 40 41 43 44", "output": "YES" }, { "input": "37 97\n0 5 10 11 12 15 16 18 19 25 28 29 34 35 36 37 38 40 46 47 48 49 55 58 60 61 62 64 65 70 76 77 80 82 88 94 96\n1 7 13 15 16 21 26 27 28 31 32 34 35 41 44 45 50 51 52 53 54 56 62 63 64 65 71 74 76 77 78 80 81 86 92 93 96", "output": "YES" }, { "input": "38 58\n1 2 3 4 5 8 9 11 12 13 15 16 17 22 23 24 25 26 27 29 30 31 32 33 34 36 37 40 41 43 46 47 48 52 53 55 56 57\n1 2 3 5 6 7 8 9 12 13 15 16 17 19 20 21 26 27 28 29 30 31 33 34 35 36 37 38 40 41 44 45 47 50 51 52 56 57", "output": "YES" }, { "input": "38 92\n1 2 3 5 6 7 12 14 15 16 17 18 20 22 29 31 33 34 38 41 43 49 54 55 57 58 61 63 66 67 69 73 75 76 82 85 88 90\n1 3 4 10 13 16 18 21 22 23 25 26 27 32 34 35 36 37 38 40 42 49 51 53 54 58 61 63 69 74 75 77 78 81 83 86 87 89", "output": "YES" }, { "input": "39 59\n0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 19 24 25 28 29 31 32 33 35 37 38 40 41 42 43 45 46 47 49 50 53 55 56\n0 1 3 4 5 6 8 9 10 12 13 16 18 19 22 23 24 25 27 28 29 30 31 32 33 34 35 37 38 39 41 46 47 50 51 53 54 55 57", "output": "YES" }, { "input": "39 67\n1 3 5 7 8 16 18 20 21 23 24 25 27 28 29 31 32 34 36 38 40 43 44 46 47 48 49 50 52 53 54 55 58 59 61 62 63 64 66\n0 1 2 4 6 8 10 12 13 21 23 25 26 28 29 30 32 33 34 36 37 39 41 43 45 48 49 51 52 53 54 55 57 58 59 60 63 64 66", "output": "YES" }, { "input": "40 63\n0 2 3 4 5 6 9 10 12 15 18 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62", "output": "YES" }, { "input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 89 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94", "output": "YES" }, { "input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 26 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65", "output": "YES" }, { "input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 29 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71", "output": "YES" }, { "input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47", "output": "YES" }, { "input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 21 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80", "output": "YES" }, { "input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 35 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54", "output": "YES" }, { "input": "43 81\n2 3 4 5 6 7 9 10 12 13 18 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79", "output": "YES" }, { "input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 39 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52", "output": "YES" }, { "input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 85 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90", "output": "YES" }, { "input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 43 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46", "output": "YES" }, { "input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 41 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70", "output": "YES" }, { "input": "46 46\n0 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\n0 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", "output": "YES" }, { "input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 87 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89", "output": "YES" }, { "input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 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\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 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", "output": "YES" }, { "input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 45 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93", "output": "YES" }, { "input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 22 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64", "output": "YES" }, { "input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 18 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89", "output": "YES" }, { "input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 19 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59", "output": "YES" }, { "input": "49 97\n0 1 2 3 6 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96", "output": "YES" }, { "input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57", "output": "YES" }, { "input": "50 97\n1 2 3 4 7 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96", "output": "YES" }, { "input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 88 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94", "output": "NO" }, { "input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 25 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65", "output": "NO" }, { "input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 28 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71", "output": "NO" }, { "input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47", "output": "NO" }, { "input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 20 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80", "output": "NO" }, { "input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 34 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54", "output": "NO" }, { "input": "43 81\n2 3 4 5 6 7 9 10 12 13 17 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79", "output": "NO" }, { "input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 38 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52", "output": "NO" }, { "input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 84 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90", "output": "NO" }, { "input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46", "output": "YES" }, { "input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 40 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70", "output": "NO" }, { "input": "46 46\n0 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\n0 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", "output": "YES" }, { "input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 86 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89", "output": "NO" }, { "input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 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\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 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", "output": "YES" }, { "input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 44 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93", "output": "NO" }, { "input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 21 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64", "output": "NO" }, { "input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 17 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89", "output": "NO" }, { "input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 18 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59", "output": "NO" }, { "input": "49 97\n0 1 2 3 5 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96", "output": "NO" }, { "input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57", "output": "NO" }, { "input": "5 10\n0 1 3 5 7\n0 1 2 4 7", "output": "NO" }, { "input": "5 8\n0 2 4 6 7\n0 2 3 5 7", "output": "NO" } ]
1,660,597,888
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
def main(): n, l = map(int, fin().split()) *a, = map(int, fin().split()) *b, = map(int, fin().split()) const = abs(a[0]-b[0]) for i in range(1, n): if abs(a[i]-b[i]) != const: return fout("NO") fout("YES") # FastIO from sys import stdin, stdout try: input, output = open("task.in", "r"), open("task.out", "w") except: input, output = stdin, stdout def fin(): return input.readline().strip("\r\n") def fout(s): return output.write(str(s)+"\n") if __name__ == "__main__": t = 1 or int(fin()) for i in range(t): main()
Title: Dasha and friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the *n* barriers. Thus, each of them wrote *n* integers in the ascending order, each of them was between 0 and *L*<=-<=1, inclusively. There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above. Input Specification: The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length. The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to *L*<=-<=1 inclusively. The second line contains *n* distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to *L*<=-<=1 inclusively. Output Specification: Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). Demo Input: ['3 8\n2 4 6\n1 5 7\n', '4 9\n2 3 5 8\n0 1 3 6\n', '2 4\n1 3\n1 2\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: The first test is analyzed in the statement.
```python def main(): n, l = map(int, fin().split()) *a, = map(int, fin().split()) *b, = map(int, fin().split()) const = abs(a[0]-b[0]) for i in range(1, n): if abs(a[i]-b[i]) != const: return fout("NO") fout("YES") # FastIO from sys import stdin, stdout try: input, output = open("task.in", "r"), open("task.out", "w") except: input, output = stdin, stdout def fin(): return input.readline().strip("\r\n") def fout(s): return output.write(str(s)+"\n") if __name__ == "__main__": t = 1 or int(fin()) for i in range(t): main() ```
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,696,304,767
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
b1,b2,b3 = map(int,input().split()) print( (b3*(b3+1)//2)*b1 - b2)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python b1,b2,b3 = map(int,input().split()) print( (b3*(b3+1)//2)*b1 - b2) ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,449,519,931
2,147,483,647
Python 3
OK
TESTS
51
184
1,126,400
from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# n=RI()[0] ans="" while n%7!=0: n-=4 ans+='4' print(ans+(n//7)*'7' if n>=0 else -1)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# n=RI()[0] ans="" while n%7!=0: n-=4 ans+='4' print(ans+(n//7)*'7' if n>=0 else -1) ```
3.951902
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color.
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n#.#.\n#.#.\n.#.#", "output": "NO" }, { "input": "#.#.\n#.#.\n#.#.\n#.#.", "output": "NO" }, { "input": ".#.#\n.#.#\n.#.#\n.#.#", "output": "NO" }, { "input": "#..#\n.##.\n####\n####", "output": "YES" }, { "input": "#.#.\n.###\n#.#.\n.###", "output": "YES" }, { "input": "#..#\n.##.\n.##.\n#..#", "output": "YES" }, { "input": ".##.\n.#..\n##.#\n#..#", "output": "YES" }, { "input": ".##.\n##..\n#..#\n..##", "output": "YES" }, { "input": "##..\n##..\n..##\n..##", "output": "YES" }, { "input": ".#..\n###.\n.#.#\n..#.", "output": "YES" }, { "input": "###.\n###.\n...#\n...#", "output": "YES" }, { "input": "#.##\n##.#\n#.##\n##.#", "output": "YES" }, { "input": ".#.#\n#.#.\n.#.#\n#.##", "output": "YES" }, { "input": "##..\n..##\n##..\n...#", "output": "YES" }, { "input": ".#..\n..##\n##..\n..##", "output": "YES" }, { "input": "##..\n...#\n##..\n...#", "output": "YES" }, { "input": ".#..\n..#.\n.#..\n..#.", "output": "YES" }, { "input": "....\n....\n....\n.#.#", "output": "YES" }, { "input": "....\n....\n....\n...#", "output": "YES" } ]
1,675,616,771
2,147,483,647
Python 3
OK
TESTS
30
46
0
x=[input() for i in range(4)] m=0 for i in range(3): for j in range(3): if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2: m=1 break if m: break if m: print("YES") else: print("NO")
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. Input Specification: Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. Output Specification: Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. Demo Input: ['####\n.#..\n####\n....\n', '####\n....\n####\n....\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
```python x=[input() for i in range(4)] m=0 for i in range(3): for j in range(3): if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2: m=1 break if m: break if m: print("YES") else: print("NO") ```
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B.
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "A>C\nA>B\nB<C", "output": "BCA" }, { "input": "C<B\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nA>B\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nA<C", "output": "ABC" }, { "input": "C<B\nB<A\nC>A", "output": "Impossible" }, { "input": "B<C\nC<A\nA>B", "output": "BCA" }, { "input": "A>B\nC<B\nC<A", "output": "CBA" }, { "input": "B>A\nC>B\nA>C", "output": "Impossible" }, { "input": "B<A\nC>B\nC>A", "output": "BAC" }, { "input": "A<B\nC>B\nA<C", "output": "ABC" }, { "input": "A<B\nC<A\nB<C", "output": "Impossible" }, { "input": "A>C\nC<B\nB>A", "output": "CAB" }, { "input": "C>A\nA<B\nB>C", "output": "ACB" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "B>C\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA<B\nB>C", "output": "ACB" }, { "input": "B>A\nA>C\nB>C", "output": "CAB" }, { "input": "B<A\nA<C\nC<B", "output": "Impossible" }, { "input": "A<C\nB>C\nA>B", "output": "Impossible" }, { "input": "B>A\nC<A\nC>B", "output": "Impossible" }, { "input": "A>C\nC>B\nB<A", "output": "BCA" }, { "input": "B<C\nB<A\nA>C", "output": "BCA" }, { "input": "A>B\nC>B\nA<C", "output": "BAC" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA>B\nB>C", "output": "Impossible" }, { "input": "B>A\nB>C\nA<C", "output": "ACB" }, { "input": "B>C\nC<A\nB<A", "output": "CBA" }, { "input": "C>A\nB>A\nB>C", "output": "ACB" }, { "input": "B<A\nB>C\nA<C", "output": "Impossible" }, { "input": "B<C\nA<B\nC>A", "output": "ABC" }, { "input": "C<B\nB>A\nA>C", "output": "CAB" }, { "input": "A>B\nC>A\nB<C", "output": "BAC" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "B>C\nC>A\nA>B", "output": "Impossible" }, { "input": "B<A\nB>C\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nC>A", "output": "ABC" }, { "input": "A>C\nA>B\nB>C", "output": "CBA" }, { "input": "B<C\nA>B\nA<C", "output": "BAC" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "C>B\nA<B\nC<A", "output": "Impossible" }, { "input": "A<C\nC<B\nA>B", "output": "Impossible" }, { "input": "B>C\nA<B\nA<C", "output": "ACB" }, { "input": "C>A\nA<B\nC>B", "output": "ABC" } ]
1,623,849,678
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
class Graph: def __init__(self,mat,unconn=0): vnum=len(mat) for x in mat: if len(x)!=vnum: raise ValueError("Argument for class 'Graph' is bad.") self._mat=[mat[i][:] for i in range(vnum)] self._unconn=unconn self._vnum=vnum def _out_edges(row,unconn): edges=[] for i in range(len(row)): if row[i]!=unconn: edges.append((i,row[i])) return edges
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. Input Specification: The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B. Output Specification: It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. Demo Input: ['A&gt;B\nC&lt;B\nA&gt;C\n', 'A&lt;B\nB&gt;C\nC&gt;A\n'] Demo Output: ['CBA', 'ACB'] Note: none
```python class Graph: def __init__(self,mat,unconn=0): vnum=len(mat) for x in mat: if len(x)!=vnum: raise ValueError("Argument for class 'Graph' is bad.") self._mat=[mat[i][:] for i in range(vnum)] self._unconn=unconn self._vnum=vnum def _out_edges(row,unconn): edges=[] for i in range(len(row)): if row[i]!=unconn: edges.append((i,row[i])) return edges ```
0
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
1,508,644,617
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
5,529,600
n = 0 k = 0 totalk = 0 n,k = input().split() n = int(n) k = int(k) totalk = k + 1 dip = 0 cert = 0 left = 0 half = int(n/2) for i in range(half,0,-1): if i % totalk == 0: dip = i/totalk; cert= i - dip break; left = n -(dip + cert) dip = int(dip) cert = int(cert) left = int(left) print(dip,cert,left)
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input Specification: The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. Output Specification: Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Demo Input: ['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n'] Demo Output: ['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n'] Note: none
```python n = 0 k = 0 totalk = 0 n,k = input().split() n = int(n) k = int(k) totalk = k + 1 dip = 0 cert = 0 left = 0 half = int(n/2) for i in range(half,0,-1): if i % totalk == 0: dip = i/totalk; cert= i - dip break; left = n -(dip + cert) dip = int(dip) cert = int(cert) left = int(left) print(dip,cert,left) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,690,042,421
2,147,483,647
Python 3
OK
TESTS
20
46
0
x, y, z = [int(x) for x in input().split()] resx = 0 resy = 0 if x % z == 0: resx += x/z else: resx += int(x/z) +1 if y % z == 0: resy += y/z else: resy += int(y/z) +1 print(int(resx * resy))
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 x, y, z = [int(x) for x in input().split()] resx = 0 resy = 0 if x % z == 0: resx += x/z else: resx += int(x/z) +1 if y % z == 0: resy += y/z else: resy += int(y/z) +1 print(int(resx * resy)) ```
3.977
710
C
Magic Odd Square
PROGRAMMING
1,500
[ "constructive algorithms", "math" ]
null
null
Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd.
[ "1\n", "3\n" ]
[ "1\n", "2 1 4\n3 5 7\n6 9 8\n" ]
none
0
[ { "input": "1", "output": "1" }, { "input": "3", "output": "2 1 4\n3 5 7\n6 9 8" }, { "input": "5", "output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24" }, { "input": "7", "output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 21 23 25 27 29 31\n26 33 35 37 39 41 28\n30 32 43 45 47 34 36\n38 40 42 49 44 46 48" }, { "input": "9", "output": "2 4 6 8 1 10 12 14 16\n18 20 22 3 5 7 24 26 28\n30 32 9 11 13 15 17 34 36\n38 19 21 23 25 27 29 31 40\n33 35 37 39 41 43 45 47 49\n42 51 53 55 57 59 61 63 44\n46 48 65 67 69 71 73 50 52\n54 56 58 75 77 79 60 62 64\n66 68 70 72 81 74 76 78 80" }, { "input": "11", "output": "2 4 6 8 10 1 12 14 16 18 20\n22 24 26 28 3 5 7 30 32 34 36\n38 40 42 9 11 13 15 17 44 46 48\n50 52 19 21 23 25 27 29 31 54 56\n58 33 35 37 39 41 43 45 47 49 60\n51 53 55 57 59 61 63 65 67 69 71\n62 73 75 77 79 81 83 85 87 89 64\n66 68 91 93 95 97 99 101 103 70 72\n74 76 78 105 107 109 111 113 80 82 84\n86 88 90 92 115 117 119 94 96 98 100\n102 104 106 108 110 121 112 114 116 118 120" }, { "input": "13", "output": "2 4 6 8 10 12 1 14 16 18 20 22 24\n26 28 30 32 34 3 5 7 36 38 40 42 44\n46 48 50 52 9 11 13 15 17 54 56 58 60\n62 64 66 19 21 23 25 27 29 31 68 70 72\n74 76 33 35 37 39 41 43 45 47 49 78 80\n82 51 53 55 57 59 61 63 65 67 69 71 84\n73 75 77 79 81 83 85 87 89 91 93 95 97\n86 99 101 103 105 107 109 111 113 115 117 119 88\n90 92 121 123 125 127 129 131 133 135 137 94 96\n98 100 102 139 141 143 145 147 149 151 104 106 108\n110 112 114 116 153 155 157 159 161 118 120 122 124\n126 128 130 132 134 163 165 167 136 ..." }, { "input": "15", "output": "2 4 6 8 10 12 14 1 16 18 20 22 24 26 28\n30 32 34 36 38 40 3 5 7 42 44 46 48 50 52\n54 56 58 60 62 9 11 13 15 17 64 66 68 70 72\n74 76 78 80 19 21 23 25 27 29 31 82 84 86 88\n90 92 94 33 35 37 39 41 43 45 47 49 96 98 100\n102 104 51 53 55 57 59 61 63 65 67 69 71 106 108\n110 73 75 77 79 81 83 85 87 89 91 93 95 97 112\n99 101 103 105 107 109 111 113 115 117 119 121 123 125 127\n114 129 131 133 135 137 139 141 143 145 147 149 151 153 116\n118 120 155 157 159 161 163 165 167 169 171 173 175 122 124\n126 128 1..." }, { "input": "17", "output": "2 4 6 8 10 12 14 16 1 18 20 22 24 26 28 30 32\n34 36 38 40 42 44 46 3 5 7 48 50 52 54 56 58 60\n62 64 66 68 70 72 9 11 13 15 17 74 76 78 80 82 84\n86 88 90 92 94 19 21 23 25 27 29 31 96 98 100 102 104\n106 108 110 112 33 35 37 39 41 43 45 47 49 114 116 118 120\n122 124 126 51 53 55 57 59 61 63 65 67 69 71 128 130 132\n134 136 73 75 77 79 81 83 85 87 89 91 93 95 97 138 140\n142 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 144\n129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161..." }, { "input": "19", "output": "2 4 6 8 10 12 14 16 18 1 20 22 24 26 28 30 32 34 36\n38 40 42 44 46 48 50 52 3 5 7 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 9 11 13 15 17 84 86 88 90 92 94 96\n98 100 102 104 106 108 19 21 23 25 27 29 31 110 112 114 116 118 120\n122 124 126 128 130 33 35 37 39 41 43 45 47 49 132 134 136 138 140\n142 144 146 148 51 53 55 57 59 61 63 65 67 69 71 150 152 154 156\n158 160 162 73 75 77 79 81 83 85 87 89 91 93 95 97 164 166 168\n170 172 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 174 176\n178..." }, { "input": "21", "output": "2 4 6 8 10 12 14 16 18 20 1 22 24 26 28 30 32 34 36 38 40\n42 44 46 48 50 52 54 56 58 3 5 7 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 9 11 13 15 17 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 19 21 23 25 27 29 31 124 126 128 130 132 134 136\n138 140 142 144 146 148 33 35 37 39 41 43 45 47 49 150 152 154 156 158 160\n162 164 166 168 170 51 53 55 57 59 61 63 65 67 69 71 172 174 176 178 180\n182 184 186 188 73 75 77 79 81 83 85 87 89 91 93 95 97 190 192 194 196\n198 200 202 99 101 103 ..." }, { "input": "23", "output": "2 4 6 8 10 12 14 16 18 20 22 1 24 26 28 30 32 34 36 38 40 42 44\n46 48 50 52 54 56 58 60 62 64 3 5 7 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 9 11 13 15 17 104 106 108 110 112 114 116 118 120\n122 124 126 128 130 132 134 136 19 21 23 25 27 29 31 138 140 142 144 146 148 150 152\n154 156 158 160 162 164 166 33 35 37 39 41 43 45 47 49 168 170 172 174 176 178 180\n182 184 186 188 190 192 51 53 55 57 59 61 63 65 67 69 71 194 196 198 200 202 204\n206 208 210 212 214 73 75 77 79 81 83 85 87 89 ..." }, { "input": "25", "output": "2 4 6 8 10 12 14 16 18 20 22 24 1 26 28 30 32 34 36 38 40 42 44 46 48\n50 52 54 56 58 60 62 64 66 68 70 3 5 7 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 9 11 13 15 17 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 19 21 23 25 27 29 31 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 33 35 37 39 41 43 45 47 49 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 51 53 55 57 59 61 63 65 67 69 71 216 218 220 222 224 226 228\n..." }, { "input": "27", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 1 28 30 32 34 36 38 40 42 44 46 48 50 52\n54 56 58 60 62 64 66 68 70 72 74 76 3 5 7 78 80 82 84 86 88 90 92 94 96 98 100\n102 104 106 108 110 112 114 116 118 120 122 9 11 13 15 17 124 126 128 130 132 134 136 138 140 142 144\n146 148 150 152 154 156 158 160 162 164 19 21 23 25 27 29 31 166 168 170 172 174 176 178 180 182 184\n186 188 190 192 194 196 198 200 202 33 35 37 39 41 43 45 47 49 204 206 208 210 212 214 216 218 220\n222 224 226 228 230 232 234 236 51 53 55 57 59 61..." }, { "input": "29", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 1 30 32 34 36 38 40 42 44 46 48 50 52 54 56\n58 60 62 64 66 68 70 72 74 76 78 80 82 3 5 7 84 86 88 90 92 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 124 126 128 130 132 9 11 13 15 17 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 19 21 23 25 27 29 31 180 182 184 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 216 218 220 33 35 37 39 41 43 45 47 49 222 224 226 228 230 232 234 236 238 240\n242 244 2..." }, { "input": "31", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 1 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60\n62 64 66 68 70 72 74 76 78 80 82 84 86 88 3 5 7 90 92 94 96 98 100 102 104 106 108 110 112 114 116\n118 120 122 124 126 128 130 132 134 136 138 140 142 9 11 13 15 17 144 146 148 150 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 186 188 190 192 19 21 23 25 27 29 31 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 33 35 37 39 41 43 45 47 49 240 242 244 24..." }, { "input": "33", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 1 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64\n66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 3 5 7 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124\n126 128 130 132 134 136 138 140 142 144 146 148 150 152 9 11 13 15 17 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 19 21 23 25 27 29 31 208 210 212 214 216 218 220 222 224 226 228 230 232\n234 236 238 240 242 244 246 248 250 252 254 256 33 35..." }, { "input": "35", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 1 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 3 5 7 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 9 11 13 15 17 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192\n194 196 198 200 202 204 206 208 210 212 214 216 218 220 19 21 23 25 27 29 31 222 224 226 228 230 232 234 236 238 240 242 244 246 248\n250 252 254 256 258 2..." }, { "input": "37", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72\n74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 3 5 7 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140\n142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 9 11 13 15 17 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204\n206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 19 21 23 25 27 29 31 236 238 240 242 244 246 248 250 252 254 256 258 26..." }, { "input": "39", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 3 5 7 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148\n150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 9 11 13 15 17 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 19 21 23 25 27 29 31 250 252 254 256 258 26..." }, { "input": "41", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 1 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80\n82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 3 5 7 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 9 11 13 15 17 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228\n230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 19 21 23 25 27 ..." }, { "input": "43", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 1 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 3 5 7 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164\n166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 9 11 13 15 17 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240\n242 244 246 248 250 252 254 256 258 260 262 264 266 268 270..." }, { "input": "45", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 1 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88\n90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 3 5 7 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172\n174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 9 11 13 15 17 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252\n254 256 258 260 262 264 266 268 270..." }, { "input": "47", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 1 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 3 5 7 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 9 11 13 15 17 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264\n266 268 270..." }, { "input": "49", "output": "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 1 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96\n98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 3 5 7 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188\n190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 9 11 13 15 17 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 ..." } ]
1,624,863,054
2,147,483,647
PyPy 3
OK
TESTS
25
124
2,764,800
n=int(input()) mxc=((n*n+1)//2-(2*n-1))//4 m=[] for i in range(n): l=[0]*n m.append(l) odd=1 i=n//2 j=0 while(j<n): m[i][j]=odd j+=1 odd+=2 j=0 while(j<n): if i==j: j+=1 continue m[j][i]=odd j+=1 odd+=2 i=0 j=0 c=0 while(c<mxc): c+=1 m[i][j]=odd odd+=2 m[i][n-1-j]=odd odd+=2 m[n-1-i][j]=odd odd+=2 m[n-i-1][n-1-j]=odd odd+=2 j+=1 if j==n//2: j=0 i+=1 even=2 for i in range(n): for j in range(n): if m[i][j]==0: m[i][j]=even even+=2 for i in range(n): for j in range(n): print(m[i][j],end=" ") print()
Title: Magic Odd Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd. Input Specification: The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49). Output Specification: Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd. Demo Input: ['1\n', '3\n'] Demo Output: ['1\n', '2 1 4\n3 5 7\n6 9 8\n'] Note: none
```python n=int(input()) mxc=((n*n+1)//2-(2*n-1))//4 m=[] for i in range(n): l=[0]*n m.append(l) odd=1 i=n//2 j=0 while(j<n): m[i][j]=odd j+=1 odd+=2 j=0 while(j<n): if i==j: j+=1 continue m[j][i]=odd j+=1 odd+=2 i=0 j=0 c=0 while(c<mxc): c+=1 m[i][j]=odd odd+=2 m[i][n-1-j]=odd odd+=2 m[n-1-i][j]=odd odd+=2 m[n-i-1][n-1-j]=odd odd+=2 j+=1 if j==n//2: j=0 i+=1 even=2 for i in range(n): for j in range(n): if m[i][j]==0: m[i][j]=even even+=2 for i in range(n): for j in range(n): print(m[i][j],end=" ") print() ```
3
220
A
Little Elephant and Problem
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
[ "2\n1 2\n", "3\n3 2 1\n", "4\n4 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
500
[ { "input": "2\n1 2", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "4\n4 3 2 1", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "2\n2 1", "output": "YES" }, { "input": "9\n7 7 8 8 10 10 10 10 1000000000", "output": "YES" }, { "input": "10\n1 2 9 4 5 6 7 8 3 10", "output": "YES" }, { "input": "4\n2 2 2 1", "output": "YES" }, { "input": "10\n1 2 4 4 4 5 5 7 7 10", "output": "YES" }, { "input": "10\n4 5 11 12 13 14 16 16 16 18", "output": "YES" }, { "input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321", "output": "YES" }, { "input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644", "output": "YES" }, { "input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5", "output": "NO" }, { "input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472", "output": "NO" }, { "input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503", "output": "NO" }, { "input": "4\n5 12 12 6", "output": "YES" }, { "input": "5\n1 3 3 3 2", "output": "YES" }, { "input": "4\n2 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "YES" }, { "input": "4\n1000000000 1 1000000000 1", "output": "YES" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 1", "output": "YES" }, { "input": "6\n1 2 3 4 5 3", "output": "NO" }, { "input": "9\n3 3 3 2 2 2 1 1 1", "output": "NO" }, { "input": "4\n4 1 2 3", "output": "NO" }, { "input": "6\n3 4 5 6 7 2", "output": "NO" }, { "input": "4\n4 2 1 3", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "4\n3 2 1 1", "output": "NO" }, { "input": "4\n4 5 1 1", "output": "NO" }, { "input": "6\n1 6 2 4 3 5", "output": "NO" }, { "input": "5\n1 4 5 2 3", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n1 4 3 2 1", "output": "NO" }, { "input": "5\n1 4 2 2 3", "output": "NO" }, { "input": "6\n1 2 3 1 2 3", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "5\n5 1 2 3 4", "output": "NO" }, { "input": "5\n3 3 3 2 2", "output": "NO" }, { "input": "5\n100 5 6 10 7", "output": "NO" }, { "input": "3\n2 3 1", "output": "NO" }, { "input": "5\n4 4 1 1 1", "output": "NO" }, { "input": "5\n1 2 5 3 4", "output": "NO" }, { "input": "4\n3 4 1 2", "output": "NO" }, { "input": "4\n2 4 1 5", "output": "NO" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "5\n1 5 4 4 4", "output": "YES" }, { "input": "7\n3 2 1 2 3 5 4", "output": "NO" }, { "input": "5\n1 1 3 2 2", "output": "YES" }, { "input": "9\n1 8 7 7 7 7 7 8 3", "output": "YES" }, { "input": "5\n1 3 2 3 3", "output": "YES" }, { "input": "10\n4 4 4 4 10 4 4 4 4 4", "output": "YES" }, { "input": "8\n3 6 6 6 6 6 4 9", "output": "YES" }, { "input": "4\n4 4 3 3", "output": "NO" }, { "input": "4\n3 2 2 4", "output": "YES" }, { "input": "5\n2 2 1 3 3", "output": "YES" }, { "input": "5\n1 2 7 3 5", "output": "NO" }, { "input": "5\n2 3 4 5 1", "output": "NO" }, { "input": "6\n1 4 3 6 2 5", "output": "NO" }, { "input": "5\n3 3 1 5 4", "output": "NO" }, { "input": "4\n1 2 1 2", "output": "YES" }, { "input": "6\n4 5 3 4 2 6", "output": "NO" }, { "input": "11\n1 2 3 4 5 1 2 3 4 5 1", "output": "NO" }, { "input": "6\n6 1 2 3 4 5", "output": "NO" }, { "input": "5\n4 1 1 1 1", "output": "YES" }, { "input": "9\n1 2 3 5 4 6 7 8 9", "output": "YES" }, { "input": "6\n6 1 2 3 4 2", "output": "NO" }, { "input": "6\n2 2 2 2 3 2", "output": "YES" }, { "input": "3\n2 1 1", "output": "YES" }, { "input": "5\n1 2 1 1 2", "output": "YES" }, { "input": "5\n1 2 2 1 2", "output": "YES" }, { "input": "8\n5 5 5 5 5 5 1 1", "output": "NO" } ]
1,689,168,459
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
import sys sys.setrecursionlimit(2000000) def clc(): n = int(input()) arr = list(map(int,input().split())) def check(arr): maxi = arr[0] maxind = 0 for i in range(1,len(arr)): if arr[i]>=maxi: maxind = i maxi = max(maxi,arr[i]) else: return False return True flag = True maxi = arr[0] maxind = 0 for i in range(1,len(arr)): if arr[i]>=maxi: maxind = i maxi = max(maxi,arr[i]) else: flag = False break if flag: print("YES") else: j = i mini = float("inf") miniindex = -1 while j<len(arr): if mini>arr[j]: mini = min(mini,arr[j]) minindex = j j+=1 arr[miniindex],arr[maxind] = arr[maxind],arr[miniindex] print ("YES" if check(arr) else "NO") return True cc = clc() if not cc : print(0)
Title: Little Elephant and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers. Output Specification: In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. Demo Input: ['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
```python import sys sys.setrecursionlimit(2000000) def clc(): n = int(input()) arr = list(map(int,input().split())) def check(arr): maxi = arr[0] maxind = 0 for i in range(1,len(arr)): if arr[i]>=maxi: maxind = i maxi = max(maxi,arr[i]) else: return False return True flag = True maxi = arr[0] maxind = 0 for i in range(1,len(arr)): if arr[i]>=maxi: maxind = i maxi = max(maxi,arr[i]) else: flag = False break if flag: print("YES") else: j = i mini = float("inf") miniindex = -1 while j<len(arr): if mini>arr[j]: mini = min(mini,arr[j]) minindex = j j+=1 arr[miniindex],arr[maxind] = arr[maxind],arr[miniindex] print ("YES" if check(arr) else "NO") return True cc = clc() if not cc : print(0) ```
0
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3 d g\n5 5 h h\n2 8 g d\n8 9 a f\n5 9 c e\n1 7 f d\n1 6 e e\n5 7 c a\n8 9 b b\n2 6 e b\n6 6 g h\n1 2 b b\n1 5 a f\n5 8 f h\n1 5 e g\n3 9 f h\n6 8 g a\n4 6 h g\n1 5 f a\n5 6 a c\n4 8 e d\n1 4 d g\n7 8 b f\n5 6 h b\n3 9 c e\n1 9 b a", "output": "aahaddddh" }, { "input": "28 45\ndcbbaddjhbeefjadjchgkhgggfha\n10 25 c a\n13 19 a f\n12 28 e d\n12 27 e a\n9 20 b e\n7 17 g d\n22 26 j j\n8 16 c g\n14 16 a d\n3 10 f c\n10 26 d b\n8 17 i e\n10 19 d i\n6 21 c j\n7 22 b k\n17 19 a i\n4 18 j k\n8 25 a g\n10 27 j e\n9 18 g d\n16 23 h a\n17 26 k e\n8 16 h f\n1 15 d f\n22 28 k k\n11 20 c k\n6 11 b h\n17 17 e i\n15 22 g h\n8 18 c f\n4 16 e a\n8 25 b c\n6 24 d g\n5 9 f j\n12 19 i h\n4 25 e f\n15 25 c j\n15 27 e e\n11 20 b f\n19 27 e k\n2 21 d a\n9 27 k e\n14 24 b a\n3 6 i g\n2 26 k f", "output": "fcbbajjfjaaefefehfahfagggfha" }, { "input": "87 5\nnfinedeojadjmgafnaogekfjkjfncnliagfchjfcmellgigjjcaaoeakdolchjcecljdeblmheimkibkgdkcdml\n47 56 a k\n51 81 o d\n5 11 j h\n48 62 j d\n16 30 k m", "output": "nfinedeohadjmgafnaogemfjmjfncnliagfchjfcmellgigddckkdekkddlchdcecljdeblmheimkibkgdkcdml" }, { "input": "5 16\nacfbb\n1 2 e f\n2 5 a f\n2 3 b e\n4 4 f a\n2 3 f a\n1 2 b e\n4 5 c d\n2 4 e c\n1 4 e a\n1 3 d c\n3 5 e b\n3 5 e b\n2 2 e d\n1 3 e c\n3 3 a e\n1 5 a a", "output": "acebb" }, { "input": "94 13\nbcaaaaaaccacddcdaacbdaabbcbaddbccbccbbbddbadddcccbddadddaadbdababadaacdcdbcdadabdcdcbcbcbcbbcd\n52 77 d d\n21 92 d b\n45 48 c b\n20 25 d a\n57 88 d b\n3 91 b d\n64 73 a a\n5 83 b d\n2 69 c c\n28 89 a b\n49 67 c b\n41 62 a c\n49 87 b c", "output": "bcaaaaaaccacddcdaacddaaddcdbdddccdccddddddbdddddcdddcdddccdddcdcdcdcccdcddcdcdcddcdcdcdcdcdbcd" }, { "input": "67 39\nacbcbccccbabaabcabcaaaaaaccbcbbcbaaaacbbcccbcbabbcacccbbabbabbabaac\n4 36 a b\n25 38 a a\n3 44 b c\n35 57 b a\n4 8 a c\n20 67 c a\n30 66 b b\n27 40 a a\n2 56 a b\n10 47 c a\n22 65 c b\n29 42 a b\n1 46 c b\n57 64 b c\n20 29 b a\n14 51 c a\n12 55 b b\n20 20 a c\n2 57 c a\n22 60 c b\n16 51 c c\n31 64 a c\n17 30 c a\n23 36 c c\n28 67 a c\n37 40 a c\n37 50 b c\n29 48 c b\n2 34 b c\n21 53 b a\n26 63 a c\n23 28 c a\n51 56 c b\n32 61 b b\n64 67 b b\n21 67 b c\n8 53 c c\n40 62 b b\n32 38 c c", "output": "accccccccaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccc" }, { "input": "53 33\nhhcbhfafeececbhadfbdbehdfacfchbhdbfebdfeghebfcgdhehfh\n27 41 h g\n18 35 c b\n15 46 h f\n48 53 e g\n30 41 b c\n12 30 b f\n10 37 e f\n18 43 a h\n10 52 d a\n22 48 c e\n40 53 f d\n7 12 b h\n12 51 f a\n3 53 g a\n19 41 d h\n22 29 b h\n2 30 a b\n26 28 e h\n25 35 f a\n19 31 h h\n44 44 d e\n19 22 e c\n29 44 d h\n25 33 d h\n3 53 g c\n18 44 h b\n19 28 f e\n3 22 g h\n8 17 c a\n37 51 d d\n3 28 e h\n27 50 h h\n27 46 f b", "output": "hhcbhfbfhfababbbbbbbbbbbbbbbbbeaaeaaeaaeabebdeaahahdh" }, { "input": "83 10\nfhbecdgadecabbbecedcgfdcefcbgechbedagecgdgfgdaahchdgchbeaedgafdefecdchceececfcdhcdh\n9 77 e e\n26 34 b g\n34 70 b a\n40 64 e g\n33 78 h f\n14 26 a a\n17 70 d g\n56 65 a c\n8 41 d c\n11 82 c b", "output": "fhbecdgacebabbbebegbgfgbefbggebhgegagebgggfggaafbfggbfagbgggbfggfebgbfbeebebfbdhbdh" }, { "input": "1 4\ne\n1 1 c e\n1 1 e a\n1 1 e c\n1 1 d a", "output": "a" }, { "input": "71 21\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n61 61 a a\n32 56 a a\n10 67 a a\n7 32 a a\n26 66 a a\n41 55 a a\n49 55 a a\n4 61 a a\n53 59 a a\n37 58 a a\n7 63 a a\n39 40 a a\n51 64 a a\n27 37 a a\n22 71 a a\n4 45 a a\n7 8 a a\n43 46 a a\n19 28 a a\n51 54 a a\n14 67 a a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "30 4\neaaddabedcbbcccddbabdecadcecce\n2 17 c a\n16 29 e e\n16 21 c b\n7 11 b c", "output": "eaaddacedacbaaaddbabdecadcecce" }, { "input": "48 30\naaaabaabbaababbbaabaabaababbabbbaabbbaabaaaaaaba\n3 45 a b\n1 14 a a\n15 32 a b\n37 47 a b\n9 35 a b\n36 39 b b\n6 26 a b\n36 44 a a\n28 44 b a\n29 31 b a\n20 39 a a\n45 45 a b\n21 32 b b\n7 43 a b\n14 48 a b\n14 33 a b\n39 44 a a\n9 36 b b\n4 23 b b\n9 42 b b\n41 41 b a\n30 47 a b\n8 42 b a\n14 38 b b\n3 15 a a\n35 47 b b\n14 34 a b\n38 43 a b\n1 35 b a\n16 28 b a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbb" }, { "input": "89 29\nbabaabaaabaaaababbbbbbbabbbaaaaababbaababababbababaaabbababaaabbbbaaabaaaaaabaaabaabbabab\n39 70 b b\n3 56 b b\n5 22 b a\n4 39 a b\n41 87 b b\n34 41 a a\n10 86 a b\n29 75 a b\n2 68 a a\n27 28 b b\n42 51 b a\n18 61 a a\n6 67 b a\n47 63 a a\n8 68 a b\n4 74 b a\n19 65 a b\n8 55 a b\n5 30 a a\n3 65 a b\n16 57 a b\n34 56 b a\n1 70 a b\n59 68 b b\n29 57 b a\n47 49 b b\n49 73 a a\n32 61 b b\n29 42 a a", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaabbbbbbbbbbbbbab" }, { "input": "59 14\nfbebcfabdefbaaedcefdeecababcabebadfbccaaedaebfdaefdbbcbebbe\n5 32 e f\n8 46 e e\n31 43 e f\n3 10 e a\n53 54 f d\n55 59 d a\n39 58 e b\n54 56 f a\n9 40 b e\n28 37 d a\n7 35 e b\n7 56 c f\n23 26 e a\n15 44 e d", "output": "fbabcfabdffbaafdfffdfffababfabfbaafdffaafdabbfdabfdbbfbbbbe" }, { "input": "7 17\nbbaabab\n3 5 a b\n5 7 a a\n5 5 a a\n4 4 b a\n7 7 a a\n5 6 b b\n1 3 b a\n6 7 a b\n4 6 a b\n6 6 a a\n2 4 b a\n1 7 b a\n4 6 b b\n2 5 b b\n2 5 a b\n1 4 a a\n4 4 b a", "output": "abbabaa" }, { "input": "100 1\ndebaaagbfdgehagadabfgheegggfghghgeeeabgceffeffggcbcegfgebbdhebhfagcgadcbdbabddbcadgbgdebdfehceehcaef\n13 99 f c", "output": "debaaagbfdgehagadabcgheegggcghghgeeeabgcecceccggcbcegcgebbdhebhcagcgadcbdbabddbcadgbgdebdcehceehcaef" }, { "input": "1 1\na\n1 1 a b", "output": "b" }, { "input": "100 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1 100 a b", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "2 2\naa\n1 2 a b\n1 2 b c", "output": "cc" }, { "input": "3 3\naaa\n1 3 a b\n1 3 b c\n1 3 c d", "output": "ddd" }, { "input": "2 2\naa\n2 2 a b\n1 1 a b", "output": "bb" } ]
1,612,370,813
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
0
n,m=(int(x) for x in input().split()) s=input() new_str=s for j in range(m): l,r,c1,c2=input().split() le=int(l) ri=int(r) new_str=new_str.replace(c1,c2,ri+1-le) print(new_str)
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space. Output Specification: Output string *s* after performing *m* operations described above. Demo Input: ['3 1\nioi\n1 1 i n\n', '5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n'] Demo Output: ['noi', 'gaaak'] Note: For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
```python n,m=(int(x) for x in input().split()) s=input() new_str=s for j in range(m): l,r,c1,c2=input().split() le=int(l) ri=int(r) new_str=new_str.replace(c1,c2,ri+1-le) print(new_str) ```
0
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,575,612,614
974
Python 3
OK
TESTS
22
421
1,024,000
s= input() ans = 0 for i in s: if int(i)%4 == 0: ans+=1 n = len(s) for i in range(0,n-1): if int(s[i:i+2])%4 == 0: ans+=i+1 print(ans)
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() ans = 0 for i in s: if int(i)%4 == 0: ans+=1 n = len(s) for i in range(0,n-1): if int(s[i:i+2])%4 == 0: ans+=i+1 print(ans) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,586,331,266
2,147,483,647
Python 3
OK
TESTS
32
93
0
s,v1,v2,t1,t2 = map(int,input().split()) player1 = (s*v1)+(t1*2) player2 = (s*v2)+(t2*2) if player1<player2: print('First') elif player2<player1: print('Second') else: print("Friendship")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s,v1,v2,t1,t2 = map(int,input().split()) player1 = (s*v1)+(t1*2) player2 = (s*v2)+(t2*2) if player1<player2: print('First') elif player2<player1: print('Second') else: print("Friendship") ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,659,417,676
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
512,000
from fractions import Fraction (yakko, wakko) = map(int, input().split(' ')) dot = ((6 - max(yakko, wakko) + 1) / 6) convert_to_fraction = Fraction(dot) numerator = convert_to_fraction.numerator denominator = convert_to_fraction.denominator print(str(numerator) + '/' + str(denominator))
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 (yakko, wakko) = map(int, input().split(' ')) dot = ((6 - max(yakko, wakko) + 1) / 6) convert_to_fraction = Fraction(dot) numerator = convert_to_fraction.numerator denominator = convert_to_fraction.denominator print(str(numerator) + '/' + str(denominator)) ```
0
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "5\n1 4 5 2 3", "output": "4" }, { "input": "6\n4 6 3 5 2 1", "output": "5" }, { "input": "7\n1 5 3 6 2 4 7", "output": "6" }, { "input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75", "output": "94" }, { "input": "8\n4 5 3 8 6 7 1 2", "output": "6" }, { "input": "9\n6 8 5 3 4 7 9 2 1", "output": "8" }, { "input": "10\n8 7 10 1 2 3 4 6 5 9", "output": "7" }, { "input": "11\n5 4 6 9 10 11 7 3 1 2 8", "output": "8" }, { "input": "12\n3 6 7 8 9 10 12 5 4 2 11 1", "output": "11" }, { "input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6", "output": "10" }, { "input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8", "output": "8" }, { "input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9", "output": "9" }, { "input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16", "output": "15" }, { "input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17", "output": "16" }, { "input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10", "output": "11" }, { "input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1", "output": "18" }, { "input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1", "output": "19" }, { "input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21", "output": "20" }, { "input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1", "output": "21" }, { "input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6", "output": "22" }, { "input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4", "output": "16" }, { "input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25", "output": "24" }, { "input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3", "output": "21" }, { "input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1", "output": "26" }, { "input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2", "output": "27" }, { "input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26", "output": "22" }, { "input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7", "output": "26" }, { "input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7", "output": "18" }, { "input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28", "output": "30" }, { "input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3", "output": "29" }, { "input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12", "output": "33" }, { "input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7", "output": "21" }, { "input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8", "output": "35" }, { "input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28", "output": "35" }, { "input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29", "output": "34" }, { "input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1", "output": "38" }, { "input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1", "output": "39" }, { "input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6", "output": "34" }, { "input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35", "output": "41" }, { "input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1", "output": "42" }, { "input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28", "output": "37" }, { "input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1", "output": "44" }, { "input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30", "output": "34" }, { "input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2", "output": "41" }, { "input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7", "output": "38" }, { "input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31", "output": "40" }, { "input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40", "output": "38" }, { "input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32", "output": "43" }, { "input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39", "output": "48" }, { "input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49", "output": "52" }, { "input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53", "output": "41" }, { "input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52", "output": "48" }, { "input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15", "output": "46" }, { "input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57", "output": "56" }, { "input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50", "output": "57" }, { "input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20", "output": "58" }, { "input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1", "output": "59" }, { "input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21", "output": "60" }, { "input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62", "output": "61" }, { "input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17", "output": "46" }, { "input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47", "output": "55" }, { "input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64", "output": "62" }, { "input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29", "output": "65" }, { "input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32", "output": "45" }, { "input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3", "output": "64" }, { "input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63", "output": "45" }, { "input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35", "output": "64" }, { "input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21", "output": "50" }, { "input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56", "output": "57" }, { "input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21", "output": "45" }, { "input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58", "output": "63" }, { "input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58", "output": "74" }, { "input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68", "output": "75" }, { "input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34", "output": "62" }, { "input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72", "output": "70" }, { "input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58", "output": "77" }, { "input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78", "output": "52" }, { "input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55", "output": "69" }, { "input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52", "output": "53" }, { "input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69", "output": "66" }, { "input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38", "output": "80" }, { "input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78", "output": "84" }, { "input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3", "output": "70" }, { "input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85", "output": "58" }, { "input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67", "output": "87" }, { "input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89", "output": "88" }, { "input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25", "output": "60" }, { "input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1", "output": "90" }, { "input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72", "output": "67" }, { "input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34", "output": "85" }, { "input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68", "output": "69" }, { "input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1", "output": "94" }, { "input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56", "output": "86" }, { "input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90", "output": "95" }, { "input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1", "output": "97" }, { "input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71", "output": "87" }, { "input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37", "output": "89" }, { "input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1", "output": "99" }, { "input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42", "output": "65" }, { "input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93", "output": "87" }, { "input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11", "output": "81" }, { "input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75", "output": "99" }, { "input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67", "output": "96" }, { "input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56", "output": "62" }, { "input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100", "output": "99" }, { "input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64", "output": "97" }, { "input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57", "output": "98" }, { "input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69", "output": "98" }, { "input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14", "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": "4\n1 2 3 4", "output": "3" }, { "input": "4\n1 2 4 3", "output": "3" }, { "input": "4\n1 3 2 4", "output": "3" }, { "input": "4\n1 3 4 2", "output": "3" }, { "input": "4\n1 4 2 3", "output": "3" }, { "input": "4\n1 4 3 2", "output": "3" }, { "input": "4\n2 1 3 4", "output": "3" }, { "input": "4\n2 1 4 3", "output": "2" }, { "input": "4\n2 4 1 3", "output": "2" }, { "input": "4\n2 4 3 1", "output": "3" }, { "input": "4\n3 1 2 4", "output": "3" }, { "input": "4\n3 1 4 2", "output": "2" }, { "input": "4\n3 2 1 4", "output": "3" }, { "input": "4\n3 2 4 1", "output": "3" }, { "input": "4\n3 4 1 2", "output": "2" }, { "input": "4\n3 4 2 1", "output": "3" }, { "input": "4\n4 1 2 3", "output": "3" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "4\n4 2 1 3", "output": "3" }, { "input": "4\n4 2 3 1", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "4\n4 3 2 1", "output": "3" }, { "input": "8\n2 5 6 4 8 3 1 7", "output": "6" }, { "input": "5\n2 3 1 5 4", "output": "3" }, { "input": "6\n2 5 3 6 4 1", "output": "5" }, { "input": "6\n5 4 2 6 1 3", "output": "4" }, { "input": "6\n4 2 3 1 6 5", "output": "4" }, { "input": "6\n5 4 2 1 6 3", "output": "4" }, { "input": "9\n7 2 3 4 5 6 1 9 8", "output": "7" }, { "input": "6\n3 2 1 4 6 5", "output": "4" }, { "input": "6\n2 3 4 1 6 5", "output": "4" }, { "input": "10\n5 2 3 4 1 6 7 8 10 9", "output": "8" }, { "input": "6\n5 2 3 1 6 4", "output": "4" }, { "input": "10\n2 9 3 4 1 10 5 6 7 8", "output": "5" }, { "input": "10\n2 3 4 5 6 7 1 8 10 9", "output": "8" }, { "input": "8\n2 3 4 5 1 6 8 7", "output": "6" }, { "input": "6\n2 1 3 4 5 6", "output": "5" } ]
1,652,544,762
2,147,483,647
PyPy 3
OK
TESTS
159
124
0
n=input() s=input().split() M=s.index(n) n=int(n) m=s.index('1') print(max(m,M,n-m-1,n-1-M))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. Output Specification: Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. Demo Input: ['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n'] Demo Output: ['3\n', '6\n', '5\n'] Note: In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
```python n=input() s=input().split() M=s.index(n) n=int(n) m=s.index('1') print(max(m,M,n-m-1,n-1-M)) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 1\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\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,671,007,780
2,147,483,647
Python 3
OK
TESTS
60
1,715
19,660,800
def binsearch(x): l, r = 0, n while l<r: m = (l+r)//2 if a[m] <= x: l = m+1 else: r = m return l n, m = map(int, input().split()) a = sorted([int(i) for i in input().split()]) b = [int(i) for i in input().split()] for i in range(m): print(binsearch(b[i]), end = ' ')
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python def binsearch(x): l, r = 0, n while l<r: m = (l+r)//2 if a[m] <= x: l = m+1 else: r = m return l n, m = map(int, input().split()) a = sorted([int(i) for i in input().split()]) b = [int(i) for i in input().split()] for i in range(m): print(binsearch(b[i]), end = ' ') ```
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them.
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
1,643,215,464
2,147,483,647
Python 3
OK
TESTS
34
124
0
n = int(input()) - 7 print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4])
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python n = int(input()) - 7 print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4]) ```
3.969
451
B
Sort the Array
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
[ "3\n3 2 1\n", "4\n2 1 3 4\n", "4\n3 1 2 4\n", "2\n1 2\n" ]
[ "yes\n1 3\n", "yes\n1 2\n", "no\n", "yes\n1 1\n" ]
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted. Sample 3. No segment can be reversed such that the array will be sorted. Definitions A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*]. If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become: *a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
1,000
[ { "input": "3\n3 2 1", "output": "yes\n1 3" }, { "input": "4\n2 1 3 4", "output": "yes\n1 2" }, { "input": "4\n3 1 2 4", "output": "no" }, { "input": "2\n1 2", "output": "yes\n1 1" }, { "input": "2\n58 4", "output": "yes\n1 2" }, { "input": "5\n69 37 27 4 2", "output": "yes\n1 5" }, { "input": "9\n6 78 63 59 28 24 8 96 99", "output": "yes\n2 7" }, { "input": "6\n19517752 43452931 112792556 68417469 779722934 921694415", "output": "yes\n3 4" }, { "input": "6\n169793171 335736854 449917902 513287332 811627074 938727967", "output": "yes\n1 1" }, { "input": "6\n509329 173849943 297546987 591032670 796346199 914588283", "output": "yes\n1 1" }, { "input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100", "output": "yes\n1 11" }, { "input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100", "output": "yes\n25 37" }, { "input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "yes\n3 22" }, { "input": "2\n404928771 698395106", "output": "yes\n1 1" }, { "input": "2\n699573624 308238132", "output": "yes\n1 2" }, { "input": "5\n75531609 242194958 437796493 433259361 942142185", "output": "yes\n3 4" }, { "input": "5\n226959376 840957605 833410429 273566427 872976052", "output": "yes\n2 4" }, { "input": "5\n373362086 994096202 767275079 734424844 515504383", "output": "yes\n2 5" }, { "input": "5\n866379155 593548704 259097686 216134784 879911740", "output": "yes\n1 4" }, { "input": "5\n738083041 719956102 420866851 307749161 257917459", "output": "yes\n1 5" }, { "input": "5\n90786760 107075352 139104198 424911569 858427981", "output": "yes\n1 1" }, { "input": "6\n41533825 525419745 636375901 636653266 879043107 967434399", "output": "yes\n1 1" }, { "input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907", "output": "yes\n20 35" }, { "input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165", "output": "no" }, { "input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471", "output": "no" }, { "input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655", "output": "yes\n1 1" }, { "input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992", "output": "no" }, { "input": "4\n1 4 2 3", "output": "no" }, { "input": "6\n1 2 5 4 3 6", "output": "yes\n3 5" }, { "input": "1\n1", "output": "yes\n1 1" }, { "input": "6\n1 5 3 4 2 6", "output": "no" }, { "input": "4\n3 4 1 2", "output": "no" }, { "input": "5\n2 5 4 3 1", "output": "no" }, { "input": "4\n2 1 4 3", "output": "no" }, { "input": "6\n2 1 4 3 5 6", "output": "no" } ]
1,689,650,498
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
4
61
2,867,200
import sys read = sys.stdin.readline write = sys.stdout.write def solve(): n = int(read()) arr = list(map(int, read().split())) comp = sorted(arr) counter = 0 ind = 0 for i in range(n): if arr[i] != comp[i]: if counter == 0: ind = i + 1 counter += 1 if counter == 0: return "yes\n1 1" if counter != 2: return "no" return "yes\n" + str(ind) + " " + str(arr.index(ind) + 1) write(solve())
Title: Sort the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). Output Specification: Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. Demo Input: ['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n'] Demo Output: ['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n'] Note: Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted. Sample 3. No segment can be reversed such that the array will be sorted. Definitions A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*]. If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become: *a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
```python import sys read = sys.stdin.readline write = sys.stdout.write def solve(): n = int(read()) arr = list(map(int, read().split())) comp = sorted(arr) counter = 0 ind = 0 for i in range(n): if arr[i] != comp[i]: if counter == 0: ind = i + 1 counter += 1 if counter == 0: return "yes\n1 1" if counter != 2: return "no" return "yes\n" + str(ind) + " " + str(arr.index(ind) + 1) write(solve()) ```
-1
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "5\n1 4 5 2 3", "output": "4" }, { "input": "6\n4 6 3 5 2 1", "output": "5" }, { "input": "7\n1 5 3 6 2 4 7", "output": "6" }, { "input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75", "output": "94" }, { "input": "8\n4 5 3 8 6 7 1 2", "output": "6" }, { "input": "9\n6 8 5 3 4 7 9 2 1", "output": "8" }, { "input": "10\n8 7 10 1 2 3 4 6 5 9", "output": "7" }, { "input": "11\n5 4 6 9 10 11 7 3 1 2 8", "output": "8" }, { "input": "12\n3 6 7 8 9 10 12 5 4 2 11 1", "output": "11" }, { "input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6", "output": "10" }, { "input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8", "output": "8" }, { "input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9", "output": "9" }, { "input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16", "output": "15" }, { "input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17", "output": "16" }, { "input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10", "output": "11" }, { "input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1", "output": "18" }, { "input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1", "output": "19" }, { "input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21", "output": "20" }, { "input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1", "output": "21" }, { "input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6", "output": "22" }, { "input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4", "output": "16" }, { "input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25", "output": "24" }, { "input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3", "output": "21" }, { "input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1", "output": "26" }, { "input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2", "output": "27" }, { "input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26", "output": "22" }, { "input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7", "output": "26" }, { "input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7", "output": "18" }, { "input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28", "output": "30" }, { "input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3", "output": "29" }, { "input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12", "output": "33" }, { "input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7", "output": "21" }, { "input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8", "output": "35" }, { "input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28", "output": "35" }, { "input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29", "output": "34" }, { "input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1", "output": "38" }, { "input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1", "output": "39" }, { "input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6", "output": "34" }, { "input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35", "output": "41" }, { "input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1", "output": "42" }, { "input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28", "output": "37" }, { "input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1", "output": "44" }, { "input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30", "output": "34" }, { "input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2", "output": "41" }, { "input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7", "output": "38" }, { "input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31", "output": "40" }, { "input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40", "output": "38" }, { "input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32", "output": "43" }, { "input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39", "output": "48" }, { "input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49", "output": "52" }, { "input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53", "output": "41" }, { "input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52", "output": "48" }, { "input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15", "output": "46" }, { "input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57", "output": "56" }, { "input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50", "output": "57" }, { "input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20", "output": "58" }, { "input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1", "output": "59" }, { "input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21", "output": "60" }, { "input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62", "output": "61" }, { "input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17", "output": "46" }, { "input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47", "output": "55" }, { "input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64", "output": "62" }, { "input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29", "output": "65" }, { "input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32", "output": "45" }, { "input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3", "output": "64" }, { "input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63", "output": "45" }, { "input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35", "output": "64" }, { "input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21", "output": "50" }, { "input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56", "output": "57" }, { "input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21", "output": "45" }, { "input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58", "output": "63" }, { "input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58", "output": "74" }, { "input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68", "output": "75" }, { "input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34", "output": "62" }, { "input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72", "output": "70" }, { "input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58", "output": "77" }, { "input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78", "output": "52" }, { "input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55", "output": "69" }, { "input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52", "output": "53" }, { "input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69", "output": "66" }, { "input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38", "output": "80" }, { "input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78", "output": "84" }, { "input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3", "output": "70" }, { "input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85", "output": "58" }, { "input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67", "output": "87" }, { "input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89", "output": "88" }, { "input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25", "output": "60" }, { "input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1", "output": "90" }, { "input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72", "output": "67" }, { "input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34", "output": "85" }, { "input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68", "output": "69" }, { "input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1", "output": "94" }, { "input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56", "output": "86" }, { "input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90", "output": "95" }, { "input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1", "output": "97" }, { "input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71", "output": "87" }, { "input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37", "output": "89" }, { "input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1", "output": "99" }, { "input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42", "output": "65" }, { "input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93", "output": "87" }, { "input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11", "output": "81" }, { "input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75", "output": "99" }, { "input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67", "output": "96" }, { "input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56", "output": "62" }, { "input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100", "output": "99" }, { "input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64", "output": "97" }, { "input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57", "output": "98" }, { "input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69", "output": "98" }, { "input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14", "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": "4\n1 2 3 4", "output": "3" }, { "input": "4\n1 2 4 3", "output": "3" }, { "input": "4\n1 3 2 4", "output": "3" }, { "input": "4\n1 3 4 2", "output": "3" }, { "input": "4\n1 4 2 3", "output": "3" }, { "input": "4\n1 4 3 2", "output": "3" }, { "input": "4\n2 1 3 4", "output": "3" }, { "input": "4\n2 1 4 3", "output": "2" }, { "input": "4\n2 4 1 3", "output": "2" }, { "input": "4\n2 4 3 1", "output": "3" }, { "input": "4\n3 1 2 4", "output": "3" }, { "input": "4\n3 1 4 2", "output": "2" }, { "input": "4\n3 2 1 4", "output": "3" }, { "input": "4\n3 2 4 1", "output": "3" }, { "input": "4\n3 4 1 2", "output": "2" }, { "input": "4\n3 4 2 1", "output": "3" }, { "input": "4\n4 1 2 3", "output": "3" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "4\n4 2 1 3", "output": "3" }, { "input": "4\n4 2 3 1", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "4\n4 3 2 1", "output": "3" }, { "input": "8\n2 5 6 4 8 3 1 7", "output": "6" }, { "input": "5\n2 3 1 5 4", "output": "3" }, { "input": "6\n2 5 3 6 4 1", "output": "5" }, { "input": "6\n5 4 2 6 1 3", "output": "4" }, { "input": "6\n4 2 3 1 6 5", "output": "4" }, { "input": "6\n5 4 2 1 6 3", "output": "4" }, { "input": "9\n7 2 3 4 5 6 1 9 8", "output": "7" }, { "input": "6\n3 2 1 4 6 5", "output": "4" }, { "input": "6\n2 3 4 1 6 5", "output": "4" }, { "input": "10\n5 2 3 4 1 6 7 8 10 9", "output": "8" }, { "input": "6\n5 2 3 1 6 4", "output": "4" }, { "input": "10\n2 9 3 4 1 10 5 6 7 8", "output": "5" }, { "input": "10\n2 3 4 5 6 7 1 8 10 9", "output": "8" }, { "input": "8\n2 3 4 5 1 6 8 7", "output": "6" }, { "input": "6\n2 1 3 4 5 6", "output": "5" } ]
1,632,826,418
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
6,963,200
t = int(input()) a = input().split() b = min(a) c = max(a) emin = a.index(b) emax = a.index(c) if emin > emax: if t - emax > emax :emin = t-1 else:emax = 0 print(abs(emin - emax)) else: if t - emin > emin :emax = t-1 else:emin = 0 print(abs(emax - emin))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. Output Specification: Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. Demo Input: ['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n'] Demo Output: ['3\n', '6\n', '5\n'] Note: In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
```python t = int(input()) a = input().split() b = min(a) c = max(a) emin = a.index(b) emax = a.index(c) if emin > emax: if t - emax > emax :emin = t-1 else:emax = 0 print(abs(emin - emax)) else: if t - emin > emin :emax = t-1 else:emin = 0 print(abs(emax - emin)) ```
0
90
B
African Crossword
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. African Crossword
2
256
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously. When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem. You are suggested to solve an African crossword and print the word encrypted there.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
[ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n" ]
[ "abcd", "codeforces" ]
none
1,000
[ { "input": "3 3\ncba\nbcd\ncbc", "output": "abcd" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "output": "codeforces" }, { "input": "4 4\nusah\nusha\nhasu\nsuha", "output": "ahhasusu" }, { "input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "output": "bcdeghjlmnprsuvwz" }, { "input": "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe", "output": "b" }, { "input": "15 3\njhg\njkn\njui\nfth\noij\nyuf\nyfb\nugd\nhgd\noih\nhvc\nugg\nyvv\ntdg\nhgf", "output": "hkniftjfbctd" }, { "input": "17 19\nbmzbmweyydiadtlcoue\ngmdbyfwurpwbpuvhifn\nuapwyndmhtqvkgkbhty\ntszotwflegsjzzszfwt\nzfpnscguemwrczqxyci\nvdqnkypnxnnpmuduhzn\noaquudhavrncwfwujpc\nmiggjmcmkkbnjfeodxk\ngjgwxtrxingiqquhuwq\nhdswxxrxuzzfhkplwun\nfagppcoildagktgdarv\neusjuqfistulgbglwmf\ngzrnyxryetwzhlnfewc\nzmnoozlqatugmdjwgzc\nfabbkoxyjxkatjmpprs\nwkdkobdagwdwxsufees\nrvncbszcepigpbzuzoo", "output": "lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs" }, { "input": "1 1\na", "output": "a" }, { "input": "2 2\nzx\nxz", "output": "zxxz" }, { "input": "1 2\nfg", "output": "fg" }, { "input": "2 1\nh\nj", "output": "hj" }, { "input": "1 3\niji", "output": "j" }, { "input": "3 1\nk\np\nk", "output": "p" }, { "input": "2 3\nmhw\nbfq", "output": "mhwbfq" }, { "input": "3 2\nxe\ner\nwb", "output": "xeerwb" }, { "input": "3 7\nnutuvjg\ntgqutfn\nyfjeiot", "output": "ntvjggqfnyfjeiot" }, { "input": "5 4\nuzvs\namfz\nwypl\nxizp\nfhmf", "output": "uzvsamfzwyplxizphm" }, { "input": "8 9\ntjqrtgrem\nrwjcfuoey\nywrjgpzca\nwabzggojv\najqmmcclh\nozilebskd\nqmgnbmtcq\nwakptzkjr", "output": "mrjcfuyyrjpzabzvalhozilebskdgnbtpzr" }, { "input": "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt", "output": "elwtabvyokgmplabqbxlt" }, { "input": "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv", "output": "eklgximpzgfvwcmrrqedoiqptdeiokuorv" }, { "input": "14 27\npzoshpvvjdpmwfoeojapmkxjrnk\nitoojpcorxjdxrwyewtmmlhjxhx\ndoyopbwusgsmephixzcilxpskxh\nygpvepeuxjbnezdrnjfwdhjwjka\nrfjlbypoalbtjwrpjxzenmeipfg\nkhjhrtktcnajrnbefhpavxxfnlx\nvwlwumqpfegjgvoezevqsolaqhh\npdrvrtzqsoujqfeitkqgtxwckrl\nxtepjflcxcrfomhqimhimnzfxzg\nwhkfkfvvjwkmwhfgeovwowshyhw\nolchgmhiehumivswgtfyhqfagbp\ntdudrkttpkryvaiepsijuejqvmq\nmuratfqqdbfpefmhjzercortroh\nwxkebkzchupxumfizftgqvuwgau", "output": "zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva" }, { "input": "1 100\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu", "output": "g" }, { "input": "2 100\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg", "output": "rbe" }, { "input": "3 100\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo", "output": "blkck" }, { "input": "100 1\na\nm\nn\nh\na\nx\nt\na\no\np\nj\nz\nr\nk\nq\nl\nb\nr\no\ni\ny\ni\np\ni\nt\nn\nd\nc\nz\np\nu\nn\nw\ny\ng\ns\nt\nm\nz\ne\nv\ng\ny\nj\nd\nz\ny\na\nn\nx\nk\nd\nq\nn\nv\ng\nk\ni\nk\nf\na\nb\nw\no\nu\nw\nk\nk\nb\nz\nu\ni\nu\nv\ng\nv\nx\ng\np\ni\nz\ns\nv\nq\ns\nb\nw\ne\np\nk\nt\np\nd\nr\ng\nd\nk\nm\nf\nd", "output": "hlc" }, { "input": "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\nrp\nsz\noi\nec\npw\nhf\njm\nwu\nhq\nra\npv\ntc\ngv\nik\nux\ntz\nbf\nty\ndk\nwo\nor\nza\nkv\nqt\nfa\njy\nbk\nuv\ngk\ncz\nds\nie\noq\nmf\nxn\nql\nxs\nfb\niv\ncj\nkn\nns\nlg\nji\nha\naj\ndg\nfj\nut\nsg\nju\noc\nov\nhe\nnw\nbl\nlp\nbx\nnm\nyq\ncw\nov\nxk\npg\noh\npl\nuo\ngf\nul", "output": "dvy" }, { "input": "100 3\nruy\nmye\njgp\nscn\nktq\nalx\nmvk\nlpm\nkry\norb\nmpu\nzcv\nlge\nkft\ndzp\ntfb\nhqz\nuur\nhry\nzjx\ncuo\nqqc\ntih\nenj\nvnp\nbwi\nzzh\nhkc\nwdr\nldh\nvel\nizj\nfhb\nqrn\nqpp\nvzs\nlhg\nkee\nlbq\nzhy\nwcl\nyaa\nton\nfly\nkyw\nept\ngwq\ncoe\nopd\neez\nnmx\nnjg\nwhy\nvel\nafq\nnbq\nulx\noxs\nbbo\nyhx\nfmz\nnrg\nnfm\njek\nbeu\ntya\nxgs\nsgg\nnkq\nbbv\nwkd\ntns\nfdt\neox\nobc\neab\nkkj\noub\ngji\nrht\nozv\nysk\nsbt\nflf\npbu\nlxb\npzs\nrzh\ncea\nkmi\nuea\nncc\nzng\nvkn\njhn\njqw\nlqc\nmbt\nlov\ngam", "output": "tvdiixs" } ]
1,531,576,796
2,147,483,647
Python 3
OK
TESTS
43
342
512,000
inds=set() def is_not_clone(words,x,z): clone=1 sim=words[z][x] #print('cursim=',sim) n=len(words) if (x,z) in inds: return 0 for c,item in enumerate(words[z]): #print('c=%s sim=%s '%(c,item)) if sim==item and c!=x: inds.add((c,z)) clone=0 for c in range(n): if sim==words[c][x] and c!=z: inds.add((x,c)) clone=0 return clone n,m = map(int, input().split()) words=list() for c in range(n): s=input() words.append(s) out='' for c in range(n): for d in range(m): if is_not_clone(words,d,c): out+=words[c][d] print(out)
Title: African Crossword Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously. When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem. You are suggested to solve an African crossword and print the word encrypted there. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. Output Specification: Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. Demo Input: ['3 3\ncba\nbcd\ncbc\n', '5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n'] Demo Output: ['abcd', 'codeforces'] Note: none
```python inds=set() def is_not_clone(words,x,z): clone=1 sim=words[z][x] #print('cursim=',sim) n=len(words) if (x,z) in inds: return 0 for c,item in enumerate(words[z]): #print('c=%s sim=%s '%(c,item)) if sim==item and c!=x: inds.add((c,z)) clone=0 for c in range(n): if sim==words[c][x] and c!=z: inds.add((x,c)) clone=0 return clone n,m = map(int, input().split()) words=list() for c in range(n): s=input() words.append(s) out='' for c in range(n): for d in range(m): if is_not_clone(words,d,c): out+=words[c][d] print(out) ```
3.913546
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,679,499,000
2,147,483,647
Python 3
OK
TESTS
22
122
102,400
import math n=int(input()) l=[i+1 for i in range(n)] l2=[] for i in range(int(n/2)): l2.append(l[i]) l2.append(l[-(i+1)]) if n%2==1: l2.append(math.ceil(n/2)) print(*l2)
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 n=int(input()) l=[i+1 for i in range(n)] l2=[] for i in range(int(n/2)): l2.append(l[i]) l2.append(l[-(i+1)]) if n%2==1: l2.append(math.ceil(n/2)) print(*l2) ```
3.969309
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work.
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "52870" }, { "input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245", "output": "46995" }, { "input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434", "output": "85540" }, { "input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357", "output": "67147" }, { "input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422", "output": "85876" }, { "input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282", "output": "38570" }, { "input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431", "output": "11134" }, { "input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424", "output": "59043" }, { "input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369", "output": "53608" }, { "input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438", "output": "84067" }, { "input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439", "output": "79844" }, { "input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437", "output": "82686" }, { "input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437", "output": "92356" }, { "input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434", "output": "107490" }, { "input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401", "output": "25258" }, { "input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419", "output": "23992" } ]
1,673,735,430
2,147,483,647
PyPy 3-64
OK
TESTS
30
154
0
[n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()]; rold=-1; ans=0; for _ in range(n): [l,r]=[int(x) for x in input().split()]; ans+=(r-l)*p1; if rold>0: if l-rold>=t1+t2: ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2); elif l-rold>=t1: ans+=p1*t1+p2*(l-rold-t1); elif l-rold>=0: ans+=p1*(l-rold); rold=r; print(ans);
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. Input Specification: The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work. Output Specification: Output the answer to the problem. Demo Input: ['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n'] Demo Output: ['30', '570'] Note: none
```python [n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()]; rold=-1; ans=0; for _ in range(n): [l,r]=[int(x) for x in input().split()]; ans+=(r-l)*p1; if rold>0: if l-rold>=t1+t2: ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2); elif l-rold>=t1: ans+=p1*t1+p2*(l-rold-t1); elif l-rold>=0: ans+=p1*(l-rold); rold=r; print(ans); ```
3.923
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5", "output": "6" }, { "input": "2\n3 5\n1 9", "output": "0" }, { "input": "10\n43 80\n39 75\n26 71\n4 17\n11 57\n31 42\n1 62\n9 19\n27 76\n34 53", "output": "4" }, { "input": "50\n33 35\n98 99\n1 2\n4 6\n17 18\n63 66\n29 30\n35 37\n44 45\n73 75\n4 5\n39 40\n92 93\n96 97\n23 27\n49 50\n2 3\n60 61\n43 44\n69 70\n7 8\n45 46\n21 22\n85 86\n48 49\n41 43\n70 71\n10 11\n27 28\n71 72\n6 7\n15 16\n46 47\n89 91\n54 55\n19 21\n86 87\n37 38\n77 82\n84 85\n54 55\n93 94\n45 46\n37 38\n75 76\n22 23\n50 52\n38 39\n1 2\n66 67", "output": "2" }, { "input": "2\n1 5\n7 9", "output": "4" }, { "input": "2\n1 5\n3 5", "output": "2" }, { "input": "2\n1 5\n1 2", "output": "3" }, { "input": "5\n5 10\n5 10\n5 10\n5 10\n5 10", "output": "0" }, { "input": "6\n1 99\n33 94\n68 69\n3 35\n93 94\n5 98", "output": "3" }, { "input": "11\n2 98\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "2" }, { "input": "10\n95 96\n19 20\n72 73\n1 2\n25 26\n48 49\n90 91\n22 23\n16 17\n16 17", "output": "1" }, { "input": "11\n1 100\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "4" }, { "input": "21\n0 100\n81 90\n11 68\n18 23\n75 78\n45 86\n37 58\n15 21\n40 98\n53 100\n10 70\n14 75\n1 92\n23 81\n13 66\n93 100\n6 34\n22 87\n27 84\n15 63\n54 91", "output": "1" }, { "input": "10\n60 66\n5 14\n1 3\n55 56\n70 87\n34 35\n16 21\n23 24\n30 31\n25 27", "output": "6" }, { "input": "40\n29 31\n22 23\n59 60\n70 71\n42 43\n13 15\n11 12\n64 65\n1 2\n62 63\n54 56\n8 9\n2 3\n53 54\n27 28\n48 49\n72 73\n17 18\n46 47\n18 19\n43 44\n39 40\n83 84\n63 64\n52 53\n33 34\n3 4\n24 25\n74 75\n0 1\n61 62\n68 69\n80 81\n5 6\n36 37\n81 82\n50 51\n66 67\n69 70\n20 21", "output": "2" }, { "input": "15\n22 31\n0 4\n31 40\n77 80\n81 83\n11 13\n59 61\n53 59\n51 53\n87 88\n14 22\n43 45\n8 10\n45 47\n68 71", "output": "9" }, { "input": "31\n0 100\n2 97\n8 94\n9 94\n14 94\n15 93\n15 90\n17 88\n19 88\n19 87\n20 86\n25 86\n30 85\n32 85\n35 82\n35 81\n36 80\n37 78\n38 74\n38 74\n39 71\n40 69\n40 68\n41 65\n43 62\n44 62\n45 61\n45 59\n46 57\n49 54\n50 52", "output": "5" }, { "input": "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n26 28\n47 88\n30 40\n26 34\n2 12\n9 10\n4 19\n35 36\n41 92\n1 16\n41 78\n56 81\n23 35\n40 68", "output": "7" }, { "input": "27\n0 97\n7 9\n6 9\n12 33\n12 26\n15 27\n10 46\n33 50\n31 47\n15 38\n12 44\n21 35\n24 37\n51 52\n65 67\n58 63\n53 60\n63 68\n57 63\n60 68\n55 58\n74 80\n70 75\n89 90\n81 85\n93 99\n93 98", "output": "19" }, { "input": "20\n23 24\n22 23\n84 86\n6 10\n40 45\n11 13\n24 27\n81 82\n53 58\n87 90\n14 15\n49 50\n70 75\n75 78\n98 100\n66 68\n18 21\n1 2\n92 93\n34 37", "output": "1" }, { "input": "11\n2 100\n34 65\n4 50\n63 97\n82 99\n43 54\n23 52\n4 33\n15 84\n23 31\n12 34", "output": "3" }, { "input": "60\n73 75\n6 7\n69 70\n15 16\n54 55\n66 67\n7 8\n39 40\n38 39\n37 38\n1 2\n46 47\n7 8\n21 22\n23 27\n15 16\n45 46\n37 38\n60 61\n4 6\n63 66\n10 11\n33 35\n43 44\n2 3\n4 6\n10 11\n93 94\n45 46\n7 8\n44 45\n41 43\n35 37\n17 18\n48 49\n89 91\n27 28\n46 47\n71 72\n1 2\n75 76\n49 50\n84 85\n17 18\n98 99\n54 55\n46 47\n19 21\n77 82\n29 30\n4 5\n70 71\n85 86\n96 97\n86 87\n92 93\n22 23\n50 52\n44 45\n63 66", "output": "2" }, { "input": "40\n47 48\n42 44\n92 94\n15 17\n20 22\n11 13\n37 39\n6 8\n39 40\n35 37\n21 22\n41 42\n77 78\n76 78\n69 71\n17 19\n18 19\n17 18\n84 85\n9 10\n11 12\n51 52\n99 100\n7 8\n97 99\n22 23\n60 62\n7 8\n67 69\n20 22\n13 14\n89 91\n15 17\n12 13\n56 57\n37 39\n29 30\n24 26\n37 38\n25 27", "output": "1" }, { "input": "10\n28 36\n18 26\n28 35\n95 100\n68 72\n41 42\n76 84\n99 100\n6 8\n58 60", "output": "1" }, { "input": "20\n69 72\n88 92\n77 80\n64 69\n66 67\n79 81\n91 96\n78 83\n81 86\n11 12\n48 53\n22 23\n81 84\n89 92\n56 60\n1 4\n1 5\n60 62\n20 23\n63 66", "output": "3" }, { "input": "71\n1 99\n11 69\n86 92\n7 49\n31 70\n42 53\n48 81\n86 96\n36 91\n19 38\n39 91\n41 64\n87 93\n83 97\n40 41\n3 32\n15 18\n58 65\n22 32\n1 71\n58 86\n64 77\n15 69\n4 34\n42 89\n9 66\n15 18\n58 65\n59 96\n39 89\n19 38\n6 63\n26 73\n29 47\n55 88\n5 78\n41 74\n48 81\n20 71\n59 96\n42 49\n4 69\n41 74\n87 93\n0 65\n2 34\n15 18\n10 56\n55 88\n33 56\n42 89\n86 92\n42 81\n65 82\n5 78\n13 52\n32 85\n7 65\n59 96\n4 65\n46 69\n10 56\n42 89\n4 69\n0 65\n32 35\n5 78\n32 75\n42 53\n55 59\n64 77", "output": "2" }, { "input": "1\n1 2", "output": "1" } ]
1,568,378,574
2,147,483,647
Python 3
OK
TESTS
37
109
0
#code n=int(input()) x,y=input().split() x,y = int(x),int(y) l=list(range(x,y)) s=set(l) for i in range (1,n): p,q=input().split() p,q=int(p),int(q) l1=list(range(p,q)) s1=set(l1) s=s-s1 print(len(s))
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. Output Specification: On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. Demo Input: ['3\n0 5\n2 8\n1 6\n', '3\n0 10\n1 5\n7 15\n'] Demo Output: ['1\n', '3\n'] Note: Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
```python #code n=int(input()) x,y=input().split() x,y = int(x),int(y) l=list(range(x,y)) s=set(l) for i in range (1,n): p,q=input().split() p,q=int(p),int(q) l1=list(range(p,q)) s1=set(l1) s=s-s1 print(len(s)) ```
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,661,313,778
2,147,483,647
PyPy 3-64
OK
TESTS
81
154
0
x = y = z = 0 for _ in range(int(input())): forces = tuple(map(int, input().split())) x += forces[0] y += forces[1] z += forces[2] print("YES" if x == y == 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 x = y = z = 0 for _ in range(int(input())): forces = tuple(map(int, input().split())) x += forces[0] y += forces[1] z += forces[2] print("YES" if x == y == z == 0 else "NO") ```
3.9615
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, { "input": "100 100 100\n100 100 100\n1", "output": "NO" }, { "input": "1 10 100\n100 10 1\n20", "output": "NO" }, { "input": "1 1 1\n0 0 0\n1", "output": "YES" }, { "input": "0 0 0\n1 1 1\n1", "output": "YES" }, { "input": "5 5 5\n0 0 0\n2", "output": "NO" }, { "input": "0 0 0\n10 10 10\n2", "output": "NO" }, { "input": "21 61 39\n63 58 69\n44", "output": "YES" }, { "input": "18 95 4\n7 1 75\n46", "output": "YES" }, { "input": "64 27 81\n72 35 23\n48", "output": "YES" }, { "input": "6 6 6\n11 11 11\n7", "output": "NO" }, { "input": "1 2 3\n2 4 6\n3", "output": "NO" }, { "input": "1 2 3\n2 4 6\n4", "output": "YES" }, { "input": "99 99 99\n99 99 99\n89", "output": "NO" }, { "input": "5 0 0\n15 0 0\n2", "output": "NO" }, { "input": "10 10 10\n0 0 0\n1", "output": "NO" }, { "input": "1 1 1\n1 1 1\n15", "output": "YES" }, { "input": "2 3 5\n2 3 5\n2", "output": "NO" }, { "input": "2 2 2\n3 3 5\n3", "output": "NO" }, { "input": "1 2 2\n2 4 4\n1", "output": "NO" }, { "input": "1 2 3\n1 5 5\n2", "output": "NO" } ]
1,658,662,417
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
a1,a2,a3=map(int,input().split()) b1,b2,b3=map(int,input().split()) n=int(input()) if a1+a2+a3==0 or b1+b2+b3==0: print("NO") elif n/2>=1: if a1+a2+a3<=5 or b1+b2+b3<=10: print("YES") else: print("NO") else: print("NO")
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. Input Specification: The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces. Output Specification: Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). Demo Input: ['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python a1,a2,a3=map(int,input().split()) b1,b2,b3=map(int,input().split()) n=int(input()) if a1+a2+a3==0 or b1+b2+b3==0: print("NO") elif n/2>=1: if a1+a2+a3<=5 or b1+b2+b3<=10: print("YES") else: print("NO") else: print("NO") ```
0
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,689,070,731
2,147,483,647
Python 3
OK
TESTS
45
46
0
l = int(input()) p = int(input()) q = int(input()) x = p*l/(p+q) print(x)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python l = int(input()) p = int(input()) q = int(input()) x = p*l/(p+q) print(x) ```
3
784
F
Crunching Numbers Just for You
PROGRAMMING
1,900
[ "*special", "implementation" ]
null
null
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100).
Output space-separated elements of the sorted array.
[ "3 3 1 2\n" ]
[ "1 2 3 \n" ]
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
0
[ { "input": "3 3 1 2", "output": "1 2 3 " }, { "input": "10 54 100 27 1 33 27 80 49 27 6", "output": "1 6 27 27 27 33 49 54 80 100 " } ]
1,617,285,165
5,505
PyPy 3
WRONG_ANSWER
TESTS
0
93
0
a = input().split(' ') b = [int(x) for x in a] for x in sorted(b): print(x, end=' ')
Title: Crunching Numbers Just for You Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. Input Specification: The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). Output Specification: Output space-separated elements of the sorted array. Demo Input: ['3 3 1 2\n'] Demo Output: ['1 2 3 \n'] Note: Remember, this is a very important feature, and you have to make sure the customers appreciate it!
```python a = input().split(' ') b = [int(x) for x in a] for x in sorted(b): print(x, end=' ') ```
0
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3" }, { "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1" }, { "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192", "output": "4\n4\n4\n4" }, { "input": "1\n1\n1\n1000000000", "output": "1" }, { "input": "1\n1\n1\n100005", "output": "1" }, { "input": "3\n1 2 3\n1\n100005", "output": "3" }, { "input": "2\n1 2\n3\n100004\n100005\n100006", "output": "2\n2\n2" }, { "input": "3\n1 1 1\n1\n1", "output": "3" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "3\n1 2 3\n1\n100000", "output": "3" }, { "input": "5\n1 1 1 1 10\n2\n1\n10", "output": "4\n5" }, { "input": "5\n3 10 8 6 11\n1\n10000000", "output": "5" } ]
1,696,960,436
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
42
2,000
13,414,400
import sys input = sys.stdin.readline def lower_bound(arr, x): n = len(arr) left = -1 right = n while left + 1 < right: mid = (left + right) if x >= arr[mid]: left = mid else: right = mid return left def main(): n = int(input().strip()) arr = list(map(int, input().strip().split())) arr.sort() q = int(input().strip()) for _ in range(q): m = int(input().strip()) index = lower_bound(arr, m) if index == -1: sys.stdout.write(f'{0}\n') else: sys.stdout.write(f'{index + 1}\n') if __name__ == "__main__": main()
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. Output Specification: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Demo Input: ['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n'] Demo Output: ['0\n4\n1\n5\n'] Note: On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
```python import sys input = sys.stdin.readline def lower_bound(arr, x): n = len(arr) left = -1 right = n while left + 1 < right: mid = (left + right) if x >= arr[mid]: left = mid else: right = mid return left def main(): n = int(input().strip()) arr = list(map(int, input().strip().split())) arr.sort() q = int(input().strip()) for _ in range(q): m = int(input().strip()) index = lower_bound(arr, m) if index == -1: sys.stdout.write(f'{0}\n') else: sys.stdout.write(f'{index + 1}\n') if __name__ == "__main__": main() ```
0
483
B
Friends and Presents
PROGRAMMING
1,800
[ "binary search", "math" ]
null
null
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the first friend does not like the numbers that are divisible without remainder by prime number *x*. The second one does not like the numbers that are divisible without remainder by prime number *y*. Of course, you're not going to present your friends numbers they don't like. Your task is to find such minimum number *v*, that you can form presents using numbers from a set 1,<=2,<=...,<=*v*. Of course you may choose not to present some numbers at all. A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=&lt;<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=&lt;<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime.
Print a single integer — the answer to the problem.
[ "3 1 2 3\n", "1 3 2 3\n" ]
[ "5\n", "4\n" ]
In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.
1,000
[ { "input": "3 1 2 3", "output": "5" }, { "input": "1 3 2 3", "output": "4" }, { "input": "916200 69682 2 3", "output": "1832399" }, { "input": "808351 17767 433 509", "output": "826121" }, { "input": "8851 901 20897 26183", "output": "9752" }, { "input": "5099 2895 16273 29473", "output": "7994" }, { "input": "5099 2895 16273 29473", "output": "7994" }, { "input": "4969 694 293 2347", "output": "5663" }, { "input": "683651932 161878530 2 5", "output": "1367303863" }, { "input": "325832598 637961741 2 3", "output": "1156553206" }, { "input": "999999999 1 2 3", "output": "1999999997" }, { "input": "11006 976 6287 9007", "output": "11982" }, { "input": "150064728 173287472 439 503", "output": "323353664" }, { "input": "819712074 101394406 6173 7307", "output": "921106500" }, { "input": "67462086 313228052 15131 29027", "output": "380690138" }, { "input": "500000000 500000000 29983 29989", "output": "1000000001" }, { "input": "500000000 500000000 2 3", "output": "1199999999" }, { "input": "500000000 500000000 29959 29983", "output": "1000000001" }, { "input": "999999999 1 29983 29989", "output": "1000033352" }, { "input": "1 999999999 29983 29989", "output": "1000033345" }, { "input": "1 999999999 2 3", "output": "1499999998" }, { "input": "999999998 1 2 3", "output": "1999999995" }, { "input": "999999998 2 2 3", "output": "1999999995" }, { "input": "9999999 10000 29983 29989", "output": "10009999" }, { "input": "1000 9999999 29983 29989", "output": "10000999" }, { "input": "110 40 1567 7681", "output": "150" }, { "input": "197 2 6361 18223", "output": "199" }, { "input": "39 154 1033 18947", "output": "193" }, { "input": "126 51 26249 29443", "output": "177" }, { "input": "14 179 19699 29303", "output": "193" }, { "input": "14797 3593 13147 13933", "output": "18390" }, { "input": "782 5750 7079 23957", "output": "6532" }, { "input": "10876 8828 12487 16607", "output": "19704" }, { "input": "16860 2201 6427 23327", "output": "19061" }, { "input": "4901 563 1997 15053", "output": "5464" }, { "input": "1277613 596606 10427 29387", "output": "1874219" }, { "input": "1513389 40825 5641 10009", "output": "1554214" }, { "input": "1749165 72848 9743 20023", "output": "1822013" }, { "input": "954386 580262 4993 15629", "output": "1534648" }, { "input": "159606 875491 43 19121", "output": "1035098" }, { "input": "139694297 21147406 8819 28499", "output": "160841703" }, { "input": "26941620 135675892 4093 28979", "output": "162617513" }, { "input": "9156260 174697920 8171 29863", "output": "183854180" }, { "input": "191370899 1962652 3517 24023", "output": "193333553" }, { "input": "78618222 88031575 28289 29023", "output": "166649797" }, { "input": "1 1 2 3", "output": "2" }, { "input": "1 2 2 3", "output": "3" }, { "input": "1 2 29983 29989", "output": "3" }, { "input": "1 1 29983 29989", "output": "2" }, { "input": "2 1 2 3", "output": "3" } ]
1,556,776,736
2,147,483,647
Python 3
OK
TESTS
50
109
0
def judge(n,m,sum): cnt=int(sum/x/y) if x==y: cnt=int(sum/x) #print(cnt) n=max(0, n-int(sum/y)+cnt) m=max(0, m-int(sum/x)+cnt) #print(n,m) if(sum-int(sum/x)-int(sum/y)+cnt>=n+m): tmp=0 else: tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt) #print(tmp) return tmp n,m,x,y=map(int,input().split()) sum=n+m #至少要n+m个数 while True: temp=judge(n,m,sum) if temp==0: break sum+=temp print(sum)
Title: Friends and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the first friend does not like the numbers that are divisible without remainder by prime number *x*. The second one does not like the numbers that are divisible without remainder by prime number *y*. Of course, you're not going to present your friends numbers they don't like. Your task is to find such minimum number *v*, that you can form presents using numbers from a set 1,<=2,<=...,<=*v*. Of course you may choose not to present some numbers at all. A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself. Input Specification: The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=&lt;<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=&lt;<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 1 2 3\n', '1 3 2 3\n'] Demo Output: ['5\n', '4\n'] Note: In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.
```python def judge(n,m,sum): cnt=int(sum/x/y) if x==y: cnt=int(sum/x) #print(cnt) n=max(0, n-int(sum/y)+cnt) m=max(0, m-int(sum/x)+cnt) #print(n,m) if(sum-int(sum/x)-int(sum/y)+cnt>=n+m): tmp=0 else: tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt) #print(tmp) return tmp n,m,x,y=map(int,input().split()) sum=n+m #至少要n+m个数 while True: temp=judge(n,m,sum) if temp==0: break sum+=temp print(sum) ```
3
622
A
Infinite Sequence
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence.
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
[ "3\n", "5\n", "10\n", "55\n", "56\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n" ]
none
0
[ { "input": "3", "output": "2" }, { "input": "5", "output": "2" }, { "input": "10", "output": "4" }, { "input": "55", "output": "10" }, { "input": "56", "output": "1" }, { "input": "1000000000000", "output": "88209" }, { "input": "847194127849", "output": "255708" }, { "input": "294719472984", "output": "593358" }, { "input": "999999911791", "output": "1414213" }, { "input": "999999911792", "output": "1" }, { "input": "100000000000000", "output": "1749820" }, { "input": "1", "output": "1" }, { "input": "99993", "output": "312" }, { "input": "99994", "output": "313" }, { "input": "99995", "output": "314" }, { "input": "99990", "output": "309" }, { "input": "2", "output": "1" }, { "input": "99991", "output": "310" }, { "input": "99992", "output": "311" }, { "input": "99996", "output": "315" }, { "input": "99997", "output": "316" }, { "input": "99998", "output": "317" }, { "input": "99999", "output": "318" }, { "input": "1021", "output": "31" }, { "input": "4", "output": "1" }, { "input": "23", "output": "2" }, { "input": "9994", "output": "124" }, { "input": "99939", "output": "258" }, { "input": "99999998250180", "output": "14142135" }, { "input": "6", "output": "3" }, { "input": "8", "output": "2" }, { "input": "35", "output": "7" }, { "input": "100", "output": "9" }, { "input": "10101010", "output": "745" }, { "input": "103", "output": "12" }, { "input": "102", "output": "11" }, { "input": "101", "output": "10" } ]
1,580,318,696
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
307,200
n = int(input()) i = 0 while i*(i+1) < 2*n: i += 1 print(n - i*(i-1)//2)
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence. Input Specification: The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Specification: Print the element in the *n*-th position of the sequence (the elements are numerated from one). Demo Input: ['3\n', '5\n', '10\n', '55\n', '56\n'] Demo Output: ['2\n', '2\n', '4\n', '10\n', '1\n'] Note: none
```python n = int(input()) i = 0 while i*(i+1) < 2*n: i += 1 print(n - i*(i-1)//2) ```
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input": "5\n5 4 3 2 1", "output": "5 4 3 2 1" }, { "input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19" }, { "input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19" }, { "input": "10\n3 4 5 6 7 8 9 10 1 2", "output": "9 10 1 2 3 4 5 6 7 8" }, { "input": "8\n1 5 3 7 2 6 4 8", "output": "1 5 3 7 2 6 4 8" }, { "input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19" }, { "input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25" }, { "input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30" }, { "input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49" }, { "input": "12\n3 8 7 4 6 5 2 1 11 9 10 12", "output": "8 7 1 4 6 5 3 2 10 11 9 12" }, { "input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4" }, { "input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1" }, { "input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3" }, { "input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53" }, { "input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24" }, { "input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61" }, { "input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14" }, { "input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21" }, { "input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9" }, { "input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13" }, { "input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16" }, { "input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6" }, { "input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90" }, { "input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9" }, { "input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20" }, { "input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28" }, { "input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5" }, { "input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43" }, { "input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43" }, { "input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45" }, { "input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64" }, { "input": "12\n12 3 1 5 11 6 7 10 2 8 9 4", "output": "3 9 2 12 4 6 7 10 11 8 5 1" }, { "input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44" }, { "input": "8\n1 3 5 2 4 8 6 7", "output": "1 4 2 5 3 7 8 6" }, { "input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12" }, { "input": "10\n2 9 4 6 10 1 7 5 3 8", "output": "6 1 9 3 8 4 7 10 2 5" }, { "input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7" }, { "input": "10\n2 4 9 3 6 8 10 5 1 7", "output": "9 1 4 2 8 5 10 6 3 7" }, { "input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23" }, { "input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27" }, { "input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23" }, { "input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50" }, { "input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98" }, { "input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25" }, { "input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54" }, { "input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71" }, { "input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8" }, { "input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51" }, { "input": "7\n2 1 5 7 3 4 6", "output": "2 1 5 6 3 7 4" }, { "input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31" }, { "input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21" }, { "input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11" }, { "input": "9\n8 5 2 6 1 9 4 7 3", "output": "5 3 9 7 2 4 8 1 6" }, { "input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13" }, { "input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6" }, { "input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14" }, { "input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16" }, { "input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24" }, { "input": "9\n4 8 6 5 3 9 2 7 1", "output": "9 7 5 1 4 3 8 2 6" }, { "input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32" }, { "input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11" }, { "input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "output": "10 4 1 8 6 13 12 5 3 11 9 2 7" }, { "input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37" }, { "input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25" }, { "input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24" }, { "input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59" }, { "input": "6\n4 3 6 5 1 2", "output": "5 6 2 1 4 3" }, { "input": "9\n7 8 5 3 1 4 2 9 6", "output": "5 7 4 6 3 9 1 2 8" }, { "input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13" }, { "input": "1\n1", "output": "1" }, { "input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13" }, { "input": "2\n2 1", "output": "2 1" }, { "input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18" }, { "input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1" }, { "input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36" }, { "input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32" }, { "input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40" }, { "input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21" }, { "input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4" }, { "input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50" }, { "input": "10\n2 10 7 4 1 5 8 6 3 9", "output": "5 1 9 4 6 8 3 7 10 2" }, { "input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1" }, { "input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11" }, { "input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37" }, { "input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53" }, { "input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49" }, { "input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38" }, { "input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2" }, { "input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5" }, { "input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12" }, { "input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82" }, { "input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97" }, { "input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96" }, { "input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96" }, { "input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1" } ]
1,699,078,015
2,147,483,647
Python 3
OK
TESTS
101
92
0
n=int(input()) m=[] l=list(map(int,input().split())) for i in range(1,len(l)+1): m.append(l.index(i)+1) for j in m: print(j,end=" ") print()
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Output Specification: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Demo Input: ['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['4 1 2 3\n', '1 3 2\n', '1 2\n'] Note: none
```python n=int(input()) m=[] l=list(map(int,input().split())) for i in range(1,len(l)+1): m.append(l.index(i)+1) for j in m: print(j,end=" ") print() ```
3
289
B
Polo the Penguin and Matrix
PROGRAMMING
1,400
[ "brute force", "dp", "implementation", "sortings", "ternary search" ]
null
null
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
[ "2 2 2\n2 4\n6 8\n", "1 2 7\n6 7\n" ]
[ "4\n", "-1\n" ]
none
1,000
[ { "input": "2 2 2\n2 4\n6 8", "output": "4" }, { "input": "1 2 7\n6 7", "output": "-1" }, { "input": "3 2 1\n5 7\n1 2\n5 100", "output": "104" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 2", "output": "12" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 3", "output": "-1" }, { "input": "2 2 4\n5 5\n5 5", "output": "0" }, { "input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7", "output": "9" }, { "input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91", "output": "0" }, { "input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47", "output": "-1" }, { "input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366", "output": "1508" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "1 1 8\n12", "output": "0" } ]
1,672,343,145
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
184
5,222,400
from collections import deque,Counter,OrderedDict import math import sys import random import bisect from functools import reduce from sys import stdin import heapq import copy import os import sys import operator from io import BytesIO, IOBase def main(): class DisjointSetUnion: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n def find(self, a): acopy = a while a != self.parent[a]: a = self.parent[a] while acopy != a: self.parent[acopy], acopy = a, self.parent[acopy] return a def union(self, a, b): a, b = self.find(a), self.find(b) if a != b: if self.size[a] < self.size[b]: a, b = b, a self.num_sets -= 1 self.parent[b] = a self.size[a] += self.size[b] def set_size(self, a): return self.size[self.find(a)] def __len__(self): return self.num_sets n,m,d = map(int, input().split()) arr = [] for _ in range(n): arr.extend(list(map(int, input().split()))) ans = True for i in arr: if (i%d)!=0:ans=False if ans: pika = sys.maxsize for i in range(len(arr)): moves = 0 for j in range(len(arr)): if i!=j: moves+=(max(arr[i],arr[j])-min(arr[i],arr[j]))//d pika=min(pika,moves) print(pika) else: print(-1) ''' nnnn wnn ww nnw nwn nnnn 5 2 AACAA ACAAA 5 2 BABBB ACCDD ''' # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main()
Title: Polo the Penguin and Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so. Input Specification: The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). Output Specification: In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). Demo Input: ['2 2 2\n2 4\n6 8\n', '1 2 7\n6 7\n'] Demo Output: ['4\n', '-1\n'] Note: none
```python from collections import deque,Counter,OrderedDict import math import sys import random import bisect from functools import reduce from sys import stdin import heapq import copy import os import sys import operator from io import BytesIO, IOBase def main(): class DisjointSetUnion: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n def find(self, a): acopy = a while a != self.parent[a]: a = self.parent[a] while acopy != a: self.parent[acopy], acopy = a, self.parent[acopy] return a def union(self, a, b): a, b = self.find(a), self.find(b) if a != b: if self.size[a] < self.size[b]: a, b = b, a self.num_sets -= 1 self.parent[b] = a self.size[a] += self.size[b] def set_size(self, a): return self.size[self.find(a)] def __len__(self): return self.num_sets n,m,d = map(int, input().split()) arr = [] for _ in range(n): arr.extend(list(map(int, input().split()))) ans = True for i in arr: if (i%d)!=0:ans=False if ans: pika = sys.maxsize for i in range(len(arr)): moves = 0 for j in range(len(arr)): if i!=j: moves+=(max(arr[i],arr[j])-min(arr[i],arr[j]))//d pika=min(pika,moves) print(pika) else: print(-1) ''' nnnn wnn ww nnw nwn nnnn 5 2 AACAA ACAAA 5 2 BABBB ACCDD ''' # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
0
152
C
Pocket Book
PROGRAMMING
1,400
[ "combinatorics" ]
null
null
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*, 1<=≤<=*k*<=≤<=*m*), then he took names number *i* and *j* and swapped their prefixes of length *k*. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers *i*, *j*, *k* independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109<=+<=7).
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters.
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7).
[ "2 3\nAAB\nBAA\n", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n" ]
[ "4\n", "216\n" ]
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
1,500
[ { "input": "2 3\nAAB\nBAA", "output": "4" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216" }, { "input": "1 1\nE", "output": "1" }, { "input": "2 2\nNS\nPD", "output": "4" }, { "input": "3 4\nPJKD\nNFJX\nFGFK", "output": "81" }, { "input": "4 5\nSXFMY\nATHLM\nKDDQW\nZWGDS", "output": "1024" }, { "input": "20 14\nJNFKBBBJYZHWQE\nLBOKZCPFNKDBJY\nXKNWGHQHIOXUPF\nDDNRUKVUGHWMXW\nMTIZFNAAFEAPHX\nIXBQOOHEULZYHU\nMRCSREUEOOMUUN\nHJTSQWKUFYZDQU\nGMCMUZCOPRVEIQ\nXBKKGGJECOBLTH\nXXHTLXCNJZJUAF\nVLJRKXXXWMTPKZ\nPTYMNPTBBCWKAD\nQYJGOBUBHMEDYE\nGTKUUVVNKAHTUI\nZNKXYZPCYLBZFP\nQCBLJTRMBDWNNE\nTDOKJOBKEOVNLZ\nFKZUITYAFJOQIM\nUWQNSGLXEEIRWF", "output": "515139391" }, { "input": "5 14\nAQRXUQQNSKZPGC\nDTTKSPFGGVCLPT\nVLZQWWESCHDTAZ\nCOKOWDWDRUOMHP\nXDTRBIZTTCIDGS", "output": "124999979" }, { "input": "9 23\nOILBYKHRGMPENVFNHLSIUOW\nLPJFHTUQUINAALRDGLSQUXR\nLYYJJEBNZATAFQWTDZSPUNZ\nHSJPIQKKWWERJZIEMLCZUKI\nOJYIEYDGPFWRHCMISJCCUEM\nLMGKZVFYIVDRTIHBWPCNUTG\nUBGGNCITVHAIPKXCLTSAULQ\nOWSAWUOXQDBSXXBHTLSXUVD\nUGQTIZQPBGMASRQPVPSFUWK", "output": "454717784" }, { "input": "25 4\nLVKG\nMICU\nZHKW\nLFGG\nOWQO\nLCQG\nLVXU\nOUKB\nLNQX\nZJTO\nOOQX\nLVQP\nMFQB\nMRQV\nOIQH\nOPXX\nXFKU\nFCQB\nZPKH\nLVCH\nNFCU\nOVQW\nOZKU\nLFHX\nLPXO", "output": "5733" }, { "input": "30 10\nUTNTGOKZYJ\nQHOUHNYZVW\nLTVGHJRZVW\nMZHYHOLZYJ\nERYEUEPZYE\nUZDBFTURYJ\nRVSMQTIZGW\nWDJQHMIRYY\nKCORHQPZYE\nRRPLFOZZVY\nJTXMFNNNYJ\nMVTGGOZZVV\nEHAFFNUZVF\nLBRNWJZNYE\nJVMOHTPZYJ\nWTARFJLZVV\nLVJCWOURVW\nLCLQFJYRVV\nQVBVGNJRYF\nNTZGHOLRYE\nMGQKHOUPYJ\nRRSSBXPZYJ\nRYCRGTLZYJ\nJRDEGNKRVW\nRZKFGHYRVG\nMDJBFNIZYG\nMPLWHXIZYE\nSRZMHMURVE\nMTEBBMRZYJ\nJPJIFOLZYM", "output": "919913906" }, { "input": "40 7\nPNTVVER\nPAHTQDR\nRXMJVAS\nVIQNLYC\nILPUSVX\nYJOXQDJ\nSEFODTO\nOTJMREL\nLIQRZGD\nLBJJPOR\nRUTYHQO\nRIWEPBD\nKQUMFIB\nISTRRYH\nXBTOTGK\nRFQODEY\nHDSTZTP\nYCXFAGL\nAREGRFU\nLELZUYU\nGVABDKH\nFJAMMME\nACVULXE\nJHVPJAS\nAAQNMBX\nJJGUCXG\nOQATILQ\nNEOSHJM\nHFLWOFM\nICYEQHY\nFACGLYP\nPLLXJEQ\nDCHXYPB\nAGDDZJJ\nLSQRXTN\nHDQZXIY\nNAHDDWW\nQCMXRQN\nFDUDSZO\nHKBEVTW", "output": "206575993" }, { "input": "2 2\nAA\nBB", "output": "4" }, { "input": "1 10\nAAAAAAAAAA", "output": "1" }, { "input": "2 8\nAAAAAAAA\nBBBBBBBB", "output": "256" }, { "input": "10 10\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB", "output": "1048576" }, { "input": "1 20\nAAAAAAAAAAAAAAAAAAAA", "output": "1" }, { "input": "20 1\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF", "output": "7" }, { "input": "5 60\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", "output": "449874206" }, { "input": "50 4\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ", "output": "10000" }, { "input": "1 100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "1" }, { "input": "100 1\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA", "output": "1" }, { "input": "100 1\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB", "output": "2" }, { "input": "100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB", "output": "14" }, { "input": "100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV", "output": "26" } ]
1,693,686,967
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
92
0
n, m = [int(x) for x in input().split()] nomes = [] output = 1 for i in range(n): nomes.append(input()) for l in range(m): letras = set() for i in range(n): letras.add(nomes[i][l]) output *= len(letras) print(output)
Title: Pocket Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*, 1<=≤<=*k*<=≤<=*m*), then he took names number *i* and *j* and swapped their prefixes of length *k*. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers *i*, *j*, *k* independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109<=+<=7). Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. Output Specification: Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). Demo Input: ['2 3\nAAB\nBAA\n', '4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n'] Demo Output: ['4\n', '216\n'] Note: In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
```python n, m = [int(x) for x in input().split()] nomes = [] output = 1 for i in range(n): nomes.append(input()) for l in range(m): letras = set() for i in range(n): letras.add(nomes[i][l]) output *= len(letras) print(output) ```
0
549
A
Face Detection
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
In the single line print the number of faces on the image.
[ "4 4\nxxxx\nxfax\nxcex\nxxxx\n", "4 2\nxx\ncf\nae\nxx\n", "2 3\nfac\ncef\n", "1 4\nface\n" ]
[ "1\n", "1\n", "2\n", "0\n" ]
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In the fourth sample the image has no faces on it.
250
[ { "input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1" }, { "input": "4 2\nxx\ncf\nae\nxx", "output": "1" }, { "input": "2 3\nfac\ncef", "output": "2" }, { "input": "1 4\nface", "output": "0" }, { "input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx", "output": "0" }, { "input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk", "output": "1" }, { "input": "1 1\np", "output": "0" }, { "input": "2 5\nacdmw\nefazb", "output": "1" }, { "input": "5 2\ndz\nda\nsx\nyu\nzz", "output": "0" }, { "input": "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn", "output": "2" }, { "input": "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay", "output": "3" }, { "input": "5 5\nbyjvu\nkmaca\nalefe\nwcacg\nrefez", "output": "5" }, { "input": "5 5\npuxac\nbbaef\naccfa\nefaec\nligsr", "output": "5" }, { "input": "37 4\nacjo\nefac\nacef\nefac\nwpef\nicac\naefe\ncfac\naece\ncfaf\nyqce\nmiaf\nirce\nycaf\naefc\ncfae\nrsnc\nbacz\nqefb\npdhs\nffac\nfaef\nacfd\nacmi\nefvm\nacaz\nefpn\nacao\nefer\nacap\nefec\nacaf\nefef\nacbj\nefac\nacef\nefoz", "output": "49" }, { "input": "7 3\njac\naef\ncfa\naec\ncfq\ndig\nxyq", "output": "5" }, { "input": "35 1\ny\na\nk\ng\ni\nd\nv\nn\nl\nx\nu\nx\nu\no\nd\nf\nk\nj\nr\nm\nq\ns\nc\nd\nc\nm\nv\nh\nn\ne\nl\nt\nz\ny\no", "output": "0" }, { "input": "9 46\nuuexbaacesjclggslacermcbkxlcxhdgqtacdwfryxzuxc\naclrsaefakndbnzlkefenuphgcgoedhkaxefjtnkgfeaca\nefuqunpmfxdyyffyhvracozzrxlpekhtsrfhlilfmyhefg\numyacfzffvicqtdpiulefnwcojuwtfbvlxkfsiapdnzpqo\nactefvuxqptremlqjhdbdwacjxdxitxjktecvefacamjcz\neflarseklqrkayhosverpfefzirqigzlxezabhzeferkwm\nztpypwxyohtacsnnvoigqwcachtaceyxlkhfhgwbnfmklb\nfzpqeymhljiefctvqtbgcdjefkxefarbciyosmktmoziac\nbssxizyrzyhacszttwhrzspbfkgfcejybdjcpuczhrkqef", "output": "20" }, { "input": "7 30\nmjfracgaacacctacrreyrlkacuacay\nrlacefacefeftaeftkacacaefcefev\nacefacefacraccfaeaefefecaeacaf\nefacefacefaefaecfcfacacaecfefa\nncefacefacecacfaeaecefefcaeace\nfafaceacuafaefadcfcafacaefcfea\nzsvefafukcecfarkaeaecefecailgu", "output": "95" }, { "input": "2 2\nff\nee", "output": "0" }, { "input": "2 2\nfa\ncc", "output": "0" }, { "input": "2 2\nfa\naa", "output": "0" }, { "input": "2 2\nfa\nea", "output": "0" }, { "input": "2 2\nfa\ndd", "output": "0" }, { "input": "2 2\nee\nff", "output": "0" }, { "input": "2 2\ncc\ncf", "output": "0" }, { "input": "2 2\naa\nae", "output": "0" }, { "input": "2 2\nef\nac", "output": "1" }, { "input": "2 2\nfe\nca", "output": "1" } ]
1,660,026,265
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
62
1,536,000
import sys input = sys.stdin.readline n,m = map(int,input().strip().split()) a = [] for _ in range(n): a.append(input().strip()) let = {'f','a','c','e'} c=0 for i in range(n): for j in range(m): try: if a[i][j] in let and a[i][j+1] in let and a[i+1][j] in let and a[i+1][j+1] in let: c+=1 except Exception: pass print(c)
Title: Face Detection Time Limit: None seconds Memory Limit: None megabytes Problem Description: The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input Specification: The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters. Output Specification: In the single line print the number of faces on the image. Demo Input: ['4 4\nxxxx\nxfax\nxcex\nxxxx\n', '4 2\nxx\ncf\nae\nxx\n', '2 3\nfac\ncef\n', '1 4\nface\n'] Demo Output: ['1\n', '1\n', '2\n', '0\n'] Note: In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In the fourth sample the image has no faces on it.
```python import sys input = sys.stdin.readline n,m = map(int,input().strip().split()) a = [] for _ in range(n): a.append(input().strip()) let = {'f','a','c','e'} c=0 for i in range(n): for j in range(m): try: if a[i][j] in let and a[i][j+1] in let and a[i+1][j] in let and a[i+1][j+1] in let: c+=1 except Exception: pass print(c) ```
0
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,696,985,248
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
f = open("input.txt", "r") door = str(f.readline())[0:-1] rail = int(str(f.readline())) f.close() if (door == "front" and rail == 1) or (door == "back" and rail == 0): out = "L" else: out = "R" f = open("output.txt", "w") f.write(out)
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. Input Specification: The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. Output Specification: Print character "R" if the VIP is right-handed or "L" if he is left-handed. Demo Input: ['front\n1\n'] Demo Output: ['L\n'] Note: none
```python f = open("input.txt", "r") door = str(f.readline())[0:-1] rail = int(str(f.readline())) f.close() if (door == "front" and rail == 1) or (door == "back" and rail == 0): out = "L" else: out = "R" f = open("output.txt", "w") f.write(out) ```
0
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,456,509,617
2,717
Python 3
WRONG_ANSWER
TESTS
25
62
0
from math import floor as F if __name__=='__main__': a,b,k= map(int,input().split(' ')) X,Y = ((k/a),0),(0,(k/b)) #print (X,Y) found = False #print (X[0]/Y[1]) x,y=(X[0]),0 while x>=0: #print (x,y) if F(x)*a+b*y==k: found=True break x-=X[0]/Y[1] y+=1 if found: print('Yes') else: print ('No')
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python from math import floor as F if __name__=='__main__': a,b,k= map(int,input().split(' ')) X,Y = ((k/a),0),(0,(k/b)) #print (X,Y) found = False #print (X[0]/Y[1]) x,y=(X[0]),0 while x>=0: #print (x,y) if F(x)*a+b*y==k: found=True break x-=X[0]/Y[1] y+=1 if found: print('Yes') else: print ('No') ```
0
0
none
none
none
0
[ "none" ]
null
null
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second.
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
[ "3\n7 1 3\n1 2 1\n", "4\n5 10 3 2\n2 3 2 4\n" ]
[ "2.000000000000\n", "1.400000000000\n" ]
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
0
[ { "input": "3\n7 1 3\n1 2 1", "output": "2.000000000000" }, { "input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000" }, { "input": "3\n1 1000000000 2\n1 2 1000000000", "output": "333333332.999999999971" }, { "input": "2\n4 5\n10 8", "output": "0.055555555556" }, { "input": "4\n14 12 10 17\n8 6 5 10", "output": "0.466666666667" }, { "input": "5\n1 15 61 29 43\n15 11 19 19 19", "output": "1.764705882353" }, { "input": "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13", "output": "1.750000000000" }, { "input": "2\n1000000000 1000000000\n1 1", "output": "0.000000000000" }, { "input": "3\n1 1 1\n1 1 1", "output": "0.000000000000" } ]
1,570,914,816
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
11
5,000
4,812,800
n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) l = -1 r = 10000000000 for e in range(100): m = (l + r) / 2 left = x[0] - m * v[0] right = x[0] + m * v[0] f = 1 for i in range(1, n): l1 = x[i] - m * v[i] r1 = x[i] + m * v[i] if right < l1 or left > r1: f = 0 break else: left = max(left, l1) right = min(right, r1) if f: r = m else: l = m print(r)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second. Output Specification: Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. Demo Input: ['3\n7 1 3\n1 2 1\n', '4\n5 10 3 2\n2 3 2 4\n'] Demo Output: ['2.000000000000\n', '1.400000000000\n'] Note: In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
```python n = int(input()) x = list(map(int, input().split())) v = list(map(int, input().split())) l = -1 r = 10000000000 for e in range(100): m = (l + r) / 2 left = x[0] - m * v[0] right = x[0] + m * v[0] f = 1 for i in range(1, n): l1 = x[i] - m * v[i] r1 = x[i] + m * v[i] if right < l1 or left > r1: f = 0 break else: left = max(left, l1) right = min(right, r1) if f: r = m else: l = m print(r) ```
0
911
D
Inversion Counting
PROGRAMMING
1,800
[ "brute force", "math" ]
null
null
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=1), (4,<=1), (4,<=3). You are given a permutation *a* of size *n* and *m* queries to it. Each query is represented by two indices *l* and *r* denoting that you have to reverse the segment [*l*,<=*r*] of the permutation. For example, if *a*<==<=[1,<=2,<=3,<=4] and a query *l*<==<=2, *r*<==<=4 is applied, then the resulting permutation is [1,<=4,<=3,<=2]. After each query you have to determine whether the number of inversions is odd or even.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct. The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the number of queries to process. Then *m* lines follow, *i*-th line containing two integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting that *i*-th query is to reverse a segment [*l**i*,<=*r**i*] of the permutation. All queries are performed one after another.
Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise.
[ "3\n1 2 3\n2\n1 2\n2 3\n", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n" ]
[ "odd\neven\n", "odd\nodd\nodd\neven\n" ]
The first example: 1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
0
[ { "input": "3\n1 2 3\n2\n1 2\n2 3", "output": "odd\neven" }, { "input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3", "output": "odd\nodd\nodd\neven" }, { "input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5", "output": "odd\nodd\neven\nodd\neven" }, { "input": "3\n2 1 3\n3\n2 3\n1 1\n1 3", "output": "even\neven\nodd" }, { "input": "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "even\neven\neven\neven\neven\neven\neven\neven\neven\neven" } ]
1,523,042,919
2,147,483,647
Python 3
OK
TESTS
23
1,263
7,782,400
from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) cnt = 0 for i in range(n): for j in range(i + 1, n): if values[i] > values[j]: cnt += 1 m = int(stdin.readline()) for i in range(m): l, r = map(int, stdin.readline().split()) n = r - l + 1 cnt += n * (n - 1) // 2 cnt &= 1 if cnt == 1: stdout.write('odd\n') else: stdout.write('even\n')
Title: Inversion Counting Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=1), (4,<=1), (4,<=3). You are given a permutation *a* of size *n* and *m* queries to it. Each query is represented by two indices *l* and *r* denoting that you have to reverse the segment [*l*,<=*r*] of the permutation. For example, if *a*<==<=[1,<=2,<=3,<=4] and a query *l*<==<=2, *r*<==<=4 is applied, then the resulting permutation is [1,<=4,<=3,<=2]. After each query you have to determine whether the number of inversions is odd or even. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct. The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the number of queries to process. Then *m* lines follow, *i*-th line containing two integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting that *i*-th query is to reverse a segment [*l**i*,<=*r**i*] of the permutation. All queries are performed one after another. Output Specification: Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise. Demo Input: ['3\n1 2 3\n2\n1 2\n2 3\n', '4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n'] Demo Output: ['odd\neven\n', 'odd\nodd\nodd\neven\n'] Note: The first example: 1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
```python from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) cnt = 0 for i in range(n): for j in range(i + 1, n): if values[i] > values[j]: cnt += 1 m = int(stdin.readline()) for i in range(m): l, r = map(int, stdin.readline().split()) n = r - l + 1 cnt += n * (n - 1) // 2 cnt &= 1 if cnt == 1: stdout.write('odd\n') else: stdout.write('even\n') ```
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "input": "eihdi", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "edhii", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto", "output": "YES" }, { "input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm", "output": "YES" }, { "input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv", "output": "YES" }, { "input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs", "output": "YES" }, { "input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji", "output": "YES" }, { "input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn", "output": "YES" }, { "input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx", "output": "YES" }, { "input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy", "output": "YES" }, { "input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc", "output": "YES" }, { "input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef", "output": "NO" }, { "input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa", "output": "YES" }, { "input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg", "output": "YES" }, { "input": "oagjghsidigeh", "output": "NO" }, { "input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz", "output": "YES" }, { "input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi", "output": "YES" }, { "input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx", "output": "YES" }, { "input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq", "output": "YES" } ]
1,575,366,354
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
202
2,150,400
s = input() a = 'heidi' q = 0 for i in s: if i == a[q]: q += 1 print('YES' if q == 5 else 'NO') # FMZJMSOMPMSL
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... Input Specification: The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). Output Specification: Output YES if the string *s* contains heidi as a subsequence and NO otherwise. Demo Input: ['abcheaibcdi\n', 'hiedi\n'] Demo Output: ['YES', 'NO'] Note: A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
```python s = input() a = 'heidi' q = 0 for i in s: if i == a[q]: q += 1 print('YES' if q == 5 else 'NO') # FMZJMSOMPMSL ```
-1
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,652,534,002
2,147,483,647
Python 3
OK
TESTS
35
31
0
n, k = input().split() n, k = int(n), int(k) rez = 0 a = input().split() for i in range(len(a)): a[i] = int(a[i]) + k for i in a: if i <= 5: rez += 1 print(rez // 3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n, k = input().split() n, k = int(n), int(k) rez = 0 a = input().split() for i in range(len(a)): a[i] = int(a[i]) + k for i in a: if i <= 5: rez += 1 print(rez // 3) ```
3
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,689,331,376
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
124
0
import collections n = int(input()) d = collections.defaultdict(int) l = list() for i in range(n): x, y = input().split(' ') d[x] += int(y) l.append((x, y)) m = 0 name = list() for key, val in d.items(): if val == m: name.append(key) elif val > m: name.clear() name.append(key) m = val d = collections.defaultdict(int) if len(name) > 1: for i in l: d[i[0]] += int(i[1]) if d[i[0]] == m: name = [i[0]] break print(name[0])
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 import collections n = int(input()) d = collections.defaultdict(int) l = list() for i in range(n): x, y = input().split(' ') d[x] += int(y) l.append((x, y)) m = 0 name = list() for key, val in d.items(): if val == m: name.append(key) elif val > m: name.clear() name.append(key) m = val d = collections.defaultdict(int) if len(name) > 1: for i in l: d[i[0]] += int(i[1]) if d[i[0]] == m: name = [i[0]] break print(name[0]) ```
0
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*).
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3", "output": "0\n0\n1\n1\n0" }, { "input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5", "output": "2\n1\n1\n1\n1\n1\n1" }, { "input": "#..#\n1\n1 4", "output": "1" }, { "input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4", "output": "2\n2\n3\n2\n1\n4\n0" }, { "input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3", "output": "0\n0\n0\n0\n0\n0\n0" }, { "input": "###..#...#\n2\n2 4\n1 2", "output": "1\n1" }, { "input": "..\n1\n1 2", "output": "1" }, { "input": "##\n1\n1 2", "output": "1" }, { "input": ".#\n1\n1 2", "output": "0" }, { "input": "#.\n1\n1 2", "output": "0" }, { "input": "...\n2\n1 2\n1 2", "output": "1\n1" } ]
1,693,565,132
2,147,483,647
PyPy 3-64
OK
TESTS
37
404
14,950,400
from sys import stdin def input(): return stdin.readline()[:-1] a=list(input()) n=len(a) p=[0]*(n+1) if a[0]==a[1]: p[1]=1 for i in range(1,n-1): if a[i]==a[i+1]: p[i+1]=p[i]+1 else: p[i+1]=p[i] q=int(input()) for i in range(q): l,r=map(int,input().split()) print(p[r-1]-p[l-1])
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=&lt;<=*r**i*), that *s**i*<==<=*s**i*<=+<=1. Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. Input Specification: The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the answers to the queries in the order in which they are given in the input. Demo Input: ['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n'] Demo Output: ['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n'] Note: none
```python from sys import stdin def input(): return stdin.readline()[:-1] a=list(input()) n=len(a) p=[0]*(n+1) if a[0]==a[1]: p[1]=1 for i in range(1,n-1): if a[i]==a[i+1]: p[i+1]=p[i]+1 else: p[i+1]=p[i] q=int(input()) for i in range(q): l,r=map(int,input().split()) print(p[r-1]-p[l-1]) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,661,953,570
2,147,483,647
Python 3
OK
TESTS
36
92
0
# cook your dish here y,w = map(int,input().split()) if y>w: res = y else: res = w res = (6-res) + 1 l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"] print(l[res])
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 # cook your dish here y,w = map(int,input().split()) if y>w: res = y else: res = w res = (6-res) + 1 l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"] print(l[res]) ```
3.954
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1000000000 -1000000000\n1000000000 1000000000", "output": "Yes" }, { "input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5", "output": "Yes" }, { "input": "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000", "output": "No" }, { "input": "2\n-1000000000 1000000000\n-1000000000 -1000000000", "output": "Yes" }, { "input": "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2", "output": "No" }, { "input": "2\n1 0\n-1 0", "output": "Yes" }, { "input": "4\n-1 1\n-1 2\n-1 3\n-1 4", "output": "Yes" }, { "input": "2\n-1 0\n1 0", "output": "Yes" }, { "input": "2\n1 2\n-1 2", "output": "Yes" }, { "input": "2\n8 0\n7 0", "output": "Yes" }, { "input": "6\n-1 0\n-2 0\n-1 -1\n-1 5\n1 0\n1 1", "output": "No" }, { "input": "4\n1 0\n2 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-2 0\n-1 0\n1 0\n2 0", "output": "No" }, { "input": "2\n1 1\n-1 1", "output": "Yes" }, { "input": "4\n-1 0\n-2 0\n1 0\n2 0", "output": "No" }, { "input": "2\n4 3\n-4 -2", "output": "Yes" }, { "input": "4\n1 0\n2 0\n-1 1\n-1 2", "output": "No" }, { "input": "5\n1 1\n2 1\n3 1\n-1 1\n-2 1", "output": "No" }, { "input": "2\n1 1\n-1 -1", "output": "Yes" }, { "input": "4\n1 2\n1 0\n1 -2\n-1 2", "output": "Yes" }, { "input": "5\n-2 3\n-3 3\n4 2\n3 2\n1 2", "output": "No" }, { "input": "3\n2 0\n3 0\n4 0", "output": "Yes" }, { "input": "5\n-3 1\n-2 1\n-1 1\n1 1\n2 1", "output": "No" }, { "input": "4\n-3 0\n1 0\n2 0\n3 0", "output": "Yes" }, { "input": "2\n1 0\n-1 1", "output": "Yes" }, { "input": "3\n-1 0\n1 0\n2 0", "output": "Yes" }, { "input": "5\n1 0\n3 0\n-1 0\n-6 0\n-4 1", "output": "No" }, { "input": "5\n-1 2\n-2 2\n-3 1\n1 2\n2 3", "output": "No" }, { "input": "3\n1 0\n-1 0\n-2 0", "output": "Yes" }, { "input": "4\n1 0\n2 0\n3 1\n4 1", "output": "Yes" }, { "input": "4\n1 0\n1 2\n1 3\n-1 5", "output": "Yes" }, { "input": "4\n2 2\n2 5\n-2 3\n-2 0", "output": "No" }, { "input": "4\n1 1\n-1 1\n-1 0\n-1 -1", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-3 -3\n-3 -4", "output": "No" }, { "input": "4\n-1 0\n-2 0\n-3 0\n-4 0", "output": "Yes" }, { "input": "2\n-1 1\n1 1", "output": "Yes" }, { "input": "5\n1 1\n2 2\n3 3\n-4 -4\n-5 -5", "output": "No" }, { "input": "5\n2 0\n3 0\n4 0\n5 0\n6 0", "output": "Yes" }, { "input": "2\n-1 2\n1 2", "output": "Yes" }, { "input": "4\n1 1\n2 1\n-3 0\n-4 0", "output": "No" }, { "input": "4\n-1 0\n-2 0\n3 0\n4 0", "output": "No" }, { "input": "3\n3 0\n2 0\n1 0", "output": "Yes" }, { "input": "4\n-2 0\n-3 0\n1 -1\n3 1", "output": "No" }, { "input": "3\n-1 -1\n1 1\n2 2", "output": "Yes" }, { "input": "4\n-2 0\n-1 0\n2 0\n1 0", "output": "No" }, { "input": "2\n-3 5\n3 5", "output": "Yes" }, { "input": "2\n-1 5\n1 5", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-2 0\n-3 0", "output": "No" }, { "input": "3\n-1 1\n1 1\n1 -1", "output": "Yes" }, { "input": "2\n1 0\n2 0", "output": "Yes" }, { "input": "4\n-1 1\n-2 1\n2 -1\n3 -1", "output": "No" }, { "input": "5\n1 0\n2 0\n3 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-3 0\n-4 0\n-5 0\n-6 0", "output": "Yes" }, { "input": "6\n-3 0\n-2 0\n-1 0\n1 0\n2 0\n3 0", "output": "No" }, { "input": "4\n5 0\n5 1\n6 0\n6 1", "output": "Yes" } ]
1,514,031,794
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
5,529,600
m=int(input()) cnt=0 cnt1=0 for i in range(m): m,n=map(int,input().split()) if m>0: cnt+=1 if m<0: cnt1+=1 if cnt==m or cnt==m-1 or cnt==0 or cnt==1: print("Yes") else: print("No")
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. Output Specification: Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower). Demo Input: ['3\n1 1\n-1 -1\n2 -1\n', '4\n1 1\n2 2\n-1 1\n-2 2\n', '3\n1 2\n2 1\n4 60\n'] Demo Output: ['Yes', 'No', 'Yes'] Note: In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
```python m=int(input()) cnt=0 cnt1=0 for i in range(m): m,n=map(int,input().split()) if m>0: cnt+=1 if m<0: cnt1+=1 if cnt==m or cnt==m-1 or cnt==0 or cnt==1: print("Yes") else: print("No") ```
0
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,599,983,351
2,147,483,647
Python 3
OK
TESTS
13
218
307,200
def check(n1, n2): if n1 >= n2: print("LIVE") else: print("DEAD") a_rec, a_nrec = 0, 0 b_rec, b_nrec = 0, 0 for _ in range(int(input())): t, x, y = [int(j) for j in input().split()] if t == 1: a_rec += x a_nrec += y else: b_rec += x b_nrec += y check(a_rec, a_nrec) check(b_rec, b_nrec)
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python def check(n1, n2): if n1 >= n2: print("LIVE") else: print("DEAD") a_rec, a_nrec = 0, 0 b_rec, b_nrec = 0, 0 for _ in range(int(input())): t, x, y = [int(j) for j in input().split()] if t == 1: a_rec += x a_nrec += y else: b_rec += x b_nrec += y check(a_rec, a_nrec) check(b_rec, b_nrec) ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,513,694,802
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
5,836,800
import math n,pos = map(int,input().split()) times = n nums = [] for i in range(1,times+1): if(n%i == 0): nums.append(i) if(len(nums)>0 and len(nums)>=pos): print(nums[pos-1]) else: print("-1")
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python import math n,pos = map(int,input().split()) times = n nums = [] for i in range(1,times+1): if(n%i == 0): nums.append(i) if(len(nums)>0 and len(nums)>=pos): print(nums[pos-1]) else: print("-1") ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,680,920,229
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
307,200
n = int(input()) times = [input() for _ in range(n)] print(max(times.count(time) for time in times))
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python n = int(input()) times = [input() for _ in range(n)] print(max(times.count(time) for time in times)) ```
0
440
B
Balancer
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configuration?
The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*.
Print the total minimum number of moves.
[ "6\n1 6 2 5 3 7\n" ]
[ "12\n" ]
none
1,000
[ { "input": "6\n1 6 2 5 3 7", "output": "12" }, { "input": "6\n6 6 6 0 0 0", "output": "27" }, { "input": "6\n0 0 0 6 6 6", "output": "27" }, { "input": "6\n6 6 0 0 6 6", "output": "12" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "10\n0 100 0 100 0 100 0 100 0 100", "output": "250" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "4\n0 0 0 0", "output": "0" }, { "input": "2\n921 29111", "output": "14095" }, { "input": "2\n0 1000000000", "output": "500000000" }, { "input": "2\n291911 1", "output": "145955" }, { "input": "2\n20180000 0", "output": "10090000" }, { "input": "10\n10 9 7 13 7 5 13 15 10 11", "output": "27" }, { "input": "100\n6 3 4 5 3 4 2 4 1 2 4 1 8 5 2 2 4 4 6 8 4 10 4 4 6 8 6 5 5 4 8 4 3 3 6 5 7 2 9 7 6 5 6 3 2 6 8 10 3 6 8 7 2 3 5 4 8 6 5 6 6 8 4 1 5 6 1 8 12 5 3 3 8 2 4 2 4 5 6 6 9 5 1 2 8 8 3 7 5 3 4 5 7 6 3 9 4 6 3 6", "output": "867" }, { "input": "10\n1 1 1 1 1 999999999 999999999 999999999 999999999 999999999", "output": "12499999975" }, { "input": "10\n1 1 1 1 1 1 1 1 2 1000000000", "output": "4499999999" }, { "input": "14\n0 0 0 0 0 0 0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "24500000000" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999", "output": "49999999900" }, { "input": "20\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 2 2 2 2 2 2 2 2 2 2", "output": "49999999900" } ]
1,401,812,532
3,132
Python 3
OK
TESTS
53
218
4,198,400
import itertools n = int(input()) a = map(int, input().split()) a = list(itertools.accumulate(a)) need_one = a[-1] // n ans = 0 for i in range(len(a) - 1): ans += abs((i + 1) * need_one - a[i]) print(ans)
Title: Balancer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configuration? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*. Output Specification: Print the total minimum number of moves. Demo Input: ['6\n1 6 2 5 3 7\n'] Demo Output: ['12\n'] Note: none
```python import itertools n = int(input()) a = map(int, input().split()) a = list(itertools.accumulate(a)) need_one = a[-1] // n ans = 0 for i in range(len(a) - 1): ans += abs((i + 1) * need_one - a[i]) print(ans) ```
3
549
H
Degenerate Matrix
PROGRAMMING
2,100
[ "binary search", "math" ]
null
null
The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||.
The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*.
Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9.
[ "1 2\n3 4\n", "1 0\n0 1\n" ]
[ "0.2000000000\n", "0.5000000000\n" ]
In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a07c34fbc6e9328bcb519d3f780eea6e02e5dc87.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,500
[ { "input": "1 2\n3 4", "output": "0.2000000000" }, { "input": "1 0\n0 1", "output": "0.5000000000" }, { "input": "1000000000 0\n0 1000000000", "output": "500000000.0000000000" }, { "input": "8205 9482\n11 -63", "output": "35.0198432832" }, { "input": "0 0\n0 0", "output": "0.0000000000" }, { "input": "1000000000 -1000000000\n1000000000 1000000000", "output": "1000000000.0000000000" }, { "input": "1000000000 1000000000\n1000000000 -1000000000", "output": "1000000000.0000000000" }, { "input": "-1 -1\n1 0", "output": "0.3333333333" }, { "input": "5 2\n-15 -6", "output": "0.0000000000" }, { "input": "2 -5\n-3 2", "output": "0.9166666667" }, { "input": "-5 -2\n-1 -3", "output": "1.1818181818" }, { "input": "-5 8\n1 6", "output": "2.1111111111" }, { "input": "1 3\n3 2", "output": "0.7777777778" }, { "input": "-42 63\n77 -32", "output": "16.3878504673" }, { "input": "91 -7\n-21 91", "output": "38.7333333333" }, { "input": "-67 -77\n-56 -75", "output": "2.5927272727" }, { "input": "-26 53\n-48 -89", "output": "29.6219512195" }, { "input": "97 -934\n-707 184", "output": "334.2819979188" }, { "input": "689 412\n-794 -421", "output": "16.0012953368" }, { "input": "-718 -387\n972 972", "output": "105.5204985241" }, { "input": "-126 -376\n75 367", "output": "19.1122881356" }, { "input": "-7 -3674\n845 5737", "output": "298.5843320666" }, { "input": "-9912 755\n-8220 6419", "output": "2268.9886983324" }, { "input": "-3928 5185\n4331 6665", "output": "3969.3426099731" }, { "input": "2056 9614\n-5171 8965", "output": "3141.2387756983" }, { "input": "41642 63236\n-59604 20357", "output": "32033.4760659150" }, { "input": "-38387 -93294\n-52918 -51288", "output": "12582.8868737997" }, { "input": "92812 73253\n-46231 11374", "output": "22109.0927374802" }, { "input": "12784 -94506\n26149 85264", "output": "18439.1869417765" }, { "input": "955162 -709099\n-743655 578837", "output": "8557.1487662354" }, { "input": "160382 -103968\n301943 -156088", "output": "8802.4244934460" }, { "input": "-634398 -468280\n447621 78431", "output": "98147.3248125840" }, { "input": "-398622 -832591\n-506781 -656493", "output": "66924.0413186624" }, { "input": "-2665612 -7693032\n-2861368 -6201836", "output": "282203.1726406262" }, { "input": "1762462 700391\n-7134185 5042962", "output": "1048758.9114990780" }, { "input": "6190536 5693104\n-8006293 -3712238", "output": "957535.4624752104" }, { "input": "553632 5653328\n-7246622 9164341", "output": "2140390.1895580233" }, { "input": "43469186 94408326\n78066381 -19616812", "output": "41883387.4306073852" }, { "input": "25683826 49101909\n88380777 46573745", "output": "14987456.1603828062" }, { "input": "-87068851 98762810\n3727856 -87235696", "output": "26110777.7289122988" }, { "input": "95145788 53456393\n42406028 83987544", "output": "20815549.6776987243" }, { "input": "876432079 -414820618\n-816514132 -914565422", "output": "520028295.4718751899" }, { "input": "-240038673 376842703\n-241080203 410087456", "output": "5983627.7655281517" }, { "input": "938457872 -536526676\n867891897 -855194260", "output": "105349963.0995401485" }, { "input": "116954418 255136645\n-851641472 174491320", "output": "204147910.8375163887" }, { "input": "1 1\n1 5", "output": "0.5000000000" }, { "input": "1 5\n1 1", "output": "0.5000000000" }, { "input": "5 1\n1 1", "output": "0.5000000000" }, { "input": "1 1\n5 1", "output": "0.5000000000" }, { "input": "-1000000000 -1000000000\n1000000000 1000000000", "output": "0.0000000000" }, { "input": "-1000000000 -1000000000\n999999999 999999999", "output": "0.0000000000" }, { "input": "536870912 88\n536870912 22528", "output": "11219.7636804586" }, { "input": "268435456 268435456\n22512 22528", "output": "7.9993289080" }, { "input": "-1 1\n1 1", "output": "1.0000000000" }, { "input": "-1000 -999\n-1 0", "output": "0.4995000000" }, { "input": "-801658422 -738703776\n910442649 -920729415", "output": "744753719.5468964978" }, { "input": "-203893419 -777818\n295920256 -474540430", "output": "99618123.5339717944" }, { "input": "448944609 529185527\n946362390 958011342", "output": "24529803.2444389601" }, { "input": "348741875 -606207234\n-279810821 -14278204", "output": "143060520.9047362779" }, { "input": "-202195424 182466434\n-722509868 -838173079", "output": "190651913.7089770083" }, { "input": "-48 9\n17 -67", "output": "21.7234042553" }, { "input": "12 180\n79 47", "output": "42.9433962264" }, { "input": "-131 -87\n-66 -109", "output": "21.7226463104" }, { "input": "171 17\n9 93", "output": "54.3103448276" }, { "input": "221 20\n-22 -200", "output": "94.5140388769" }, { "input": "372 -352\n-160 -423", "output": "216.4903748734" }, { "input": "480 37\n-3 -459", "output": "224.9325842697" }, { "input": "-535 -395\n-264 513", "output": "321.2340966921" }, { "input": "-498 -685\n-532 526", "output": "503.1068273092" }, { "input": "-16 450\n-848 27", "output": "284.2416107383" }, { "input": "-621967643 610314360\n-660274542 -772630232", "output": "611623765.8647500770" }, { "input": "222416863 97256131\n897661932 -426944193", "output": "125718637.9005708302" }, { "input": "67861199 302935298\n883117733 559626116", "output": "126575973.2879779836" }, { "input": "1000000000 1\n1000000000 2", "output": "0.4999999993" }, { "input": "-2 1\n1 -2", "output": "0.5000000000" }, { "input": "1000000000 999999995\n99999999 -199992543", "output": "142854098.7306812546" } ]
1,512,313,808
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
5,529,600
f = lambda: map(int, input().split()) a, b = f() c, d = f() x = abs((a * d - b * c) / (a - c)) y = abs((a * d - b * c) / (d - b)) u = abs(a * a - c * c) / 2 v = abs(b * b - d * d) / 2 print(min(x * y / (x + y), abs((u - v) / (a + b + c + d))))
Title: Degenerate Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||. Input Specification: The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*. Output Specification: Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. Demo Input: ['1 2\n3 4\n', '1 0\n0 1\n'] Demo Output: ['0.2000000000\n', '0.5000000000\n'] Note: In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a07c34fbc6e9328bcb519d3f780eea6e02e5dc87.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python f = lambda: map(int, input().split()) a, b = f() c, d = f() x = abs((a * d - b * c) / (a - c)) y = abs((a * d - b * c) / (d - b)) u = abs(a * a - c * c) / 2 v = abs(b * b - d * d) / 2 print(min(x * y / (x + y), abs((u - v) / (a + b + c + d)))) ```
0
180
C
Letter
PROGRAMMING
1,400
[ "dp" ]
null
null
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Print a single number — the least number of actions needed to make the message fancy.
[ "PRuvetSTAaYA\n", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "helloworld\n" ]
[ "5\n", "0\n", "0\n" ]
none
0
[ { "input": "PRuvetSTAaYA", "output": "5" }, { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0" }, { "input": "helloworld", "output": "0" }, { "input": "P", "output": "0" }, { "input": "t", "output": "0" }, { "input": "XdJ", "output": "1" }, { "input": "FSFlNEelYY", "output": "3" }, { "input": "lgtyasficu", "output": "0" }, { "input": "WYKUDTDDBT", "output": "0" }, { "input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd", "output": "0" }, { "input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu", "output": "43" }, { "input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR", "output": "13" }, { "input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi", "output": "27" }, { "input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn", "output": "31" } ]
1,575,117,428
2,147,483,647
PyPy 3
OK
TESTS
40
310
2,355,200
s = input() up_cnt = 0 low_cnt = 0 for i in s: if i.isupper(): up_cnt += 1 else: low_cnt += 1 cur_up = 0 cur_low = 0 ans = 1000000000 cost = up_cnt for i in s: if i.isupper(): cur_up += 1 else: cur_low += 1 a = cur_low + up_cnt - cur_up if a < ans: ans = a print(min(ans, up_cnt))
Title: Letter Time Limit: None seconds Memory Limit: None megabytes Problem Description: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. Input Specification: The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. Output Specification: Print a single number — the least number of actions needed to make the message fancy. Demo Input: ['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n'] Demo Output: ['5\n', '0\n', '0\n'] Note: none
```python s = input() up_cnt = 0 low_cnt = 0 for i in s: if i.isupper(): up_cnt += 1 else: low_cnt += 1 cur_up = 0 cur_low = 0 ans = 1000000000 cost = up_cnt for i in s: if i.isupper(): cur_up += 1 else: cur_low += 1 a = cur_low + up_cnt - cur_up if a < ans: ans = a print(min(ans, up_cnt)) ```
3
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,443,893,347
2,647
Python 3
WRONG_ANSWER
PRETESTS
0
46
0
#!/usr/bin/python3 ''' Created on Sep 25, 2015 @author: kate ''' n = int(input()) x = y = [0 for i in range(n+1)] res = [] for i in range(n ** 2): roads =[int(j) for j in input().split()] if x[roads[0]] == 0 and y[roads[1]] == 0: res.append(i + 1) x[roads[0]] = y[roads[1]] = 1 print (sorted(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 #!/usr/bin/python3 ''' Created on Sep 25, 2015 @author: kate ''' n = int(input()) x = y = [0 for i in range(n+1)] res = [] for i in range(n ** 2): roads =[int(j) for j in input().split()] if x[roads[0]] == 0 and y[roads[1]] == 0: res.append(i + 1) x[roads[0]] = y[roads[1]] = 1 print (sorted(res)) ```
0
765
B
Code obfuscation
PROGRAMMING
1,100
[ "greedy", "implementation", "strings" ]
null
null
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs. You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
[ "abacaba\n", "jinotega\n" ]
[ "YES\n", "NO\n" ]
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
1,000
[ { "input": "abacaba", "output": "YES" }, { "input": "jinotega", "output": "NO" }, { "input": "aaaaaaaaaaa", "output": "YES" }, { "input": "aba", "output": "YES" }, { "input": "bab", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "YES" }, { "input": "fihyxmbnzq", "output": "NO" }, { "input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr", "output": "NO" }, { "input": "bbbbbb", "output": "NO" }, { "input": "aabbbd", "output": "NO" }, { "input": "abdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "abcdeghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "abcdefghijklmnopqrsuvwxyz", "output": "NO" }, { "input": "abcdefghijklmnopqrstuvwxy", "output": "YES" }, { "input": "abcdefghijklmnopqrsutvwxyz", "output": "NO" }, { "input": "acdef", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa", "output": "YES" }, { "input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc", "output": "YES" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg", "output": "NO" }, { "input": "b", "output": "NO" }, { "input": "ac", "output": "NO" }, { "input": "cde", "output": "NO" }, { "input": "abd", "output": "NO" }, { "input": "zx", "output": "NO" }, { "input": "bcd", "output": "NO" }, { "input": "aaac", "output": "NO" }, { "input": "aacb", "output": "NO" }, { "input": "acd", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "NO" }, { "input": "abcdefghijklmnopqrstuvwxyzz", "output": "YES" }, { "input": "bc", "output": "NO" }, { "input": "aaaaaaaaad", "output": "NO" }, { "input": "abb", "output": "YES" }, { "input": "abcb", "output": "YES" }, { "input": "aac", "output": "NO" }, { "input": "abcbcb", "output": "YES" }, { "input": "bb", "output": "NO" }, { "input": "abbb", "output": "YES" }, { "input": "bbb", "output": "NO" }, { "input": "x", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz", "output": "NO" }, { "input": "acbccccccccccc", "output": "NO" }, { "input": "za", "output": "NO" }, { "input": "ade", "output": "NO" }, { "input": "bbbbbbbbbb", "output": "NO" }, { "input": "bac", "output": "NO" }, { "input": "bcddcb", "output": "NO" }, { "input": "aaacb", "output": "NO" }, { "input": "aaaaac", "output": "NO" }, { "input": "aaaaaaaaaaad", "output": "NO" }, { "input": "c", "output": "NO" }, { "input": "abcccccccc", "output": "YES" }, { "input": "aaaaaaac", "output": "NO" } ]
1,580,477,676
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
s = input() l = list(s) s1 = set(l) if(len(l)!=len(s1)): print("NO") else: print("YES")
Title: Code obfuscation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs. You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation. Input Specification: In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. Output Specification: If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". Demo Input: ['abacaba\n', 'jinotega\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
```python s = input() l = list(s) s1 = set(l) if(len(l)!=len(s1)): print("NO") else: print("YES") ```
0
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2", "output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10" }, { "input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6", "output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4" }, { "input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9", "output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6" }, { "input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2", "output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4" } ]
1,650,679,378
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
614,400
from sys import stdin input=lambda :stdin.readline()[:-1] #UnionFind from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] h,w,q=map(int,input().split()) def conv(i,j):return w*i+j uf=UnionFind(h*w) s=[] for _ in range(h): s.append(input()) dxdy=[(0,1),(1,0)] for x1 in range(h-1): for y1 in range(w-1): for dx,dy in dxdy: x2,y2=x1+dx,y1+dy if s[x1][y1]==s[x2][y2]=='.': uf.union(conv(x1,y1),conv(x2,y2)) for _ in range(q): x,y=map(int,input().split()) print(2*uf.size(conv(x-1,y-1))+2)
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. Input Specification: First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. Output Specification: Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. Demo Input: ['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n'] Demo Output: ['6\n4\n10\n', '8\n'] Note: none
```python from sys import stdin input=lambda :stdin.readline()[:-1] #UnionFind from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] h,w,q=map(int,input().split()) def conv(i,j):return w*i+j uf=UnionFind(h*w) s=[] for _ in range(h): s.append(input()) dxdy=[(0,1),(1,0)] for x1 in range(h-1): for y1 in range(w-1): for dx,dy in dxdy: x2,y2=x1+dx,y1+dy if s[x1][y1]==s[x2][y2]=='.': uf.union(conv(x1,y1),conv(x2,y2)) for _ in range(q): x,y=map(int,input().split()) print(2*uf.size(conv(x-1,y-1))+2) ```
0
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,541,589,931
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
109
0
a=int(input()) if a/2==0: b=a/2-1 c=a-b else: b=a//2 c=a-b print(b+" "+c)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python a=int(input()) if a/2==0: b=a/2-1 c=a-b else: b=a//2 c=a-b print(b+" "+c) ```
-1
946
C
String Transformation
PROGRAMMING
1,300
[ "greedy", "strings" ]
null
null
You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters.
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
[ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n" ]
[ "abcdefghijklmnopqrstuvwxyz\n", "-1\n" ]
none
0
[ { "input": "aacceeggiikkmmooqqssuuwwyy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "thereisnoanswer", "output": "-1" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs", "output": "-1" }, { "input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa" }, { "input": "abcdefghijklmnopqrstuvwxxx", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxya", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "cdaaaaaaaaabcdjklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "zazaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zazbcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abbbefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaa" }, { "input": "abcdefghijklmaopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvwxyx", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaz" }, { "input": "zaaaazaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zabcdzefghijklmnopqrstuvwxyzaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa" }, { "input": "aaaaaafghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyzz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyzaaaaaz" }, { "input": "abcdefghijklmnopqrstuvwaxy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaa" }, { "input": "abcdefghijklmnapqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abcdefghijklmnopqrstuvnxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaa" }, { "input": "abcdefghijklmnopqrstuvwxyzzzz", "output": "abcdefghijklmnopqrstuvwxyzzzz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aacceeggiikkmmooqqssuuwwya", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aacdefghijklmnopqrstuvwxyyy", "output": "abcdefghijklmnopqrstuvwxyzy" }, { "input": "abcaefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zaaacaaaaaaaaaaaaaaaaaaaayy", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "abcdedccdcdccdcdcdcdcdcddccdcdcdc", "output": "abcdefghijklmnopqrstuvwxyzcdcdcdc" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "abcdecdcdcddcdcdcdcdcdcdcd", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "a", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaa" }, { "input": "aaadefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaa" }, { "input": "abbbbbbbbbbbbbbbbbbbbbbbbz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aacceeggiikkmmaacceeggiikkmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy", "output": "abcdefghijklmnopqrstuvwxyzmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaap", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zabcdefghijklmnopqrstuvwxyz", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "rveviaomdienfygifatviahordebxazoxflfgzslhyzowhxbhqzpsgellkoimnwkvhpbijorhpggwfjexivpqbcbmqjyghkbq", "output": "rveviaomdienfygifbtvichordefxgzoxhlijzslkyzowlxmnqzpsopqrstuvwxyzhpbijorhpggwfjexivpqbcbmqjyghkbq" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "xtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknly", "output": "xtlsgypsfadpooefxzbcoejuvpvdeoygpofylgphnpljvrvipyjmyklwqnqrqpmxunopqrvstwuxwvwxyzbxcoksfzkvatxdknly" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxsa", "output": "jqcfvsavebixhiocdefphgmsmhijkylwsmpynoypqrxstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh", "output": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldcefsdrefynghiyjkxxplmornopqrstuvwxyzopkmcoqh" }, { "input": "abadefghijklmnopqrstuvwxyz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "zazsazcbbbbbbbbbbbbbbbbbbbbbbb", "output": "zazsbzcdefghijklmnopqrstuvwxyz" }, { "input": "zazsazcbbbbbbbbbbbbbbbbbbbbbyb", "output": "zazsbzcdefghijklmnopqrstuvwxyz" }, { "input": "bbcdefghijklmnopqrstuvwxyzzz", "output": "-1" }, { "input": "zaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zabcdefghijklmnopqrstuvwxyz" }, { "input": "zzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "zzzzzabcdefghijklmnopqrstuvwxyza" }, { "input": "kkimnfjbbgggicykcciwtoazomcvisigagkjwhyrmojmoebnqoadpmockfjxibdtvrbedrsdoundbcpkfdqdidqdmxdltink", "output": "kkimnfjbbgggicykcciwtoazomcvisigbgkjwhyrmojmoecnqodepmofkgjxihitvrjklrsmounopqrstuvwxyzdmxdltink" }, { "input": "cawgathqceccscakbazmhwbefvygjbcfyihcbgga", "output": "-1" }, { "input": "acrsbyszsbfslzbqzzamcmrypictkcheddehvxdipaxaannjodzyfxgtfnwababzjraapqbqbfzhbiewlzz", "output": "acrsbyszscfslzdqzzemfmrypigtkhijklmnvxopqrxstuvwxyzyfxgtfnwababzjraapqbqbfzhbiewlzz" }, { "input": "ggcebbheeblbioxdvtlrtkxeuilonazpebcbqpzz", "output": "-1" }, { "input": "zzzzabcdefghijklmnopqrstuvwxy", "output": "-1" }, { "input": "zabcdefghijklmnopqrstuvwxy", "output": "-1" }, { "input": "babcdefghijklmnopqrstuvwxyz", "output": "babcdefghijklmnopqrstuvwxyz" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } ]
1,669,052,833
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
import bisect def transform_str(s): if len(s) < 26: return None pos_list = [] for i in range(26): pos_list.append([]) for i in range(len(s)): pos_list[ord(s[i]) - ord('a')] += [i] not_greater_pos = [] for i in range(26): if i == 0: not_greater_pos += [pos_list[i]] else: not_greater_pos += [not_greater_pos[i-1]] prev_pos = -1 res = [*s] for i in range(26): if not not_greater_pos[i] or prev_pos >= not_greater_pos[i][-1]: return None curr_pos = bisect.bisect(not_greater_pos[i], prev_pos) res[curr_pos] = chr(i + ord('a')) return "".join(res) if __name__ == "__main__": s = input() t = transform_str(s) if t is None: print(-1) else: print(t)
Title: String Transformation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible. Input Specification: The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. Output Specification: If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). Demo Input: ['aacceeggiikkmmooqqssuuwwyy\n', 'thereisnoanswer\n'] Demo Output: ['abcdefghijklmnopqrstuvwxyz\n', '-1\n'] Note: none
```python import bisect def transform_str(s): if len(s) < 26: return None pos_list = [] for i in range(26): pos_list.append([]) for i in range(len(s)): pos_list[ord(s[i]) - ord('a')] += [i] not_greater_pos = [] for i in range(26): if i == 0: not_greater_pos += [pos_list[i]] else: not_greater_pos += [not_greater_pos[i-1]] prev_pos = -1 res = [*s] for i in range(26): if not not_greater_pos[i] or prev_pos >= not_greater_pos[i][-1]: return None curr_pos = bisect.bisect(not_greater_pos[i], prev_pos) res[curr_pos] = chr(i + ord('a')) return "".join(res) if __name__ == "__main__": s = input() t = transform_str(s) if t is None: print(-1) else: print(t) ```
0
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "6 0\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "1 3\n1000000000", "output": "0" }, { "input": "1 9\n1000000000", "output": "0" }, { "input": "1 0\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 3\n1", "output": "0" }, { "input": "1 9\n1", "output": "0" }, { "input": "2 8\n123456780\n123", "output": "1" }, { "input": "2 8\n12345678\n1230", "output": "0" }, { "input": "6 1\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "6 2\n10\n102\n120\n1032\n1212103\n1999999", "output": "4" }, { "input": "6 3\n10\n102\n120\n1032\n1212103\n1999999", "output": "2" }, { "input": "6 9\n10\n102\n120\n1032\n1212103\n1999999", "output": "0" }, { "input": "1 2\n2220", "output": "0" } ]
1,639,826,389
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n,k = map(int,input().split()) count = 0 for i in range(n): a = input() a = list(map(int,a)) if sorted(list(a)) == [b for b in range(k+1)]: count+=1 print(count)
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). Input Specification: The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the number of *k*-good numbers in *a*. Demo Input: ['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n'] Demo Output: ['10\n', '1\n'] Note: none
```python n,k = map(int,input().split()) count = 0 for i in range(n): a = input() a = list(map(int,a)) if sorted(list(a)) == [b for b in range(k+1)]: count+=1 print(count) ```
0
911
A
Nearest Minimums
PROGRAMMING
1,100
[ "implementation" ]
null
null
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Print the only number — distance between two nearest minimums in the array.
[ "2\n3 3\n", "3\n5 6 5\n", "9\n2 1 3 5 4 1 2 3 1\n" ]
[ "1\n", "2\n", "3\n" ]
none
0
[ { "input": "2\n3 3", "output": "1" }, { "input": "3\n5 6 5", "output": "2" }, { "input": "9\n2 1 3 5 4 1 2 3 1", "output": "3" }, { "input": "6\n4 6 7 8 6 4", "output": "5" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "42\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", "output": "1" }, { "input": "2\n10000000 10000000", "output": "1" }, { "input": "5\n100000000 100000001 100000000 100000001 100000000", "output": "2" }, { "input": "9\n4 3 4 3 4 1 3 3 1", "output": "3" }, { "input": "3\n10000000 1000000000 10000000", "output": "2" }, { "input": "12\n5 6 6 5 6 1 9 9 9 9 9 1", "output": "6" }, { "input": "5\n5 5 1 2 1", "output": "2" }, { "input": "5\n2 2 1 3 1", "output": "2" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "1" }, { "input": "3\n100000005 1000000000 100000005", "output": "2" }, { "input": "5\n1 2 2 2 1", "output": "4" }, { "input": "3\n10000 1000000 10000", "output": "2" }, { "input": "3\n999999999 999999998 999999998", "output": "1" }, { "input": "6\n2 1 1 2 3 4", "output": "1" }, { "input": "4\n1000000000 900000000 900000000 1000000000", "output": "1" }, { "input": "5\n7 7 2 7 2", "output": "2" }, { "input": "6\n10 10 1 20 20 1", "output": "3" }, { "input": "2\n999999999 999999999", "output": "1" }, { "input": "10\n100000 100000 1 2 3 4 5 6 7 1", "output": "7" }, { "input": "10\n3 3 1 2 2 1 10 10 10 10", "output": "3" }, { "input": "5\n900000000 900000001 900000000 900000001 900000001", "output": "2" }, { "input": "5\n3 3 2 5 2", "output": "2" }, { "input": "2\n100000000 100000000", "output": "1" }, { "input": "10\n10 15 10 2 54 54 54 54 2 10", "output": "5" }, { "input": "2\n999999 999999", "output": "1" }, { "input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "5\n1000000000 100000000 1000000000 1000000000 100000000", "output": "3" }, { "input": "4\n10 9 10 9", "output": "2" }, { "input": "5\n1 3 2 3 1", "output": "4" }, { "input": "5\n2 2 1 4 1", "output": "2" }, { "input": "6\n1 2 2 2 2 1", "output": "5" }, { "input": "7\n3 7 6 7 6 7 3", "output": "6" }, { "input": "8\n1 2 2 2 2 1 2 2", "output": "5" }, { "input": "10\n2 2 2 3 3 1 3 3 3 1", "output": "4" }, { "input": "2\n88888888 88888888", "output": "1" }, { "input": "3\n100000000 100000000 100000000", "output": "1" }, { "input": "10\n1 3 2 4 5 5 4 3 2 1", "output": "9" }, { "input": "5\n2 2 1 2 1", "output": "2" }, { "input": "6\n900000005 900000000 900000001 900000000 900000001 900000001", "output": "2" }, { "input": "5\n41 41 1 41 1", "output": "2" }, { "input": "6\n5 5 1 3 3 1", "output": "3" }, { "input": "8\n1 2 2 2 1 2 2 2", "output": "4" }, { "input": "7\n6 6 6 6 1 8 1", "output": "2" }, { "input": "3\n999999999 1000000000 999999999", "output": "2" }, { "input": "5\n5 5 4 10 4", "output": "2" }, { "input": "11\n2 2 3 4 1 5 3 4 2 5 1", "output": "6" }, { "input": "5\n3 5 4 5 3", "output": "4" }, { "input": "6\n6 6 6 6 1 1", "output": "1" }, { "input": "7\n11 1 3 2 3 1 11", "output": "4" }, { "input": "5\n3 3 1 2 1", "output": "2" }, { "input": "5\n4 4 2 5 2", "output": "2" }, { "input": "4\n10000099 10000567 10000099 10000234", "output": "2" }, { "input": "4\n100000009 100000011 100000012 100000009", "output": "3" }, { "input": "2\n1000000 1000000", "output": "1" }, { "input": "2\n10000010 10000010", "output": "1" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "8\n2 6 2 8 1 9 8 1", "output": "3" }, { "input": "5\n7 7 1 8 1", "output": "2" }, { "input": "7\n1 3 2 3 2 3 1", "output": "6" }, { "input": "7\n2 3 2 1 3 4 1", "output": "3" }, { "input": "5\n1000000000 999999999 1000000000 1000000000 999999999", "output": "3" }, { "input": "4\n1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "5\n5 5 3 5 3", "output": "2" }, { "input": "6\n2 3 3 3 3 2", "output": "5" }, { "input": "4\n1 1 2 2", "output": "1" }, { "input": "5\n1 1 2 2 2", "output": "1" }, { "input": "6\n2 1 1 2 2 2", "output": "1" }, { "input": "5\n1000000000 1000000000 100000000 1000000000 100000000", "output": "2" }, { "input": "7\n2 2 1 1 2 2 2", "output": "1" }, { "input": "8\n2 2 2 1 1 2 2 2", "output": "1" }, { "input": "10\n2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "11\n2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "12\n2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "13\n2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "4\n1000000000 100000000 100000000 1000000000", "output": "1" }, { "input": "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2", "output": "1" }, { "input": "4\n1 2 3 1", "output": "3" }, { "input": "8\n5 5 5 5 3 5 5 3", "output": "3" }, { "input": "7\n2 3 2 1 4 4 1", "output": "3" }, { "input": "6\n3 3 1 2 4 1", "output": "3" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "5\n3 3 2 8 2", "output": "2" }, { "input": "5\n1 2 1 2 2", "output": "2" }, { "input": "4\n1 2 1 2", "output": "2" }, { "input": "5\n3 1 1 3 2", "output": "1" }, { "input": "4\n1 1 2 1", "output": "1" }, { "input": "4\n2 2 1 1", "output": "1" }, { "input": "5\n1 2 2 1 2", "output": "3" }, { "input": "7\n2 1 2 1 1 2 1", "output": "1" }, { "input": "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000", "output": "4" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "85\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 1", "output": "84" }, { "input": "5\n1000000000 1000000000 999999999 1000000000 999999999", "output": "2" }, { "input": "5\n2 1 2 2 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n1 2 1 1", "output": "1" }, { "input": "6\n1 3 4 2 4 1", "output": "5" }, { "input": "9\n2 2 5 1 6 8 7 9 1", "output": "5" }, { "input": "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999", "output": "6" }, { "input": "7\n3 3 1 2 4 1 2", "output": "3" }, { "input": "7\n3 3 1 2 3 4 1", "output": "4" }, { "input": "8\n10 5 10 1 10 10 10 1", "output": "4" } ]
1,589,237,582
2,147,483,647
Python 3
OK
TESTS
140
187
9,523,200
_=int(input()) A=list(map(int,input().split())) xmin=min(*A) index=[] for i in range(len(A)): if A[i]==xmin: index.append(i) m=[] for i in range(len(index)-1): m.append(index[i+1]-index[i]) print(min(m))
Title: Nearest Minimums Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. Input Specification: The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. Output Specification: Print the only number — distance between two nearest minimums in the array. Demo Input: ['2\n3 3\n', '3\n5 6 5\n', '9\n2 1 3 5 4 1 2 3 1\n'] Demo Output: ['1\n', '2\n', '3\n'] Note: none
```python _=int(input()) A=list(map(int,input().split())) xmin=min(*A) index=[] for i in range(len(A)): if A[i]==xmin: index.append(i) m=[] for i in range(len(index)-1): m.append(index[i+1]-index[i]) print(min(m)) ```
3
779
A
Pupils Redistribution
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and 5. The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal. To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class *A* and one student of class *B*. After that, they both change their groups. Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups. The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*. The third line contains sequence of integer numbers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=5), where *b**i* is academic performance of the *i*-th student of the group *B*.
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
[ "4\n5 4 4 4\n5 5 4 5\n", "6\n1 1 1 1 1 1\n5 5 5 5 5 5\n", "1\n5\n3\n", "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n" ]
[ "1\n", "3\n", "-1\n", "4\n" ]
none
500
[ { "input": "4\n5 4 4 4\n5 5 4 5", "output": "1" }, { "input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5", "output": "3" }, { "input": "1\n5\n3", "output": "-1" }, { "input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1", "output": "4" }, { "input": "1\n1\n2", "output": "-1" }, { "input": "1\n1\n1", "output": "0" }, { "input": "8\n1 1 2 2 3 3 4 4\n4 4 5 5 1 1 1 1", "output": "2" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1\n2 2 2 2 2 2 2 2 2 2", "output": "5" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "2\n1 2\n1 1", "output": "-1" }, { "input": "2\n2 2\n1 1", "output": "1" }, { "input": "2\n1 2\n2 1", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "1" }, { "input": "5\n5 5 5 5 5\n5 5 5 5 5", "output": "0" }, { "input": "5\n5 5 5 3 5\n5 3 5 5 5", "output": "0" }, { "input": "5\n2 3 2 3 3\n2 3 2 2 2", "output": "1" }, { "input": "5\n4 4 1 4 2\n1 2 4 2 2", "output": "1" }, { "input": "50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "50\n1 3 1 3 3 3 1 3 3 3 3 1 1 1 3 3 3 1 3 1 1 1 3 1 3 1 3 3 3 1 3 1 1 3 3 3 1 1 1 1 3 3 1 1 1 3 3 1 1 1\n1 3 1 3 3 1 1 3 1 3 3 1 1 1 1 3 3 1 3 1 1 3 1 1 3 1 1 1 1 3 3 1 3 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 3 1", "output": "0" }, { "input": "50\n1 1 1 4 1 1 4 1 4 1 1 4 1 1 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 4 4 4 4 4 4 1 4 1 1 1 1 4 1 4 4 1 1 1 4\n1 4 4 1 1 4 1 4 4 1 1 4 1 4 1 1 4 1 1 1 4 4 1 1 4 1 4 1 1 4 4 4 4 1 1 4 4 1 1 1 4 1 4 1 4 1 1 1 4 4", "output": "0" }, { "input": "50\n3 5 1 3 3 4 3 4 2 5 2 1 2 2 5 5 4 5 4 2 1 3 4 2 3 3 3 2 4 3 5 5 5 5 5 5 2 5 2 2 5 4 4 1 5 3 4 2 1 3\n3 5 3 2 5 3 4 4 5 2 3 4 4 4 2 2 4 4 4 3 3 5 5 4 3 1 4 4 5 5 4 1 2 5 5 4 1 2 3 4 5 5 3 2 3 4 3 5 1 1", "output": "3" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "100\n1 1 3 1 3 1 1 3 1 1 3 1 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 1 1 3 1 1 1 3 1 1 3 3 1 3 3 1 3 1 3 3 3 3 1 1 3 3 3 1 1 3 1 3 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3 1 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 1 3 1 1 1\n1 1 1 3 3 3 3 3 3 3 1 3 3 3 1 3 3 3 3 3 3 1 3 3 1 3 3 1 1 1 3 3 3 3 3 3 3 1 1 3 3 3 1 1 3 3 1 1 1 3 3 3 1 1 3 1 1 3 3 1 1 3 3 3 3 3 3 1 3 3 3 1 1 3 3 3 1 1 3 3 1 3 1 3 3 1 1 3 3 1 1 3 1 3 3 3 1 3 1 3", "output": "0" }, { "input": "100\n2 4 5 2 5 5 4 4 5 4 4 5 2 5 5 4 5 2 5 2 2 4 5 4 4 4 2 4 2 2 4 2 4 2 2 2 4 5 5 5 4 2 4 5 4 4 2 5 4 2 5 4 5 4 5 4 5 5 5 4 2 2 4 5 2 5 5 2 5 2 4 4 4 5 5 2 2 2 4 4 2 2 2 5 5 2 2 4 5 4 2 4 4 2 5 2 4 4 4 4\n4 4 2 5 2 2 4 2 5 2 5 4 4 5 2 4 5 4 5 2 2 2 2 5 4 5 2 4 2 2 5 2 5 2 4 5 5 5 2 5 4 4 4 4 5 2 2 4 2 4 2 4 5 5 5 4 5 4 5 5 5 2 5 4 4 4 4 4 2 5 5 4 2 4 4 5 5 2 4 4 4 2 2 2 5 4 2 2 4 5 4 4 4 4 2 2 4 5 5 2", "output": "0" }, { "input": "100\n3 3 4 3 3 4 3 1 4 2 1 3 1 1 2 4 4 4 4 1 1 4 1 4 4 1 1 2 3 3 3 2 4 2 3 3 3 1 3 4 2 2 1 3 4 4 3 2 2 2 4 2 1 2 1 2 2 1 1 4 2 1 3 2 4 4 4 2 3 1 3 1 3 2 2 2 2 4 4 1 3 1 1 4 2 3 3 4 4 2 4 4 2 4 3 3 1 3 2 4\n3 1 4 4 2 1 1 1 1 1 1 3 1 1 3 4 3 2 2 4 2 1 4 4 4 4 1 2 3 4 2 3 3 4 3 3 2 4 2 2 2 1 2 4 4 4 2 1 3 4 3 3 4 2 4 4 3 2 4 2 4 2 4 4 1 4 3 1 4 3 3 3 3 1 2 2 2 2 4 1 2 1 3 4 3 1 3 3 4 2 3 3 2 1 3 4 2 1 1 2", "output": "0" }, { "input": "100\n2 4 5 2 1 5 5 2 1 5 1 5 1 1 1 3 4 5 1 1 2 3 3 1 5 5 4 4 4 1 1 1 5 2 3 5 1 2 2 1 1 1 2 2 1 2 4 4 5 1 3 2 5 3 5 5 3 2 2 2 1 3 4 4 4 4 4 5 3 1 4 1 5 4 4 5 4 5 2 4 4 3 1 2 1 4 5 3 3 3 3 2 2 2 3 5 3 1 3 4\n3 2 5 1 5 4 4 3 5 5 5 2 1 4 4 3 2 3 3 5 5 4 5 5 2 1 2 4 4 3 5 1 1 5 1 3 2 5 2 4 4 2 4 2 4 2 3 2 5 1 4 4 1 1 1 5 3 5 1 1 4 5 1 1 2 2 5 3 5 1 1 1 2 3 3 2 3 2 4 4 5 4 2 1 3 4 1 1 2 4 1 5 3 1 2 1 3 4 1 3", "output": "0" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "100\n1 4 4 1 4 4 1 1 4 1 1 1 1 4 4 4 4 1 1 1 1 1 1 4 4 4 1 1 4 4 1 1 1 1 4 4 4 4 4 1 1 4 4 1 1 1 4 1 1 1 1 4 4 4 4 4 4 1 4 4 4 4 1 1 1 4 1 4 1 1 1 1 4 1 1 1 4 4 4 1 4 4 1 4 4 4 4 4 1 4 1 1 4 1 4 1 1 1 4 4\n4 1 1 4 4 4 1 4 4 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 1 1 1 4 4 1 4 1 4 1 4 4 1 1 4 1 4 1 1 1 4 1 4 4 4 1 4 1 4 4 4 4 1 4 1 1 4 1 1 4 4 4 1 4 1 4 1 4 4 4 1 1 4 1 4 4 4 4 1 1 1 1 1 4 4 1 4 1 4 1 1 1 4 4 1", "output": "1" }, { "input": "100\n5 2 5 2 2 3 3 2 5 3 2 5 3 3 3 5 2 2 5 5 3 3 5 3 2 2 2 3 2 2 2 2 3 5 3 3 2 3 2 5 3 3 5 3 2 2 5 5 5 5 5 2 3 2 2 2 2 3 2 5 2 2 2 3 5 5 5 3 2 2 2 3 5 3 2 5 5 3 5 5 5 3 2 5 2 3 5 3 2 5 5 3 5 2 3 3 2 2 2 2\n5 3 5 3 3 5 2 5 3 2 3 3 5 2 5 2 2 5 2 5 2 5 3 3 5 3 2 2 2 3 5 3 2 2 3 2 2 5 5 2 3 2 3 3 5 3 2 5 2 2 2 3 3 5 3 3 5 2 2 2 3 3 2 2 3 5 3 5 5 3 3 2 5 3 5 2 3 2 5 5 3 2 5 5 2 2 2 2 3 2 2 5 2 5 2 2 3 3 2 5", "output": "1" }, { "input": "100\n4 4 5 4 3 5 5 2 4 5 5 5 3 4 4 2 5 2 5 3 3 3 3 5 3 2 2 2 4 4 4 4 3 3 4 5 3 2 2 2 4 4 5 3 4 5 4 5 5 2 4 2 5 2 3 4 4 5 2 2 4 4 5 5 5 3 5 4 5 5 5 4 3 3 2 4 3 5 5 5 2 4 2 5 4 3 5 3 2 3 5 2 5 2 2 5 4 5 4 3\n5 4 2 4 3 5 2 5 5 3 4 5 4 5 3 3 5 5 2 3 4 2 3 5 2 2 2 4 2 5 2 4 4 5 2 2 4 4 5 5 2 3 4 2 4 5 2 5 2 2 4 5 5 3 5 5 5 4 3 4 4 3 5 5 3 4 5 3 2 3 4 3 4 4 2 5 3 4 5 5 3 5 3 3 4 3 5 3 2 2 4 5 4 5 5 2 3 4 3 5", "output": "1" }, { "input": "100\n1 4 2 2 2 1 4 5 5 5 4 4 5 5 1 3 2 1 4 5 2 3 4 4 5 4 4 4 4 5 1 3 5 5 3 3 3 3 5 1 4 3 5 1 2 4 1 3 5 5 1 3 3 3 1 3 5 4 4 2 2 5 5 5 2 3 2 5 1 3 5 4 5 3 2 2 3 2 3 3 2 5 2 4 2 3 4 1 3 1 3 1 5 1 5 2 3 5 4 5\n1 2 5 3 2 3 4 2 5 1 2 5 3 4 3 3 4 1 5 5 1 3 3 1 1 4 1 4 2 5 4 1 3 4 5 3 2 2 1 4 5 5 2 3 3 5 5 4 2 3 3 5 3 3 5 4 4 5 3 5 1 1 4 4 4 1 3 5 5 5 4 2 4 5 3 2 2 2 5 5 5 1 4 3 1 3 1 2 2 4 5 1 3 2 4 5 1 5 2 5", "output": "1" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "input": "100\n5 2 2 2 5 2 5 5 5 2 5 2 5 5 5 5 5 5 2 2 2 5 5 2 5 2 2 5 2 5 5 2 5 2 5 2 5 5 5 5 5 2 2 2 2 5 5 2 5 5 5 2 5 5 5 2 5 5 5 2 2 2 5 2 2 2 5 5 2 5 5 5 2 5 2 2 5 2 2 2 5 5 5 5 2 5 2 5 2 2 5 2 5 2 2 2 2 5 5 2\n5 5 2 2 5 5 2 5 2 2 5 5 5 5 2 5 5 2 5 2 2 5 2 2 5 2 5 2 2 5 2 5 2 5 5 2 2 5 5 5 2 5 5 2 5 5 5 2 2 5 5 5 2 5 5 5 2 2 2 5 5 5 2 2 5 5 2 2 2 5 2 5 5 2 5 2 5 2 2 5 5 2 2 5 5 2 2 5 2 2 5 2 2 2 5 5 2 2 2 5", "output": "1" }, { "input": "100\n3 3 2 2 1 2 3 3 2 2 1 1 3 3 1 1 1 2 1 2 3 2 3 3 3 1 2 3 1 2 1 2 3 3 2 1 1 1 1 1 2 2 3 2 1 1 3 3 1 3 3 1 3 1 3 3 3 2 1 2 3 1 3 2 2 2 2 2 2 3 1 3 1 2 2 1 2 3 2 3 3 1 2 1 1 3 1 1 1 2 1 2 2 2 3 2 3 2 1 1\n1 3 1 2 1 1 1 1 1 2 1 2 1 3 2 2 3 2 1 1 2 2 2 1 1 3 2 3 2 1 2 2 3 2 3 1 3 1 1 2 3 1 2 1 3 2 1 2 3 2 3 3 3 2 2 2 3 1 3 1 1 2 1 3 1 3 1 3 3 3 1 3 3 2 1 3 3 3 3 3 2 1 2 2 3 3 2 1 2 2 1 3 3 1 3 2 2 1 1 3", "output": "1" }, { "input": "100\n5 3 3 2 5 3 2 4 2 3 3 5 3 4 5 4 3 3 4 3 2 3 3 4 5 4 2 4 2 4 5 3 3 4 5 3 5 3 5 3 3 2 5 3 4 5 2 5 2 2 4 2 2 2 2 5 4 5 4 3 5 4 2 5 5 3 4 5 2 3 2 2 2 5 3 2 2 2 3 3 5 2 3 2 4 5 3 3 3 5 2 3 3 3 5 4 5 5 5 2\n4 4 4 5 5 3 5 5 4 3 5 4 3 4 3 3 5 3 5 5 3 3 3 5 5 4 4 3 2 5 4 3 3 4 5 3 5 2 4 2 2 2 5 3 5 2 5 5 3 3 2 3 3 4 2 5 2 5 2 4 2 4 2 3 3 4 2 2 2 4 4 3 3 3 4 3 3 3 5 5 3 4 2 2 3 5 5 2 3 4 5 4 5 3 4 2 5 3 2 4", "output": "3" }, { "input": "100\n5 3 4 4 2 5 1 1 4 4 3 5 5 1 4 4 2 5 3 2 1 1 3 2 4 4 4 2 5 2 2 3 1 4 1 4 4 5 3 5 1 4 1 4 1 5 5 3 5 5 1 5 3 5 1 3 3 4 5 3 2 2 4 5 2 5 4 2 4 4 1 1 4 2 4 1 2 2 4 3 4 1 1 1 4 3 5 1 2 1 4 5 4 4 2 1 4 1 3 2\n1 1 1 1 4 2 1 4 1 1 3 5 4 3 5 2 2 4 2 2 4 1 3 4 4 5 1 1 2 2 2 1 4 1 4 4 1 5 5 2 3 5 1 5 4 2 3 2 2 5 4 1 1 4 5 2 4 5 4 4 3 3 2 4 3 4 5 5 4 2 4 2 1 2 3 2 2 5 5 3 1 3 4 3 4 4 5 3 1 1 3 5 1 4 4 2 2 1 4 5", "output": "2" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "input": "100\n3 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 4 4 3 3 3 3 3 3 4 3 3 4 3 3 3 3 4 3 3 3 4 4 4 3 3 4 4 4 3 4 4 3 3 4 3 3 3 4 4 4 3 4 3 3 3 3 3 3 3 4 4 3 3 3 3 4 3 3 3 3 3 4 4 3 3 3 3 3 4 3 4 4 4 4 3 4 3 4 4 4 4 3 3\n4 3 3 3 3 4 4 3 4 4 4 3 3 4 4 3 4 4 4 4 3 4 3 3 3 4 4 4 3 4 3 4 4 3 3 4 3 3 3 3 3 4 3 3 3 3 4 4 4 3 3 4 3 4 4 4 4 3 4 4 3 3 4 3 3 4 3 4 3 4 4 4 4 3 3 4 3 4 4 4 3 3 4 4 4 4 4 3 3 3 4 3 3 4 3 3 3 3 3 3", "output": "5" }, { "input": "100\n4 2 5 2 5 4 2 5 5 4 4 2 4 4 2 4 4 5 2 5 5 2 2 4 4 5 4 5 5 5 2 2 2 2 4 4 5 2 4 4 4 2 2 5 5 4 5 4 4 2 4 5 4 2 4 5 4 2 4 5 4 4 4 4 4 5 4 2 5 2 5 5 5 5 4 2 5 5 4 4 2 5 2 5 2 5 4 2 4 2 4 5 2 5 2 4 2 4 2 4\n5 4 5 4 5 2 2 4 5 2 5 5 5 5 5 4 4 4 4 5 4 5 5 2 4 4 4 4 5 2 4 4 5 5 2 5 2 5 5 4 4 5 2 5 2 5 2 5 4 5 2 5 2 5 2 4 4 5 4 2 5 5 4 2 2 2 5 4 2 2 4 4 4 5 5 2 5 2 2 4 4 4 2 5 4 5 2 2 5 4 4 5 5 4 5 5 4 5 2 5", "output": "5" }, { "input": "100\n3 4 5 3 5 4 5 4 4 4 2 4 5 4 3 2 3 4 3 5 2 5 2 5 4 3 4 2 5 2 5 3 4 5 2 5 4 2 4 5 4 3 2 4 4 5 2 5 5 3 3 5 2 4 4 2 3 3 2 5 5 5 2 4 5 5 4 2 2 5 3 3 2 4 4 2 4 5 5 2 5 5 3 2 5 2 4 4 3 3 5 4 5 5 2 5 4 5 4 3\n4 3 5 5 2 4 2 4 5 5 5 2 3 3 3 3 5 5 5 5 3 5 2 3 5 2 3 2 2 5 5 3 5 3 4 2 2 5 3 3 3 3 5 2 4 5 3 5 3 4 4 4 5 5 3 4 4 2 2 4 4 5 3 2 4 5 5 4 5 2 2 3 5 4 5 5 2 5 4 3 2 3 2 5 4 5 3 4 5 5 3 5 2 2 4 4 3 2 5 2", "output": "4" }, { "input": "100\n4 1 1 2 1 4 4 1 4 5 5 5 2 2 1 3 5 2 1 5 2 1 2 4 4 2 1 2 2 2 4 3 1 4 2 2 3 1 1 4 4 5 4 4 4 5 1 4 1 4 3 1 2 1 2 4 1 2 5 2 1 4 3 4 1 4 2 1 1 1 5 3 3 1 4 1 3 1 4 1 1 2 2 2 3 1 4 3 4 4 5 2 5 4 3 3 3 2 2 1\n5 1 4 4 3 4 4 5 2 3 3 4 4 2 3 2 3 1 3 1 1 4 1 5 4 3 2 4 3 3 3 2 3 4 1 5 4 2 4 2 2 2 5 3 1 2 5 3 2 2 1 1 2 2 3 5 1 2 5 3 2 1 1 2 1 2 4 3 5 4 5 3 2 4 1 3 4 1 4 4 5 4 4 5 4 2 5 3 4 1 4 2 4 2 4 5 4 5 4 2", "output": "6" }, { "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\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": "0" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\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 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 1 3 1 3 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 4 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 1 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3", "output": "1" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1", "output": "25" }, { "input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4", "output": "50" }, { "input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "40" }, { "input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3", "output": "30" }, { "input": "5\n4 4 4 4 5\n4 5 5 5 5", "output": "-1" }, { "input": "4\n1 1 1 1\n3 3 3 3", "output": "2" }, { "input": "6\n1 1 2 2 3 4\n1 2 3 3 4 4", "output": "-1" }, { "input": "4\n1 1 1 2\n3 3 3 3", "output": "-1" }, { "input": "3\n2 2 2\n4 4 4", "output": "-1" }, { "input": "2\n1 2\n3 4", "output": "-1" }, { "input": "6\n1 1 1 3 3 3\n2 2 2 4 4 4", "output": "-1" }, { "input": "5\n1 2 2 2 2\n1 1 1 1 3", "output": "-1" }, { "input": "2\n1 3\n2 2", "output": "-1" }, { "input": "2\n1 3\n4 5", "output": "-1" }, { "input": "4\n1 2 3 4\n5 5 5 5", "output": "-1" }, { "input": "2\n1 3\n2 4", "output": "-1" }, { "input": "2\n1 2\n4 4", "output": "-1" }, { "input": "2\n1 2\n3 3", "output": "-1" }, { "input": "10\n4 4 4 4 2 3 3 3 3 1\n2 2 2 2 4 1 1 1 1 3", "output": "-1" }, { "input": "6\n1 2 3 3 4 4\n1 1 2 2 3 4", "output": "-1" }, { "input": "5\n3 3 3 3 1\n1 1 1 1 3", "output": "-1" }, { "input": "2\n1 1\n2 3", "output": "-1" }, { "input": "8\n1 1 2 2 3 3 3 3\n2 2 2 2 1 1 1 1", "output": "2" }, { "input": "5\n1 1 1 3 3\n1 1 1 1 2", "output": "-1" }, { "input": "6\n2 2 3 3 4 4\n2 3 4 5 5 5", "output": "-1" }, { "input": "6\n1 1 2 2 3 4\n3 3 4 4 1 2", "output": "-1" }, { "input": "4\n1 2 3 3\n3 3 3 3", "output": "-1" }, { "input": "3\n1 2 3\n3 3 3", "output": "-1" }, { "input": "5\n3 3 3 2 2\n2 2 2 3 3", "output": "-1" }, { "input": "10\n1 2 3 4 1 2 3 4 1 2\n1 2 3 4 1 2 3 4 3 4", "output": "-1" }, { "input": "2\n2 2\n1 3", "output": "-1" }, { "input": "3\n1 2 3\n1 1 4", "output": "-1" }, { "input": "4\n3 4 4 4\n3 3 4 4", "output": "-1" } ]
1,488,108,543
2,147,483,647
Python 3
OK
TESTS
81
62
4,608,000
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) aa = [0]*6 for v in a: aa[v] += 1 bb = [0]*6 for v in b: bb[v] += 1 res = sum(map(lambda x, y: max(x-y, 0), aa, bb)) if any(map(lambda x, y: (x-y) & 1, aa, bb)): print(-1) else: print(res//2)
Title: Pupils Redistribution Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and 5. The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal. To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class *A* and one student of class *B*. After that, they both change their groups. Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance. Input Specification: The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups. The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*. The third line contains sequence of integer numbers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=5), where *b**i* is academic performance of the *i*-th student of the group *B*. Output Specification: Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. Demo Input: ['4\n5 4 4 4\n5 5 4 5\n', '6\n1 1 1 1 1 1\n5 5 5 5 5 5\n', '1\n5\n3\n', '9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n'] Demo Output: ['1\n', '3\n', '-1\n', '4\n'] Note: none
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) aa = [0]*6 for v in a: aa[v] += 1 bb = [0]*6 for v in b: bb[v] += 1 res = sum(map(lambda x, y: max(x-y, 0), aa, bb)) if any(map(lambda x, y: (x-y) & 1, aa, bb)): print(-1) else: print(res//2) ```
3
808
C
Tea Party
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "sortings" ]
null
null
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup will contain tea for at least half of its volume - Every cup will contain integer number of milliliters of tea - All the tea from the teapot will be poured into cups - All friends will be satisfied. Friend with cup *i* won't be satisfied, if there exists such cup *j* that cup *i* contains less tea than cup *j* but *a**i*<=&gt;<=*a**j*. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.
The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1.
[ "2 10\n8 7\n", "4 4\n1 1 1 1\n", "3 10\n9 8 10\n" ]
[ "6 4 \n", "1 1 1 1 \n", "-1\n" ]
In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
0
[ { "input": "2 10\n8 7", "output": "6 4 " }, { "input": "4 4\n1 1 1 1", "output": "1 1 1 1 " }, { "input": "3 10\n9 8 10", "output": "-1" }, { "input": "1 1\n1", "output": "1 " }, { "input": "1 1\n2", "output": "1 " }, { "input": "1 10\n20", "output": "10 " }, { "input": "3 10\n8 4 8", "output": "4 2 4 " }, { "input": "3 100\n37 26 37", "output": "37 26 37 " }, { "input": "3 60\n43 23 24", "output": "36 12 12 " }, { "input": "20 14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 8\n1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2", "output": "-1" }, { "input": "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39 45 31 10 12 48 2 19 37 47 45 30 24 21 42 36 14 31 30 31 50 6 3 33 49", "output": "13 11 12 37 28 12 10 18 3 6 2 6 46 50 7 50 4 1 4 40 2 3 34 27 6 39 45 31 5 6 48 1 10 37 47 45 30 12 11 42 36 7 31 30 31 50 3 2 33 49 " }, { "input": "50 440\n14 69 33 38 83 65 21 66 89 3 93 60 31 16 61 20 42 64 13 1 50 50 74 58 67 61 52 22 69 68 18 33 28 59 4 8 96 32 84 85 87 87 61 89 2 47 15 64 88 18", "output": "-1" }, { "input": "100 640\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": "-1" }, { "input": "100 82\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" }, { "input": "100 55\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" }, { "input": "30 50\n3 1 2 4 1 2 2 4 3 4 4 3 3 3 3 5 3 2 5 4 3 3 5 3 3 5 4 5 3 5", "output": "-1" }, { "input": "40 100\n3 3 3 3 4 1 1 1 1 1 2 2 1 3 1 2 3 2 1 2 2 2 1 4 2 2 3 3 3 2 4 6 4 4 3 2 2 2 4 5", "output": "3 3 3 3 4 1 1 1 1 1 2 2 1 3 1 2 3 2 1 2 2 2 1 4 2 2 3 3 3 2 4 6 4 4 3 2 2 2 4 5 " }, { "input": "100 10000\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": "2 5\n3 4", "output": "2 3 " }, { "input": "2 6\n2 6", "output": "1 5 " }, { "input": "23 855\n5 63 94 57 38 84 77 79 83 36 47 31 60 79 75 48 88 17 46 33 23 15 27", "output": "3 32 94 29 19 84 39 72 83 18 24 16 30 79 38 24 88 9 23 17 12 8 14 " }, { "input": "52 2615\n73 78 70 92 94 74 46 19 55 20 70 3 1 42 68 10 66 80 1 31 65 19 73 74 56 35 53 38 92 35 65 81 6 98 74 51 27 49 76 19 86 76 5 60 14 75 64 99 43 7 36 79", "output": "73 78 70 92 94 74 46 10 55 10 70 2 1 42 68 5 66 80 1 16 65 10 73 74 56 18 53 38 92 30 65 81 3 98 74 51 14 49 76 10 86 76 3 60 7 75 64 99 43 4 36 79 " }, { "input": "11 287\n34 30 69 86 22 53 11 91 62 44 5", "output": "17 15 35 43 11 27 6 77 31 22 3 " }, { "input": "55 1645\n60 53 21 20 87 48 10 21 76 35 52 41 82 86 93 11 93 86 34 15 37 63 57 3 57 57 32 8 55 25 29 38 46 22 13 87 27 35 40 83 5 7 6 18 88 25 4 59 95 62 31 93 98 50 62", "output": "30 27 11 10 82 24 5 11 38 18 26 21 41 43 93 6 93 43 17 8 19 32 29 2 29 29 16 4 28 13 15 19 23 11 7 87 14 18 20 42 3 4 3 9 88 13 2 30 95 31 16 93 98 25 31 " }, { "input": "71 3512\n97 46 76 95 81 96 99 83 10 50 19 18 73 5 41 60 12 73 60 31 21 64 88 61 43 57 61 19 75 35 41 85 12 59 32 47 37 43 35 92 90 47 3 98 21 18 61 79 39 86 74 8 52 33 39 27 93 54 35 38 96 36 83 51 97 10 8 66 75 87 68", "output": "97 46 76 95 81 96 99 83 5 50 10 9 73 3 41 60 6 73 60 16 11 64 88 61 43 57 61 10 75 18 41 85 6 59 16 47 19 43 18 92 90 47 2 98 11 9 61 79 20 86 74 4 52 17 21 14 93 54 18 19 96 18 83 51 97 5 4 66 75 87 68 " }, { "input": "100 2633\n99 50 64 81 75 73 26 31 31 36 95 12 100 2 70 72 78 56 76 23 94 8 91 1 39 82 97 67 64 25 71 90 48 34 31 46 64 37 46 50 99 93 14 56 1 89 95 89 50 52 12 58 43 65 45 88 90 14 38 19 6 15 91 67 43 48 82 20 11 48 33 20 39 52 73 5 25 84 26 54 42 56 10 28 9 63 60 98 30 1 25 74 86 56 85 9 12 94 80 95", "output": "50 25 32 41 38 37 13 16 16 18 48 6 61 1 35 36 39 28 38 12 47 4 46 1 20 41 49 34 32 13 36 45 24 17 16 23 32 19 23 25 50 47 7 28 1 45 48 45 25 26 6 29 22 33 23 44 45 7 19 10 3 8 46 34 22 24 41 10 6 24 17 10 20 26 37 3 13 42 13 27 21 28 5 14 5 32 30 49 15 1 13 37 43 28 43 5 6 47 40 48 " }, { "input": "71 1899\n23 55 58 87 69 85 100 21 19 72 81 68 20 25 29 92 18 74 89 70 53 7 78 57 41 79 64 87 63 76 95 84 1 28 32 1 79 34 77 17 71 61 35 31 62 92 69 99 60 26 2 18 61 9 27 77 82 6 30 65 52 3 51 43 13 77 41 59 19 29 86", "output": "12 28 29 44 35 43 95 11 10 36 41 34 10 13 15 46 9 37 45 35 27 4 39 29 21 40 32 44 32 38 48 42 1 14 16 1 40 17 39 9 36 31 18 16 31 46 35 50 30 13 1 9 31 5 14 39 41 3 15 33 26 2 26 22 7 39 21 30 10 15 43 " }, { "input": "10 21\n3 3 3 3 4 3 3 3 3 3", "output": "2 2 2 2 3 2 2 2 2 2 " } ]
1,638,711,156
1,056
PyPy 3
OK
TESTS
29
93
0
n, w = map(int, input().split()) A = list(map(int, input().split())) B = [] for i, a in enumerate(A): B.append((a, i)) B.sort(key=lambda x: x[0]) m = 0 ans = [0]*n for a, i in B: ans[i] = (a+1)//2 m += (a+1)//2 if m > w: print(-1) exit() r = w-m for j in reversed(range(n)): if r == 0: break a, i = B[j] if a-ans[i] <= r: r -= a-ans[i] ans[i] = a else: ans[i] += r r = 0 if r: print(-1) else: print(*ans)
Title: Tea Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup will contain tea for at least half of its volume - Every cup will contain integer number of milliliters of tea - All the tea from the teapot will be poured into cups - All friends will be satisfied. Friend with cup *i* won't be satisfied, if there exists such cup *j* that cup *i* contains less tea than cup *j* but *a**i*<=&gt;<=*a**j*. For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1. Input Specification: The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1. Demo Input: ['2 10\n8 7\n', '4 4\n1 1 1 1\n', '3 10\n9 8 10\n'] Demo Output: ['6 4 \n', '1 1 1 1 \n', '-1\n'] Note: In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
```python n, w = map(int, input().split()) A = list(map(int, input().split())) B = [] for i, a in enumerate(A): B.append((a, i)) B.sort(key=lambda x: x[0]) m = 0 ans = [0]*n for a, i in B: ans[i] = (a+1)//2 m += (a+1)//2 if m > w: print(-1) exit() r = w-m for j in reversed(range(n)): if r == 0: break a, i = B[j] if a-ans[i] <= r: r -= a-ans[i] ans[i] = a else: ans[i] += r r = 0 if r: print(-1) else: print(*ans) ```
3
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements.
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......*..", "output": "2 1" }, { "input": "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.", "output": "1 2" }, { "input": "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "2 100\n...................................................................................................*\n*..................................................................................................*", "output": "1 1" }, { "input": "2 2\n*.\n**", "output": "1 2" }, { "input": "2 2\n**\n.*", "output": "2 1" }, { "input": "2 3\n*.*\n..*", "output": "2 1" } ]
1,661,187,562
2,147,483,647
Python 3
OK
TESTS
36
92
0
L = [int(h) for h in input().split(' ')] n = L[0]; m = L[1] if ((n >= 2) and (n <= 100) and (m >= 2) and (m <= 100)): N = M = list() for i in range(0, n): R = list() s = input() for j in range(0, len(s)): R = R + [s[j]] for k in range(0, len(R)): if (R[k] == '*'): N = N + [i + 1] M = M + [k + 1] En = set(N); Em = set(M) for p in range(0, len(N)): for qn in En: if (N.count(qn) == 1): x = qn for qm in Em: if (M.count(qm) == 1): y = qm print(x, ' ', y)
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Specification: Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Demo Input: ['3 2\n.*\n..\n**\n', '3 3\n*.*\n*..\n...\n'] Demo Output: ['1 1\n', '2 3\n'] Note: none
```python L = [int(h) for h in input().split(' ')] n = L[0]; m = L[1] if ((n >= 2) and (n <= 100) and (m >= 2) and (m <= 100)): N = M = list() for i in range(0, n): R = list() s = input() for j in range(0, len(s)): R = R + [s[j]] for k in range(0, len(R)): if (R[k] == '*'): N = N + [i + 1] M = M + [k + 1] En = set(N); Em = set(M) for p in range(0, len(N)): for qn in En: if (N.count(qn) == 1): x = qn for qm in Em: if (M.count(qm) == 1): y = qm print(x, ' ', y) ```
3
53
A
Autocomplete
PROGRAMMING
1,100
[ "implementation" ]
A. Autocomplete
2
256
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*.
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' operator in the modern programming languages.
[ "next\n2\nnextpermutation\nnextelement\n", "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n" ]
[ "nextelement\n", "find\n", "find\n" ]
none
500
[ { "input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find" }, { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find" }, { "input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "output": "kudljmxcse" }, { "input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "output": "ntqwpadm" }, { "input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "output": "aflb" }, { "input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb", "output": "dzwzyji" }, { "input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg" }, { "input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb" }, { "input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld" } ]
1,660,387,243
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
s = input() short = " "*200 ll = list() for i in range(int(input())): l = input() if l.startswith(s) and len(l) < len(short): short = l ll.append(short) if len(ll) == 0: print(s) else: min(ll)
Title: Autocomplete Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*. Input Specification: The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only. Output Specification: If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' operator in the modern programming languages. Demo Input: ['next\n2\nnextpermutation\nnextelement\n', 'find\n4\nfind\nfindfirstof\nfindit\nfand\n', 'find\n4\nfondfind\nfondfirstof\nfondit\nfand\n'] Demo Output: ['nextelement\n', 'find\n', 'find\n'] Note: none
```python s = input() short = " "*200 ll = list() for i in range(int(input())): l = input() if l.startswith(s) and len(l) < len(short): short = l ll.append(short) if len(ll) == 0: print(s) else: min(ll) ```
0
1,010
A
Fly
PROGRAMMING
1,500
[ "binary search", "math" ]
null
null
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet. For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets. The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload. The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$.
[ "2\n12\n11 8\n7 5\n", "3\n1\n1 4 1\n2 5 3\n", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n" ]
[ "10.0000000000\n", "-1\n", "85.4800000000\n" ]
Let's consider the first example. Initially, the mass of a rocket with fuel is $22$ tons. - At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
500
[ { "input": "2\n12\n11 8\n7 5", "output": "10.0000000000" }, { "input": "3\n1\n1 4 1\n2 5 3", "output": "-1" }, { "input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000" }, { "input": "3\n3\n1 2 1\n2 2 2", "output": "-1" }, { "input": "4\n4\n2 3 2 2\n2 3 4 3", "output": "284.0000000000" }, { "input": "5\n2\n1 2 2 1 2\n4 5 1 4 1", "output": "-1" }, { "input": "7\n7\n3 2 6 2 2 2 5\n4 7 5 6 2 2 2", "output": "4697.0000000000" }, { "input": "2\n1000\n12 34\n56 78", "output": "159.2650775220" }, { "input": "8\n4\n1 1 4 1 3 1 8 1\n1 1 1 1 1 3 1 2", "output": "-1" }, { "input": "9\n2\n8 7 1 1 3 7 1 2 4\n4 1 1 8 7 7 1 1 5", "output": "-1" }, { "input": "10\n10\n9 8 8 7 2 10 2 9 2 4\n3 10 6 2 6 6 5 9 4 5", "output": "3075.7142857143" }, { "input": "20\n12\n3 9 12 13 16 18 9 9 19 7 2 5 17 14 7 7 15 16 5 7\n16 9 13 5 14 10 4 3 16 16 12 20 17 11 4 5 5 14 6 15", "output": "4670.8944493007" }, { "input": "30\n5\n25 1 28 1 27 25 24 1 28 1 12 1 29 16 1 1 1 1 27 1 24 1 1 1 1 1 1 1 30 3\n1 22 1 1 24 2 13 1 16 21 1 27 14 16 1 1 7 1 1 18 1 23 10 1 15 16 16 15 10 1", "output": "-1" }, { "input": "40\n13\n1 1 1 23 21 1 1 1 1 1 40 32 1 21 1 8 1 1 36 15 33 1 30 1 1 37 22 1 4 39 7 1 9 37 1 1 1 28 1 1\n1 34 17 1 38 20 8 14 1 18 29 3 21 21 18 14 1 11 1 1 23 1 25 1 14 1 7 31 9 20 25 1 1 1 1 8 26 12 1 1", "output": "-1" }, { "input": "50\n19\n17 7 13 42 19 25 10 25 2 36 17 40 30 48 34 43 34 20 5 15 8 7 43 35 21 40 40 19 30 11 49 7 24 23 43 30 38 49 10 8 30 11 28 50 48 25 25 20 48 24\n49 35 10 22 24 50 50 7 6 13 16 35 12 43 50 44 35 33 38 49 26 18 23 37 7 38 23 20 28 48 41 16 6 32 32 34 11 39 38 9 38 23 16 31 37 47 33 20 46 30", "output": "7832.1821424977" }, { "input": "60\n21\n11 35 1 28 39 13 19 56 13 13 21 25 1 1 23 1 52 26 53 1 1 1 30 39 1 7 1 1 3 1 1 10 1 1 37 1 1 25 1 1 1 53 1 3 48 1 6 5 4 15 1 14 25 53 25 38 27 1 1 1\n1 1 1 35 40 58 10 22 1 56 1 59 1 6 33 1 1 1 1 18 14 1 1 40 25 47 1 34 1 1 53 1 1 25 1 45 1 1 25 34 3 1 1 1 53 27 11 58 1 1 1 10 12 1 1 1 31 52 1 1", "output": "-1" }, { "input": "70\n69\n70 66 57 58 24 60 39 2 48 61 65 22 10 26 68 62 48 25 12 14 45 57 6 30 48 15 46 33 42 28 69 42 64 25 24 8 62 12 68 53 55 20 32 70 3 5 41 49 16 26 2 34 34 20 39 65 18 47 62 31 39 28 61 67 7 14 31 31 53 54\n40 33 24 20 68 20 22 39 53 56 48 38 59 45 47 46 7 69 11 58 61 40 35 38 62 66 18 36 44 48 67 24 14 27 67 63 68 30 50 6 58 7 6 35 20 58 6 12 12 23 14 2 63 27 29 22 49 16 55 40 70 27 27 70 42 38 66 55 69 47", "output": "217989.4794743629" }, { "input": "80\n21\n65 4 26 25 1 1 1 1 1 1 60 1 29 43 48 6 48 13 29 1 1 62 1 1 1 1 1 1 1 26 9 1 22 1 35 13 66 36 1 1 1 38 55 21 70 1 58 70 1 1 38 1 1 20 1 1 51 1 1 28 1 23 11 1 39 47 1 52 41 1 63 1 1 52 1 45 11 10 80 1\n1 1 25 30 1 1 55 54 1 48 10 37 22 1 74 1 78 13 1 65 32 1 1 1 1 69 5 59 1 1 65 1 40 1 31 1 1 75 54 1 60 1 1 1 1 1 1 1 11 29 36 1 72 71 52 1 1 1 37 1 1 75 43 9 53 1 62 1 29 1 40 27 59 74 41 53 19 30 1 73", "output": "-1" }, { "input": "90\n35\n1 68 16 30 24 1 1 1 35 1 1 67 1 1 1 1 33 16 37 77 83 1 77 26 1 1 68 67 70 62 1 47 1 1 1 84 1 65 1 32 83 1 1 1 28 1 71 76 84 1 1 5 1 74 10 1 1 1 38 87 13 1 7 66 81 49 1 9 1 11 1 25 1 1 1 1 7 1 1 36 61 47 51 1 1 69 40 1 37 1\n40 1 21 1 19 51 37 52 64 1 86 1 5 24 1 1 1 19 36 1 1 77 24 4 1 18 89 1 1 1 1 1 29 22 1 80 32 36 6 1 63 1 30 1 1 1 86 79 73 52 9 1 1 11 7 1 25 20 1 20 1 49 1 37 1 41 1 1 1 1 54 55 1 10 1 1 1 1 1 1 66 1 68 1 1 1 1 53 1 1", "output": "-1" }, { "input": "2\n1\n1 1\n1 1", "output": "-1" }, { "input": "2\n1\n1 1\n2 2", "output": "-1" }, { "input": "2\n1\n2 2\n1 1", "output": "-1" }, { "input": "2\n1\n2 2\n2 2", "output": "15.0000000000" }, { "input": "2\n2\n1 1\n1 1", "output": "-1" }, { "input": "2\n2\n1 1\n2 2", "output": "-1" }, { "input": "2\n2\n2 2\n1 1", "output": "-1" }, { "input": "2\n2\n2 2\n2 2", "output": "30.0000000000" }, { "input": "40\n55\n1 382 1 1 1 629 111 689 396 614 1 1 995 148 7 820 913 1 1 169 157 1 702 1 159 1 1 226 1 253 1 319 1 130 1 1 1 466 1 756\n1 23 555 1 412 1 1 373 316 234 888 1 112 818 33 443 313 1 235 1 1 610 110 535 1 445 1 386 1 1 758 1 292 1 862 1 244 428 530 1", "output": "-1" }, { "input": "49\n1\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\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "695580114.6380882263" }, { "input": "2\n12\n11 8\n1 1", "output": "-1" }, { "input": "3\n3\n7 11 17\n19 31 33", "output": "1.6012429470" } ]
1,542,195,237
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
p=[] b=int(input()) a=str(input()) p=a.split(" ") p.sort() p.reverse() if p[1]=='1': print('HARD') else: print('EASY')
Title: Fly Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet. The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet. For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well. Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. Input Specification: The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets. The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload. The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. Output Specification: If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$. Demo Input: ['2\n12\n11 8\n7 5\n', '3\n1\n1 4 1\n2 5 3\n', '6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n'] Demo Output: ['10.0000000000\n', '-1\n', '85.4800000000\n'] Note: Let's consider the first example. Initially, the mass of a rocket with fuel is $22$ tons. - At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel. In the second case, the rocket will not be able even to take off from Earth.
```python p=[] b=int(input()) a=str(input()) p=a.split(" ") p.sort() p.reverse() if p[1]=='1': print('HARD') else: print('EASY') ```
-1
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,559,319,746
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
78
0
s=[int(n) for n in input().split()] n=s[0] k=s[1] z=[] for a in range(1,int(n**.5)+1): if n%a==0: z.append(a) if n/a!=a: z.append(n//a) if k>len(z): print(-1) else: print(z[k-1])
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python s=[int(n) for n in input().split()] n=s[0] k=s[1] z=[] for a in range(1,int(n**.5)+1): if n%a==0: z.append(a) if n/a!=a: z.append(n//a) if k>len(z): print(-1) else: print(z[k-1]) ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,637,992,189
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a = list(map(ord,input())) A = ord("A") Z = ord("Z") ans = 0 curr = 0 for i in a: x = i - A curr = x ans += min(abs(x-curr), 26 -(x- curr)) print(ans)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python a = list(map(ord,input())) A = ord("A") Z = ord("Z") ans = 0 curr = 0 for i in a: x = i - A curr = x ans += min(abs(x-curr), 26 -(x- curr)) print(ans) ```
0
933
B
A Determined Cleanup
PROGRAMMING
2,000
[ "math" ]
null
null
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficients strictly less than *k*, whose remainder is *p* when divided by (*x*<=+<=*k*). That is, *f*(*x*)<==<=*q*(*x*)·(*x*<=+<=*k*)<=+<=*p*, where *q*(*x*) is a polynomial (not necessarily with integer coefficients).
The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000).
If the polynomial does not exist, print a single integer -1, or output two lines otherwise. In the first line print a non-negative integer *d* — the number of coefficients in the polynomial. In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0<=≤<=*a**i*<=&lt;<=*k* for all 0<=≤<=*i*<=≤<=*d*<=-<=1, and *a**d*<=-<=1<=≠<=0. If there are many possible solutions, print any of them.
[ "46 2\n", "2018 214\n" ]
[ "7\n0 1 0 0 1 1 1\n", "3\n92 205 1\n" ]
In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·(*x* + 2) + 46. In the second example, *f*(*x*) = *x*<sup class="upper-index">2</sup> + 205*x* + 92 = (*x* - 9)·(*x* + 214) + 2018.
750
[ { "input": "46 2", "output": "7\n0 1 0 0 1 1 1" }, { "input": "2018 214", "output": "3\n92 205 1" }, { "input": "4 2", "output": "3\n0 0 1" }, { "input": "5 2", "output": "3\n1 0 1" }, { "input": "10 3", "output": "3\n1 0 1" }, { "input": "250 1958", "output": "1\n250" }, { "input": "1000000000000000000 2000", "output": "7\n0 0 0 0 500 1969 1" }, { "input": "1 2", "output": "1\n1" }, { "input": "2 2", "output": "3\n0 1 1" }, { "input": "3 2", "output": "3\n1 1 1" }, { "input": "6 2", "output": "5\n0 1 0 1 1" }, { "input": "7 2", "output": "5\n1 1 0 1 1" }, { "input": "8 2", "output": "5\n0 0 0 1 1" }, { "input": "9 2", "output": "5\n1 0 0 1 1" }, { "input": "10 2", "output": "5\n0 1 1 1 1" }, { "input": "1 3", "output": "1\n1" }, { "input": "2 3", "output": "1\n2" }, { "input": "3 3", "output": "3\n0 2 1" }, { "input": "4 3", "output": "3\n1 2 1" }, { "input": "5 3", "output": "3\n2 2 1" }, { "input": "6 3", "output": "3\n0 1 1" }, { "input": "7 3", "output": "3\n1 1 1" }, { "input": "8 3", "output": "3\n2 1 1" }, { "input": "9 3", "output": "3\n0 0 1" }, { "input": "462 2", "output": "11\n0 1 0 0 1 0 1 1 0 1 1" }, { "input": "462 3", "output": "7\n0 2 1 1 0 1 1" }, { "input": "2018 4", "output": "7\n2 0 2 1 0 2 1" }, { "input": "20180214 5", "output": "11\n4 3 4 4 4 3 2 2 2 0 2" }, { "input": "1317 221", "output": "3\n212 216 1" }, { "input": "1314 520", "output": "3\n274 518 1" }, { "input": "1562 862", "output": "3\n700 861 1" }, { "input": "6666666666666666 3", "output": "35\n0 1 2 0 0 2 2 1 2 2 1 1 2 2 2 2 0 0 0 2 1 2 1 1 1 1 1 2 1 2 0 1 1 2 1" }, { "input": "252525252525252525 252", "output": "9\n189 176 211 80 27 238 231 249 1" }, { "input": "271828182845904523 536", "output": "7\n3 157 21 240 147 288 12" }, { "input": "314159265358979323 846", "output": "7\n553 47 111 353 790 122 1" }, { "input": "393939393939393939 393", "output": "7\n237 191 82 181 11 30 107" }, { "input": "233333333333333333 2000", "output": "7\n1333 1334 1334 1334 584 1993 1" }, { "input": "998244353998244353 2000", "output": "7\n353 878 500 1456 391 1969 1" }, { "input": "1000000000000000000 2", "output": "61\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1" }, { "input": "1000000000000000000 3", "output": "39\n1 0 0 0 2 0 2 2 0 2 0 0 1 1 1 2 1 1 1 0 1 2 2 0 1 1 1 2 0 0 0 1 0 0 0 1 1 1 1" } ]
1,626,710,156
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
39
109
20,172,800
import sys import math from math import * import builtins input = sys.stdin.readline def print(x, end='\n'): sys.stdout.write(str(x) + end) # IO helpers def get_int(): return int(input()) def get_list_ints(): return list(map(int, input().split())) def get_char_list(): s = input() return list(s[:len(s) - 1]) def get_tuple_ints(): return tuple(map(int, input().split())) def print_iterable(p): print(" ".join(map(str, p))) def binary_search(arr, x): low = 0 high = len(arr) - 1 mid = 0 while low <= high: mid = (high + low) // 2 if arr[mid] < x: low = mid + 1 elif arr[mid] > x: high = mid - 1 else: return mid return high def reverse(list,n): for i in range(n//2): list[i],list[n-i-1]=list[n-i-1],list[i] def main(): list1=get_list_ints() alist1=list1.copy() p=list1[0] k=list1[1] ans=0 qxco=[] while p>=1: if ans%2==0: p=math.floor(p/k) ans+=1 qxco.append(p) else: p=math.ceil(p/k) ans+=1 qxco.append(p) print(ans) coeff=[] counter=0 for i in range(len(qxco)-1,0,-1): if counter%2==0: coeff.append(-1*qxco[i]*k+qxco[i-1]) counter+=1 else: coeff.append(qxco[i]*k-qxco[i-1]) counter+=1 coeff.append(alist1[0]-k*(alist1[0]//k)) reverse(coeff,ans) print_iterable(coeff) pass if __name__ == '__main__': main()
Title: A Determined Cleanup Time Limit: None seconds Memory Limit: None megabytes Problem Description: In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficients strictly less than *k*, whose remainder is *p* when divided by (*x*<=+<=*k*). That is, *f*(*x*)<==<=*q*(*x*)·(*x*<=+<=*k*)<=+<=*p*, where *q*(*x*) is a polynomial (not necessarily with integer coefficients). Input Specification: The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000). Output Specification: If the polynomial does not exist, print a single integer -1, or output two lines otherwise. In the first line print a non-negative integer *d* — the number of coefficients in the polynomial. In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0<=≤<=*a**i*<=&lt;<=*k* for all 0<=≤<=*i*<=≤<=*d*<=-<=1, and *a**d*<=-<=1<=≠<=0. If there are many possible solutions, print any of them. Demo Input: ['46 2\n', '2018 214\n'] Demo Output: ['7\n0 1 0 0 1 1 1\n', '3\n92 205 1\n'] Note: In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·(*x* + 2) + 46. In the second example, *f*(*x*) = *x*<sup class="upper-index">2</sup> + 205*x* + 92 = (*x* - 9)·(*x* + 214) + 2018.
```python import sys import math from math import * import builtins input = sys.stdin.readline def print(x, end='\n'): sys.stdout.write(str(x) + end) # IO helpers def get_int(): return int(input()) def get_list_ints(): return list(map(int, input().split())) def get_char_list(): s = input() return list(s[:len(s) - 1]) def get_tuple_ints(): return tuple(map(int, input().split())) def print_iterable(p): print(" ".join(map(str, p))) def binary_search(arr, x): low = 0 high = len(arr) - 1 mid = 0 while low <= high: mid = (high + low) // 2 if arr[mid] < x: low = mid + 1 elif arr[mid] > x: high = mid - 1 else: return mid return high def reverse(list,n): for i in range(n//2): list[i],list[n-i-1]=list[n-i-1],list[i] def main(): list1=get_list_ints() alist1=list1.copy() p=list1[0] k=list1[1] ans=0 qxco=[] while p>=1: if ans%2==0: p=math.floor(p/k) ans+=1 qxco.append(p) else: p=math.ceil(p/k) ans+=1 qxco.append(p) print(ans) coeff=[] counter=0 for i in range(len(qxco)-1,0,-1): if counter%2==0: coeff.append(-1*qxco[i]*k+qxco[i-1]) counter+=1 else: coeff.append(qxco[i]*k-qxco[i-1]) counter+=1 coeff.append(alist1[0]-k*(alist1[0]//k)) reverse(coeff,ans) print_iterable(coeff) pass if __name__ == '__main__': main() ```
0
650
A
Watchmen
PROGRAMMING
1,400
[ "data structures", "geometry", "math" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
500
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { "input": "2\n315 845\n-669 -762", "output": "0" }, { "input": "3\n8911 7861\n-6888 7861\n8911 7861", "output": "3" }, { "input": "2\n-1 1000000000\n0 -1", "output": "0" }, { "input": "2\n1000000000 0\n-7 1", "output": "0" }, { "input": "2\n1 4\n2 1", "output": "0" }, { "input": "2\n1 0\n0 2333333", "output": "0" }, { "input": "2\n2 1\n1 2", "output": "0" }, { "input": "2\n1 1000000000\n2 -1000000000", "output": "0" }, { "input": "2\n0 1000000000\n1 -7", "output": "0" }, { "input": "2\n1 0\n0 19990213", "output": "0" } ]
1,612,437,564
2,147,483,647
PyPy 3
OK
TESTS
71
2,215
34,816,000
""" import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') """ q = {} w = {} e = {} r = 0 for _ in range(int(input())): x, y = map(int, input().split()) a, s, d = q.get(x, 0), w.get(y, 0), e.get((x, y), 0) r += a + s - d q[x], w[y], e[x, y] = a + 1, s + 1, d + 1 print(r)
Title: Watchmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. Input Specification: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. Output Specification: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Demo Input: ['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n'] Demo Output: ['2\n', '11\n'] Note: In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
```python """ import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') """ q = {} w = {} e = {} r = 0 for _ in range(int(input())): x, y = map(int, input().split()) a, s, d = q.get(x, 0), w.get(y, 0), e.get((x, y), 0) r += a + s - d q[x], w[y], e[x, y] = a + 1, s + 1, d + 1 print(r) ```
3
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, { "input": "helloworld", "output": "w" }, { "input": "zzzzzzzazz", "output": "zzzzzzzzz" }, { "input": "testcase", "output": "tt" }, { "input": "hahahahaha", "output": "hhhhh" }, { "input": "abbbbbbbbb", "output": "bbbbbbbbb" }, { "input": "zaz", "output": "zz" }, { "input": "aza", "output": "z" }, { "input": "dcbaedcba", "output": "e" }, { "input": "abcdeabcd", "output": "e" }, { "input": "edcbabcde", "output": "ee" }, { "input": "aaaaaaaaab", "output": "b" }, { "input": "testzzzzzz", "output": "zzzzzz" }, { "input": "zzzzzzwait", "output": "zzzzzz" }, { "input": "rrrrrqponm", "output": "rrrrr" }, { "input": "zzyzyy", "output": "zzz" }, { "input": "aababb", "output": "bbb" }, { "input": "zanzibar", "output": "zz" }, { "input": "hhgfedcbaa", "output": "hh" }, { "input": "aabcdefghh", "output": "hh" }, { "input": "aruaru", "output": "uu" }, { "input": "uraura", "output": "uu" }, { "input": "aru", "output": "u" }, { "input": "aburvabur", "output": "v" }, { "input": "ura", "output": "u" }, { "input": "eurottat", "output": "u" }, { "input": "referee", "output": "rr" }, { "input": "joking", "output": "o" }, { "input": "seriously", "output": "y" }, { "input": "sets", "output": "t" }, { "input": "test", "output": "tt" }, { "input": "klmgameklm", "output": "mmm" }, { "input": "dfkjafdkdd", "output": "kk" }, { "input": "zzzzzzzzzz", "output": "zzzzzzzzzz" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "buzz", "output": "zz" }, { "input": "b", "output": "b" }, { "input": "y", "output": "y" }, { "input": "yy", "output": "yy" }, { "input": "zz", "output": "zz" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "a", "output": "a" }, { "input": "z", "output": "z" }, { "input": "zz", "output": "zz" }, { "input": "zzazazzzaz", "output": "zzzzzzz" }, { "input": "hellhellhe", "output": "llll" }, { "input": "hellohello", "output": "oo" }, { "input": "refer", "output": "rr" } ]
1,658,052,044
2,147,483,647
PyPy 3-64
OK
TESTS
54
124
0
s = input() M = sorted(list(s))[-1] ans = "" for c in s: if c == M: ans += M print(ans)
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". Input Specification: The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. Output Specification: Print the lexicographically largest palindromic subsequence of string *s*. Demo Input: ['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n'] Demo Output: ['rr\n', 'wwwww\n', 's\n', 'ssss\n'] Note: Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
```python s = input() M = sorted(list(s))[-1] ans = "" for c in s: if c == M: ans += M print(ans) ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", "output": "18" }, { "input": "z\na", "output": "2" }, { "input": "ama\nsama", "output": "1" }, { "input": "aaabc\nbc", "output": "3" }, { "input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "output": "32" }, { "input": "ahmedaly\naly", "output": "5" }, { "input": "aa\na", "output": "1" }, { "input": "aa\nba", "output": "2" }, { "input": "cccba\nba", "output": "3" }, { "input": "a\nab", "output": "3" }, { "input": "dadc\ndddc", "output": "4" }, { "input": "aacaaab\nb", "output": "6" }, { "input": "dddc\ncdcde", "output": "9" }, { "input": "bbdab\ndab", "output": "2" }, { "input": "a\naa", "output": "1" }, { "input": "aa\nab", "output": "4" }, { "input": "codeforces\nces", "output": "7" } ]
1,641,832,999
2,147,483,647
Python 3
OK
TESTS
28
155
716,800
a = input() b = input() c = len(a) d = len(b) while c * d * (a[c - 1] == b[d - 1]): c = c - 1 d = d - 1 print(c + d)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python a = input() b = input() c = len(a) d = len(b) while c * d * (a[c - 1] == b[d - 1]): c = c - 1 d = d - 1 print(c + d) ```
3
991
C
Candies
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
[ "68\n" ]
[ "3\n" ]
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
1,250
[ { "input": "68", "output": "3" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "1" }, { "input": "43", "output": "2" }, { "input": "756", "output": "29" }, { "input": "999999972", "output": "39259423" }, { "input": "999999973", "output": "39259424" }, { "input": "1000000000000000000", "output": "39259424579862572" }, { "input": "6", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "66", "output": "2" }, { "input": "67", "output": "3" }, { "input": "1000", "output": "39" }, { "input": "10000", "output": "392" }, { "input": "100500", "output": "3945" }, { "input": "1000000", "output": "39259" }, { "input": "10000000", "output": "392594" }, { "input": "100000000", "output": "3925942" }, { "input": "123456789", "output": "4846842" }, { "input": "543212345", "output": "21326204" }, { "input": "505050505", "output": "19827992" }, { "input": "777777777", "output": "30535108" }, { "input": "888888871", "output": "34897266" }, { "input": "1000000000", "output": "39259424" }, { "input": "999999999999999973", "output": "39259424579862572" }, { "input": "999999999999999998", "output": "39259424579862572" }, { "input": "999999999999999999", "output": "39259424579862573" }, { "input": "100000000000000000", "output": "3925942457986257" }, { "input": "540776028375043656", "output": "21230555700587649" }, { "input": "210364830044445976", "output": "8258802179385535" }, { "input": "297107279239074256", "output": "11664260821414605" }, { "input": "773524766411950187", "output": "30368137227605772" }, { "input": "228684941775227220", "output": "8978039224174797" }, { "input": "878782039723446310", "output": "34500477210660436" }, { "input": "615090701338187389", "output": "24148106998961343" }, { "input": "325990422297859188", "output": "12798196397960353" }, { "input": "255163492355051023", "output": "10017571883647466" }, { "input": "276392003308849171", "output": "10850991008380891" }, { "input": "601", "output": "23" }, { "input": "983", "output": "38" }, { "input": "729", "output": "29" }, { "input": "70", "output": "3" }, { "input": "703", "output": "28" }, { "input": "257", "output": "10" }, { "input": "526", "output": "20" }, { "input": "466", "output": "18" }, { "input": "738", "output": "29" }, { "input": "116", "output": "5" }, { "input": "888888888888888887", "output": "34897266293211176" }, { "input": "888888888888888888", "output": "34897266293211176" }, { "input": "888888888888888889", "output": "34897266293211176" }, { "input": "999999999999999969", "output": "39259424579862571" }, { "input": "999999999999999970", "output": "39259424579862571" }, { "input": "999999999999999971", "output": "39259424579862572" }, { "input": "999999999999999943", "output": "39259424579862571" }, { "input": "999999999999999944", "output": "39259424579862570" }, { "input": "999999999999999945", "output": "39259424579862571" }, { "input": "999999999999999917", "output": "39259424579862570" }, { "input": "999999999999999918", "output": "39259424579862569" }, { "input": "999999999999999919", "output": "39259424579862570" }, { "input": "99999999999999957", "output": "3925942457986255" }, { "input": "99999999999999958", "output": "3925942457986255" }, { "input": "99999999999999959", "output": "3925942457986256" }, { "input": "888888888888888853", "output": "34897266293211174" }, { "input": "888888888888888854", "output": "34897266293211174" }, { "input": "888888888888888855", "output": "34897266293211175" } ]
1,538,552,977
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
n = int(input()) lo = 1 hi = n def check(k): global n cp = n a = 0 b = 0 while n>0: a += min(n, k) n -= min(n, k) if n==0: break b += n//10 n -= n//10 if n<=0: break #print('for',k,a,b) n = cp return a>=b while lo+1<hi: #print(lo, hi) mid = (lo+hi+1)//2 if check(mid): hi = mid else: lo = mid+1 mid = (lo+hi+1)//2 print(mid)
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. Output Specification: Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. Demo Input: ['68\n'] Demo Output: ['3\n'] Note: In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
```python n = int(input()) lo = 1 hi = n def check(k): global n cp = n a = 0 b = 0 while n>0: a += min(n, k) n -= min(n, k) if n==0: break b += n//10 n -= n//10 if n<=0: break #print('for',k,a,b) n = cp return a>=b while lo+1<hi: #print(lo, hi) mid = (lo+hi+1)//2 if check(mid): hi = mid else: lo = mid+1 mid = (lo+hi+1)//2 print(mid) ```
0
958
F1
Lightsabers (easy)
PROGRAMMING
1,500
[ "implementation" ]
null
null
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. Heidi has *n* Jedi Knights standing in front of her, each one with a lightsaber of one of *m* possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly *k*1 knights with lightsabers of the first color, *k*2 knights with lightsabers of the second color, ..., *k**m* knights with lightsabers of the *m*-th color. Help her find out if this is possible.
The first line of the input contains *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired counts of lightsabers of each color from 1 to *m*.
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
[ "5 2\n1 1 2 2 1\n1 2\n" ]
[ "YES\n" ]
none
0
[ { "input": "5 2\n1 1 2 2 1\n1 2", "output": "YES" }, { "input": "1 1\n1\n1", "output": "YES" }, { "input": "2 1\n1 1\n1", "output": "YES" }, { "input": "2 1\n1 1\n2", "output": "YES" }, { "input": "2 2\n1 2\n1 1", "output": "YES" }, { "input": "3 3\n1 1 3\n0 1 2", "output": "NO" }, { "input": "4 4\n2 3 3 2\n0 0 1 0", "output": "YES" }, { "input": "2 2\n2 2\n0 2", "output": "YES" }, { "input": "3 3\n1 1 3\n0 1 1", "output": "NO" }, { "input": "4 4\n2 4 4 3\n1 1 1 1", "output": "NO" }, { "input": "2 2\n2 1\n0 1", "output": "YES" }, { "input": "3 3\n3 1 1\n1 1 1", "output": "NO" }, { "input": "4 4\n1 3 1 4\n1 0 0 1", "output": "YES" }, { "input": "2 2\n2 1\n1 0", "output": "YES" }, { "input": "3 3\n3 1 1\n2 0 0", "output": "YES" }, { "input": "4 4\n4 4 2 2\n1 1 1 1", "output": "NO" }, { "input": "2 2\n1 2\n0 2", "output": "NO" }, { "input": "3 3\n3 2 3\n0 2 1", "output": "NO" }, { "input": "4 4\n1 2 4 2\n0 0 1 0", "output": "NO" }, { "input": "2 2\n2 1\n1 1", "output": "YES" }, { "input": "3 3\n2 2 1\n1 1 1", "output": "NO" }, { "input": "6 6\n5 1 6 3 3 2\n1 1 2 0 0 1", "output": "YES" }, { "input": "4 4\n1 2 1 1\n2 1 0 0", "output": "YES" }, { "input": "5 5\n5 3 5 2 5\n0 0 0 0 1", "output": "YES" }, { "input": "6 6\n1 2 2 4 6 1\n1 0 0 0 0 1", "output": "YES" }, { "input": "4 4\n2 2 4 1\n0 2 0 0", "output": "YES" }, { "input": "5 5\n1 5 3 5 1\n1 0 0 0 1", "output": "YES" }, { "input": "6 6\n5 4 4 3 4 6\n0 0 1 1 0 0", "output": "YES" }, { "input": "4 4\n1 3 4 4\n1 0 1 1", "output": "YES" }, { "input": "5 5\n2 5 2 5 3\n0 0 1 0 1", "output": "YES" }, { "input": "6 6\n5 6 5 6 3 5\n0 0 0 0 2 1", "output": "YES" }, { "input": "4 4\n4 3 4 2\n0 0 0 1", "output": "YES" }, { "input": "5 5\n4 2 1 1 3\n1 1 0 1 0", "output": "YES" }, { "input": "6 6\n1 5 5 1 1 6\n3 0 0 0 2 0", "output": "YES" }, { "input": "4 4\n2 3 2 2\n0 3 1 0", "output": "YES" }, { "input": "5 5\n2 1 5 1 2\n2 1 0 0 1", "output": "YES" }, { "input": "99 2\n2 1 2 1 2 2 1 1 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 1 1 1 2 1 2 1 2 2 1 1 1 2 2 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 1 2 1 2 2 2 1\n3 2", "output": "YES" }, { "input": "99 2\n2 1 2 1 2 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 1 2 2 1 2 2 1 1 1 1 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 2 2 1 1\n3 2", "output": "YES" }, { "input": "99 2\n1 1 1 1 1 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 1 2 2 2 1 1 2 2 2 1 1 1 1 1 2 2 2 2 1 1 2 2 2 2 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 2 2 2 2 1 1 1 2 2 1 2 2 2 2 1 1 1 2 2 2 1 1 1 2 2 1 1 2 1 1 1 2 1 1 2 1 1\n3 2", "output": "YES" }, { "input": "99 2\n2 1 1 2 1 2 1 2 2 2 1 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 2 1 2 1 1 2 1 1 1 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 1 1\n4 1", "output": "YES" }, { "input": "99 2\n2 2 1 2 1 2 2 1 1 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 1 1 2 1 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 1 2 2 2 2 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 2 1 1\n1 4", "output": "YES" }, { "input": "99 2\n2 2 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1 1 2 1 2 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 1 2 2 2 1 2 2 2 1 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 2 2 2 1 2 2\n0 1", "output": "YES" }, { "input": "99 2\n1 2 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 2 1 2 1 1 2 1 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1\n1 0", "output": "YES" }, { "input": "99 2\n2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 1 1 2 2 1 1 1 2 2 1 2 2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 1 1 1 1 2 1\n0 1", "output": "YES" }, { "input": "99 2\n2 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 2 1 1 1 1 2 2 1 1 2 2 2 1 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 2 1 2 2 2 1 1 2 2 2 2 1 1 1 1 2 2 1 2 1 1 1\n44 55", "output": "NO" }, { "input": "99 2\n1 2 1 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 1 2 1 2 1 1\n50 49", "output": "NO" }, { "input": "99 2\n2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 2 2 2 2 2 1 1 1 1 1 2 1 2 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 2 1 2 2\n52 47", "output": "NO" }, { "input": "99 2\n2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 2 2 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 2 2 1 2 1 2 1 1 2 1 2 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 1 2 1 2 2 2 2 1 1 1 2 1 2 1 1 1 2 1 1 1\n2 3", "output": "YES" }, { "input": "99 2\n1 2 2 1 1 1 2 1 1 2 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 2 2 1 2 2 2 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 1 1 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 1 1 2 1 1 1 2 1 1 2 2 1 2 1 1 1 1 2 1 1\n4 1", "output": "YES" }, { "input": "99 2\n1 1 1 1 1 2 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 2 2 2 1 2 1 2 2 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 2 1 1 2 1 2 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 2 2 1 2 2 1 2 1 2 1 2 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1\n2 3", "output": "YES" }, { "input": "99 2\n2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 1 2 2 2 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 2 1 2 2 2 1 2 2 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 2 1\n2 3", "output": "YES" }, { "input": "99 2\n1 2 2 2 1 2 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 2 1 1 1 2 2 1 2 1 1 2 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2\n1 0", "output": "YES" }, { "input": "99 2\n1 1 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 1 2 1 2 2 2 1 2 2 1 1 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 1 2 1 1 2 2 1 1 2 2 1 1 2 2\n0 1", "output": "YES" }, { "input": "99 2\n2 2 1 2 2 2 1 1 1 1 1 2 2 1 2 2 2 2 2 2 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 1 2 2 2 2 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 2 2 1 2 2 2 1 1 1 1\n0 1", "output": "YES" }, { "input": "99 2\n1 1 1 2 2 2 1 2 1 2 1 1 1 2 1 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2 2 1 2 1 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 2 1 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 2 1\n52 47", "output": "YES" }, { "input": "99 2\n1 2 2 1 1 1 2 1 2 2 1 2 2 1 1 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 1 2 2 2 1 1\n54 45", "output": "YES" }, { "input": "99 2\n2 2 2 1 2 1 1 1 1 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 1 2 1 1 2 1 1 2 1 1 2 2 1 2 2 1 1 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1\n47 52", "output": "YES" }, { "input": "100 10\n2 9 6 4 10 8 6 2 5 4 6 7 8 10 6 1 9 8 7 6 2 1 10 5 5 8 2 2 10 2 6 5 2 4 7 3 9 6 3 3 5 9 8 7 10 10 5 7 3 9 5 3 4 5 8 9 7 6 10 5 2 6 3 7 8 8 3 7 10 2 9 7 7 5 9 4 10 8 8 8 3 7 8 7 1 6 6 7 3 6 7 6 4 5 6 3 10 1 1 9\n1 0 0 0 0 0 0 0 1 0", "output": "YES" }, { "input": "100 10\n2 10 5 8 4 8 3 10 5 6 5 10 2 8 2 5 6 4 7 5 10 6 8 1 6 5 8 4 1 2 5 5 9 9 7 5 2 4 4 8 6 4 3 2 9 8 5 1 7 8 5 9 6 5 1 9 6 6 5 4 7 10 3 8 6 3 1 9 8 7 7 10 4 4 3 10 2 2 10 2 6 8 8 6 9 5 5 8 2 9 4 1 3 3 1 5 5 6 7 4\n0 0 0 0 0 1 1 0 0 0", "output": "YES" }, { "input": "100 10\n10 8 1 2 8 1 4 9 4 10 1 3 1 3 7 3 10 6 8 10 3 10 7 7 5 3 2 10 4 4 7 10 10 6 10 2 2 5 1 1 2 5 10 9 6 9 6 10 7 3 10 7 6 7 3 3 9 2 3 8 2 9 9 5 7 5 8 6 6 6 6 10 10 4 2 2 7 4 1 4 7 4 6 4 6 8 8 6 3 10 2 3 5 2 10 3 4 7 3 10\n0 0 0 1 0 0 0 0 1 0", "output": "YES" }, { "input": "100 10\n5 5 6 8 2 3 3 6 5 4 10 2 10 1 8 9 7 6 5 10 4 9 8 8 5 4 2 10 7 9 3 6 10 1 9 5 8 7 8 6 1 1 9 1 9 6 3 10 4 4 9 9 1 7 6 3 1 10 3 9 7 9 8 5 7 6 10 4 8 2 9 1 7 1 7 7 9 1 2 3 9 1 6 7 10 7 9 8 2 2 5 1 1 3 8 10 6 4 2 6\n0 0 1 0 0 0 1 0 0 0", "output": "NO" }, { "input": "100 100\n48 88 38 80 20 25 80 40 71 17 5 68 84 16 20 91 86 29 51 37 62 100 25 19 44 58 90 75 27 68 77 67 74 33 43 10 86 33 66 4 66 84 86 8 50 75 95 1 52 16 93 90 70 25 50 37 53 97 44 33 44 66 57 75 43 52 1 73 49 25 3 82 62 75 24 96 41 33 3 91 72 62 43 3 71 13 73 69 88 19 23 10 26 28 81 27 1 86 4 63\n3 0 3 2 1 0 0 1 0 2 0 0 1 0 0 2 1 0 2 1 0 0 1 1 3 1 2 1 1 0 0 0 4 0 0 0 2 0 0 1 1 0 3 3 0 0 0 0 1 2 1 2 1 0 0 0 1 1 0 0 0 3 1 0 0 3 1 2 1 1 2 1 2 1 4 0 1 0 0 0 1 1 0 2 0 4 0 1 0 2 2 0 1 0 1 1 1 0 0 1", "output": "YES" }, { "input": "100 100\n98 31 82 85 31 21 82 23 9 72 13 79 73 63 19 74 5 29 91 24 70 55 36 2 75 49 19 44 39 97 43 51 68 63 79 91 14 14 7 56 50 79 14 43 21 10 29 26 17 18 7 85 65 31 16 55 15 80 36 99 99 97 96 72 3 2 14 33 47 9 71 33 61 11 69 13 12 99 40 5 83 43 99 59 84 62 14 30 12 91 20 12 32 16 65 45 19 72 37 30\n0 0 0 0 0 0 2 0 0 1 0 0 0 2 1 1 1 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 2 0", "output": "YES" }, { "input": "100 100\n46 97 18 86 7 31 2 100 32 67 85 97 62 76 36 88 75 31 46 55 79 37 50 99 9 68 18 97 12 5 65 42 87 86 40 46 87 90 32 68 79 1 40 9 30 50 13 9 73 100 1 90 7 39 65 79 99 86 94 22 49 43 63 78 53 68 89 25 55 66 30 27 77 97 75 70 56 49 54 60 84 16 65 45 47 51 12 70 75 8 13 76 80 84 60 92 15 53 2 3\n2 0 0 0 1 0 1 0 3 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 2 1 1 0 0 0 0 1 0 1 2 0 1 1 0 1 2 1 0 2 2 0 0 1 1 2 1 0 0 0 1 0 0 1 0 3 1 0 3 0 1 0 0 1 0 2 0 1 1 3 0 0 0 0 1 0 2 2 0 1 2 0 0 0 1 0 0 2 0 2 1", "output": "YES" }, { "input": "100 100\n52 93 36 69 49 37 48 42 63 27 16 60 16 63 80 37 69 24 86 38 73 15 43 65 49 35 39 98 91 24 20 35 12 40 75 32 54 4 76 22 23 7 50 86 41 9 9 91 23 18 41 61 47 66 1 79 49 21 99 29 87 94 42 55 87 21 60 67 36 89 40 71 6 63 65 88 17 12 89 32 79 99 34 30 63 33 53 56 10 11 66 80 73 50 47 12 91 42 28 56\n1 0 0 1 0 1 1 0 2 1 1 1 0 0 0 0 1 1 0 0 2 1 2 0 0 0 0 0 1 1 0 2 1 1 0 1 0 0 0 1 2 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 2 0 1 2 1 0 0 0 1 0 1 0 1 1 0 0 2 1 0 0 0 0 0 1 2 1 2 0 1 0 0 1 0 0 0 0 2 0", "output": "YES" }, { "input": "100 100\n95 60 61 26 78 50 77 97 64 8 16 74 43 79 100 37 66 91 1 20 97 70 95 87 42 83 54 66 31 64 57 15 38 76 31 89 76 61 77 22 90 79 59 26 63 60 82 57 3 50 100 9 85 33 32 78 31 50 45 64 93 60 28 84 74 19 51 24 71 32 71 42 77 94 7 81 99 13 42 64 94 65 45 5 95 75 50 100 33 1 46 77 44 81 93 9 39 6 71 93\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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0", "output": "YES" }, { "input": "100 100\n20 7 98 36 47 73 38 11 46 9 98 97 24 60 72 24 14 71 41 24 77 24 23 2 15 12 99 34 14 3 79 74 8 22 57 77 93 62 62 88 32 54 8 5 34 14 46 30 65 20 55 93 76 15 27 18 11 47 80 38 41 14 65 36 75 64 1 16 64 62 33 37 51 7 78 1 39 22 84 91 78 79 77 32 24 48 14 56 21 2 42 60 96 87 23 73 44 24 20 80\n2 0 0 0 0 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 2 2 0 0 0 0 0 0 0 0 0 1 1 1 2 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0", "output": "YES" }, { "input": "100 100\n14 95 7 48 86 65 51 9 5 54 22 58 93 72 31 65 86 27 20 23 24 43 5 78 12 68 60 24 55 55 83 18 1 60 37 62 15 2 5 70 86 93 98 34 45 24 69 66 55 55 74 77 87 55 83 27 46 37 55 12 33 91 1 23 4 78 74 97 8 25 63 63 9 16 60 27 41 18 42 84 35 76 59 8 33 92 40 89 19 23 90 18 30 51 42 62 42 34 75 61\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "YES" }, { "input": "100 100\n94 78 24 48 89 1 2 22 11 42 86 26 7 23 94 100 82 27 24 28 98 62 12 53 67 43 33 45 13 1 80 99 3 79 71 20 26 35 20 69 45 52 39 48 23 3 80 43 60 90 66 43 54 40 93 35 13 20 90 47 55 39 79 2 61 95 83 60 53 4 55 3 33 74 17 38 78 83 83 94 34 43 34 99 46 71 42 58 65 94 65 64 70 88 49 39 2 36 10 55\n0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 1 1 1 0 0 2 0 0 0 1 0 0 0 0 0 1 1 2 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 3 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0", "output": "YES" } ]
1,523,700,240
10,740
PyPy 3
RUNTIME_ERROR
TESTS
5
155
22,425,600
n,m = map(int,input().split()) l = list(map(int,input().split())) k = list(map(int,input().split())) temp = l[0] j = 0 cnt = {l[0]:[1]} for i in range(1,n): if l[i] == temp: cnt[temp][j] += 1 else: temp = l[i] if temp in cnt.keys(): cnt[temp].append(1) j = len(cnt[temp])-1 else: cnt[temp] = [1] j = 0 for i in range(m): if max(cnt[i+1]) < k[i]: print("NO") break else: print("YES")
Title: Lightsabers (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. Heidi has *n* Jedi Knights standing in front of her, each one with a lightsaber of one of *m* possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly *k*1 knights with lightsabers of the first color, *k*2 knights with lightsabers of the second color, ..., *k**m* knights with lightsabers of the *m*-th color. Help her find out if this is possible. Input Specification: The first line of the input contains *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired counts of lightsabers of each color from 1 to *m*. Output Specification: Output YES if an interval with prescribed color counts exists, or output NO if there is none. Demo Input: ['5 2\n1 1 2 2 1\n1 2\n'] Demo Output: ['YES\n'] Note: none
```python n,m = map(int,input().split()) l = list(map(int,input().split())) k = list(map(int,input().split())) temp = l[0] j = 0 cnt = {l[0]:[1]} for i in range(1,n): if l[i] == temp: cnt[temp][j] += 1 else: temp = l[i] if temp in cnt.keys(): cnt[temp].append(1) j = len(cnt[temp])-1 else: cnt[temp] = [1] j = 0 for i in range(m): if max(cnt[i+1]) < k[i]: print("NO") break else: print("YES") ```
-1
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,697,630,751
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x= int(input()) n =[] y =[] count = 0 while x: if len(y) <= 3: y.append(x) if len(y) == 3: n.append(y) y=[] for i in n: for j in i: if j == 1: count +=1 if count >=2: count = 1 return count
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Specification: Print a single integer — the number of problems the friends will implement on the contest. Demo Input: ['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
```python x= int(input()) n =[] y =[] count = 0 while x: if len(y) <= 3: y.append(x) if len(y) == 3: n.append(y) y=[] for i in n: for j in i: if j == 1: count +=1 if count >=2: count = 1 return count ```
-1