contestId
int64 0
1.01k
| name
stringlengths 2
58
| tags
sequencelengths 0
11
| title
stringclasses 523
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
| test_cases
listlengths 0
402
| timeConsumedMillis
int64 0
8k
| memoryConsumedBytes
int64 0
537M
| score
float64 -1
3.99
| __index_level_0__
int64 0
621k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | [
"none"
] | null | null | Dima came to the horse land. There are *n* horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is at most 3.
Right now the horse land is going through an election campaign. So the horses trusted Dima to split them into two parts. At that the horses want the following condition to hold: a horse shouldn't have more than one enemy in its party.
Help Dima split the horses into parties. Note that one of the parties can turn out to be empty. | The first line contains two integers *n*,<=*m* — the number of horses in the horse land and the number of enemy pairs.
Next *m* lines define the enemy pairs. The *i*-th line contains integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*), which mean that horse *a**i* is the enemy of horse *b**i*.
Consider the horses indexed in some way from 1 to *n*. It is guaranteed that each horse has at most three enemies. No pair of enemies occurs more than once in the input. | Print a line, consisting of *n* characters: the *i*-th character of the line must equal "0", if the horse number *i* needs to go to the first party, otherwise this character should equal "1".
If there isn't a way to divide the horses as required, print -1. | [
"3 3\n1 2\n3 2\n3 1\n",
"2 1\n2 1\n",
"10 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n"
] | [
"100\n",
"00\n",
"0110000000\n"
] | none | [] | 62 | 0 | 0 | 3,479 |
|
673 | Problems for Round | [
"greedy",
"implementation"
] | null | null | There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset of each division should be non-empty. - Each problem should be used in exactly one division (yes, it is unusual requirement). - Each problem used in division 1 should be harder than any problem used in division 2. - If two problems are similar, they should be used in different divisions.
Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.
Note, that the relation of similarity is not transitive. That is, if problem *i* is similar to problem *j* and problem *j* is similar to problem *k*, it doesn't follow that *i* is similar to *k*. | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). It's guaranteed, that no pair of problems meets twice in the input. | Print one integer — the number of ways to split problems in two divisions. | [
"5 2\n1 4\n5 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"3 2\n3 1\n3 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together. | [
{
"input": "5 2\n1 4\n5 2",
"output": "2"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "0"
},
{
"input": "3 2\n3 1\n3 2",
"output": "1"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 0",
"output": "2"
},
{
"input": "3 1\n1 2",
"output": "1"
},
{
"input": "3 1\n1 3",
"output": "2"
},
{
"input": "100000 0",
"output": "99999"
},
{
"input": "4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "3 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 2\n1 3",
"output": "1"
},
{
"input": "3 2\n1 2\n2 3",
"output": "0"
},
{
"input": "4 0",
"output": "3"
},
{
"input": "100000 1\n100000 1",
"output": "99999"
},
{
"input": "100000 1\n26711 97965",
"output": "71254"
},
{
"input": "100000 10\n99562 479\n643 99684\n593 99867\n99529 175\n99738 616\n99523 766\n99503 121\n99784 158\n199 99199\n15 99849",
"output": "98433"
},
{
"input": "10 10\n8 3\n2 8\n3 7\n3 9\n9 4\n7 2\n1 8\n1 9\n10 2\n10 1",
"output": "3"
},
{
"input": "55 1\n55 1",
"output": "54"
},
{
"input": "4 2\n1 4\n3 2",
"output": "1"
},
{
"input": "5 1\n1 5",
"output": "4"
},
{
"input": "7 1\n3 5",
"output": "2"
},
{
"input": "7 2\n1 6\n2 7",
"output": "4"
},
{
"input": "5 1\n2 3",
"output": "1"
},
{
"input": "5 2\n3 5\n1 2",
"output": "0"
},
{
"input": "4 2\n3 4\n1 2",
"output": "0"
},
{
"input": "7 2\n1 5\n5 2",
"output": "3"
},
{
"input": "7 2\n1 3\n3 6",
"output": "0"
},
{
"input": "10 11\n1 10\n1 9\n1 8\n1 7\n2 10\n2 9\n2 8\n2 7\n3 10\n3 9\n3 8",
"output": "4"
},
{
"input": "4 2\n1 2\n1 3",
"output": "1"
}
] | 46 | 5,120,000 | 0 | 3,494 |
|
74 | Train | [
"dp",
"games",
"greedy"
] | B. Train | 2 | 256 | A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move.
The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the *n*-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move.
The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of *n* wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back.
Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train.
If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again.
At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. | The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*).
The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon *n* is the tail.
The third line has the length from 1 to 200 and consists of symbols "0" and "1". The *i*-th symbol contains information about the train's state at the *i*-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station. | If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. | [
"5 3 2\nto head\n0001001\n",
"3 2 1\nto tail\n0001\n"
] | [
"Stowaway",
"Controller 2"
] | none | [
{
"input": "5 3 2\nto head\n0001001",
"output": "Stowaway"
},
{
"input": "3 2 1\nto tail\n0001",
"output": "Controller 2"
},
{
"input": "4 2 1\nto tail\n1000001",
"output": "Controller 6"
},
{
"input": "2 1 2\nto head\n111111",
"output": "Stowaway"
},
{
"input": "4 1 4\nto head\n010001",
"output": "Stowaway"
},
{
"input": "10 2 1\nto tail\n000000001",
"output": "Stowaway"
},
{
"input": "5 5 3\nto tail\n01010000000001",
"output": "Controller 10"
},
{
"input": "4 3 1\nto tail\n1000001001101",
"output": "Controller 6"
},
{
"input": "4 1 3\nto head\n011000011000001",
"output": "Controller 14"
},
{
"input": "20 13 9\nto head\n1111111111111111111111111111111111111111",
"output": "Stowaway"
},
{
"input": "2 1 2\nto head\n1101",
"output": "Controller 3"
},
{
"input": "2 2 1\nto tail\n1101",
"output": "Controller 3"
},
{
"input": "2 1 2\nto head\n01",
"output": "Controller 1"
},
{
"input": "2 2 1\nto tail\n01",
"output": "Controller 1"
},
{
"input": "5 4 2\nto tail\n1",
"output": "Stowaway"
},
{
"input": "8 8 7\nto head\n0000000000001",
"output": "Stowaway"
},
{
"input": "8 8 7\nto head\n0000000000000100101000110101011",
"output": "Controller 13"
},
{
"input": "10 3 8\nto head\n01",
"output": "Stowaway"
},
{
"input": "5 1 4\nto head\n1000000000001",
"output": "Controller 7"
},
{
"input": "5 1 3\nto head\n1000000000001",
"output": "Controller 6"
},
{
"input": "3 3 1\nto tail\n1001000001",
"output": "Controller 6"
},
{
"input": "4 3 1\nto tail\n00011110000000010001",
"output": "Controller 3"
},
{
"input": "5 3 4\nto tail\n0001000000101000010010010000100110011",
"output": "Controller 9"
},
{
"input": "6 4 5\nto tail\n0010000101101011001000000100111101101001010011001",
"output": "Stowaway"
},
{
"input": "7 1 7\nto head\n011001001000100000000000000100001100000001100000000010000010011",
"output": "Controller 24"
},
{
"input": "8 5 6\nto tail\n01110101111111111111111111001111111011011111111111101111111111011111101",
"output": "Stowaway"
},
{
"input": "9 7 2\nto head\n1000100010110000101010010000000000010010000010100000001001000000001000000101100000000001",
"output": "Controller 33"
},
{
"input": "10 8 2\nto tail\n0000000000000001000000000000000000000000001000000000010000000000001000000000000000100000000000000001",
"output": "Controller 8"
},
{
"input": "10 1 8\nto tail\n0000000000000000001000010000000001000001000000010000000000000000010010001000001000110010000001010011",
"output": "Controller 11"
},
{
"input": "10 3 6\nto head\n0000001001010100000001010001000110001100011100000100100001100000001100000000000010000001000100100011",
"output": "Controller 5"
},
{
"input": "13 9 8\nto tail\n000000000000000000000000000010011100000000000100100000000010000100000000000000000000000000000000000000010000011",
"output": "Controller 5"
},
{
"input": "17 14 17\nto head\n0000001010000000000000100011000000100000001010000001011000000000001000100000000010100000010001000000000000000100000000000001",
"output": "Stowaway"
},
{
"input": "20 15 7\nto head\n10011111001101010111101110101101101111011110111101001000101111011111011001110010001111111111111101111101011011111010011111111101111011111111",
"output": "Stowaway"
},
{
"input": "26 10 11\nto head\n0000000001001000100000010000110000000011100001000010000000000010000000000000110100000001000000010000110011000000100000000010001100010000000100001110001",
"output": "Stowaway"
},
{
"input": "31 7 15\nto tail\n0010000000000000100000010000010000100000000000000000000001000001100100000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000100001",
"output": "Controller 106"
},
{
"input": "38 7 18\nto tail\n00000000000000000000000000000000000000000000000000000000000000000000000000000001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "Controller 57"
},
{
"input": "42 24 17\nto head\n00000000000000000000100010000000000000000000001000100000000000000000001000000000000010000100100000100000001000000010010000000000101000000000000000010000000000000000000000000011001",
"output": "Stowaway"
},
{
"input": "45 21 37\nto tail\n00000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "Controller 96"
},
{
"input": "49 44 14\nto head\n0000000000000000000000000000000000100000100000000000000000000000010000000000001000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000111001",
"output": "Controller 157"
},
{
"input": "50 4 12\nto tail\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001",
"output": "Stowaway"
},
{
"input": "50 9 39\nto tail\n00000000000000001000000000000000000000000000000000000000000010000000100000000000000001000100000000000000010000000001000000000000000000000000010000000000000000000000000000000000001000000000000000000101",
"output": "Stowaway"
},
{
"input": "50 43 15\nto tail\n00000000000001000000000000000000000000001000000000000000000000001010000000000000000000000010000001000000000000100000000000000000000000000000100000000100000000000001000000000011000000101000010000000001",
"output": "Stowaway"
},
{
"input": "2 2 1\nto tail\n11111101111111011111111111111111111111111111110111111110111111111101111111111001111110111111101011101110110011111011111011101011111111101111111110111111011111111111111111110111111111111111101111101111",
"output": "Controller 7"
},
{
"input": "2 2 1\nto tail\n10111111111111111110111011111111111111111111111111111110111111111110111111101111111111111111111111011111111111111011111111110111111101111111111101111111111111111101111111111111111111111111111001111111",
"output": "Controller 2"
},
{
"input": "3 1 3\nto head\n11111111101111101111011011001011101100101101111111111011011111110011110101010111111101101010010111110110111111011111111111111111111110011111011011101110111111111111100111001110111110111011100111111111",
"output": "Controller 28"
},
{
"input": "3 1 3\nto head\n10111111111111111011110110111111110111011111111111111111110101111111111111101111111111011110111110111111111111111111111111111110111111111111111110001011101111101110111111111111111111110101111111110011",
"output": "Controller 148"
},
{
"input": "4 2 4\nto head\n01101111110010111111111111011110111101000011111110111100111010111110111011010111010110011101101010111100000011001011011101101111010111101001001011101111111111100011110110011010111010111011001011111001",
"output": "Controller 42"
},
{
"input": "50 50 14\nto head\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "Stowaway"
},
{
"input": "50 42 13\nto head\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "Controller 61"
},
{
"input": "50 43 39\nto head\n01100111001110101111000001011111111100101101011010010001000001110001010011001010010100101100110011010011110110011111011101001111110001111001001100011110000111100100010001000011001001100000000010001111",
"output": "Stowaway"
},
{
"input": "3 3 2\nto tail\n0001",
"output": "Controller 1"
},
{
"input": "3 2 3\nto head\n0000000000000000001",
"output": "Controller 2"
}
] | 124 | 307,200 | 3.968428 | 3,516 |
779 | Pupils Redistribution | [
"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 | [
{
"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"
}
] | 15 | 0 | 0 | 3,521 |
|
626 | Block Towers | [
"brute force",
"greedy",
"math",
"number theory"
] | null | null | Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers. | The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=><=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. | Print a single integer, denoting the minimum possible height of the tallest tower. | [
"1 3\n",
"3 2\n",
"5 0\n"
] | [
"9\n",
"8\n",
"10\n"
] | In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks. | [
{
"input": "1 3",
"output": "9"
},
{
"input": "3 2",
"output": "8"
},
{
"input": "5 0",
"output": "10"
},
{
"input": "4 2",
"output": "9"
},
{
"input": "0 1000000",
"output": "3000000"
},
{
"input": "1000000 1",
"output": "2000000"
},
{
"input": "1083 724",
"output": "2710"
},
{
"input": "1184 868",
"output": "3078"
},
{
"input": "1285 877",
"output": "3243"
},
{
"input": "820189 548173",
"output": "2052543"
},
{
"input": "968867 651952",
"output": "2431228"
},
{
"input": "817544 553980",
"output": "2057286"
},
{
"input": "813242 543613",
"output": "2035282"
},
{
"input": "961920 647392",
"output": "2413968"
},
{
"input": "825496 807050",
"output": "2448819"
},
{
"input": "974174 827926",
"output": "2703150"
},
{
"input": "969872 899794",
"output": "2804499"
},
{
"input": "818549 720669",
"output": "2308827"
},
{
"input": "967227 894524",
"output": "2792626"
},
{
"input": "185253 152723",
"output": "506964"
},
{
"input": "195173 150801",
"output": "518961"
},
{
"input": "129439 98443",
"output": "341823"
},
{
"input": "163706 157895",
"output": "482402"
},
{
"input": "197973 140806",
"output": "508168"
},
{
"input": "1000000 1000000",
"output": "3000000"
},
{
"input": "1000000 999999",
"output": "2999998"
},
{
"input": "999999 1000000",
"output": "3000000"
},
{
"input": "500000 500100",
"output": "1500300"
},
{
"input": "500000 166000",
"output": "1000000"
},
{
"input": "500000 499000",
"output": "1498500"
},
{
"input": "500000 167000",
"output": "1000500"
},
{
"input": "1 1000000",
"output": "3000000"
},
{
"input": "2 999123",
"output": "2997369"
},
{
"input": "10 988723",
"output": "2966169"
},
{
"input": "234 298374",
"output": "895122"
},
{
"input": "2365 981235",
"output": "2943705"
},
{
"input": "12345 981732",
"output": "2945196"
},
{
"input": "108752 129872",
"output": "389616"
},
{
"input": "984327 24352",
"output": "1968654"
},
{
"input": "928375 1253",
"output": "1856750"
},
{
"input": "918273 219",
"output": "1836546"
},
{
"input": "987521 53",
"output": "1975042"
},
{
"input": "123456 1",
"output": "246912"
},
{
"input": "789123 0",
"output": "1578246"
},
{
"input": "143568 628524",
"output": "1885572"
},
{
"input": "175983 870607",
"output": "2611821"
},
{
"input": "6 4",
"output": "15"
},
{
"input": "6 3",
"output": "14"
},
{
"input": "7 3",
"output": "15"
},
{
"input": "5 4",
"output": "14"
},
{
"input": "5 3",
"output": "12"
},
{
"input": "8 5",
"output": "20"
},
{
"input": "1 0",
"output": "2"
},
{
"input": "19170 15725",
"output": "52342"
},
{
"input": "3000 2000",
"output": "7500"
},
{
"input": "7 4",
"output": "16"
},
{
"input": "50 30",
"output": "120"
},
{
"input": "300 200",
"output": "750"
},
{
"input": "9 4",
"output": "20"
},
{
"input": "4 3",
"output": "10"
},
{
"input": "1 1",
"output": "3"
},
{
"input": "8 6",
"output": "21"
},
{
"input": "10 6",
"output": "24"
},
{
"input": "65 56",
"output": "182"
},
{
"input": "13 10",
"output": "34"
},
{
"input": "14 42",
"output": "126"
},
{
"input": "651 420",
"output": "1606"
},
{
"input": "8 9",
"output": "27"
},
{
"input": "15 10",
"output": "38"
},
{
"input": "999999 888888",
"output": "2833330"
},
{
"input": "192056 131545",
"output": "485402"
},
{
"input": "32 16",
"output": "72"
},
{
"input": "18 12",
"output": "45"
},
{
"input": "1000000 666667",
"output": "2500000"
},
{
"input": "0 1",
"output": "3"
},
{
"input": "9 5",
"output": "21"
},
{
"input": "1515 1415",
"output": "4395"
},
{
"input": "300000 200000",
"output": "750000"
}
] | 61 | 0 | -1 | 3,524 |
|
733 | Parade | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be *n* columns participating in the parade, the *i*-th column consists of *l**i* soldiers, who start to march from left leg, and *r**i* soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if *L* is the total number of soldiers on the parade who start to march from the left leg, and *R* is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |*L*<=-<=*R*|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index *i* and swap values *l**i* and *r**i*.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9. | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
"input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417",
"output": "4"
},
{
"input": "4\n4 1\n5 3\n7 6\n3 5",
"output": "4"
},
{
"input": "3\n6 5\n9 8\n3 10",
"output": "3"
},
{
"input": "3\n100 9\n1 3\n1 5",
"output": "1"
},
{
"input": "4\n10 1\n10 2\n10 3\n1 10",
"output": "4"
},
{
"input": "5\n25 1\n24 1\n2 3\n2 3\n2 3",
"output": "3"
},
{
"input": "3\n90 1\n1 90\n100 1",
"output": "2"
},
{
"input": "3\n1 123\n22 1\n12 1",
"output": "1"
},
{
"input": "3\n4 5\n7 6\n10 9",
"output": "1"
},
{
"input": "4\n50 1\n50 1\n50 1\n1 49",
"output": "4"
},
{
"input": "7\n2 1\n2 1\n2 1\n2 1\n1 200\n1 200\n1 200",
"output": "1"
},
{
"input": "5\n10 8\n7 6\n2 8\n9 1\n7 1",
"output": "3"
},
{
"input": "3\n22 1\n12 1\n1 123",
"output": "3"
},
{
"input": "3\n10 8\n9 7\n4 5",
"output": "3"
},
{
"input": "5\n1 2\n4 8\n4 8\n32 16\n128 64",
"output": "2"
},
{
"input": "5\n10 1\n10 1\n10 1\n100 1\n1 5",
"output": "5"
}
] | 358 | 2,662,400 | 3 | 3,532 |
|
340 | Iahub and Permutations | [
"combinatorics",
"math"
] | null | null | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the research. The permutation contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*). She replaces some of permutation elements with -1 value as a revenge.
When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element *a**k* which has value equal to *k* (*a**k*<==<=*k*). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109<=+<=7). | The first line contains integer *n* (2<=≤<=*n*<=≤<=2000). On the second line, there are *n* integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109<=+<=7). | [
"5\n-1 -1 4 3 -1\n"
] | [
"2\n"
] | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [
{
"input": "5\n-1 -1 4 3 -1",
"output": "2"
},
{
"input": "8\n2 4 5 3 -1 8 -1 6",
"output": "1"
},
{
"input": "7\n-1 -1 4 -1 7 1 6",
"output": "4"
},
{
"input": "6\n-1 -1 -1 -1 -1 -1",
"output": "265"
},
{
"input": "2\n-1 -1",
"output": "1"
},
{
"input": "10\n4 10 -1 1 6 8 9 2 -1 -1",
"output": "4"
},
{
"input": "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "927799753"
}
] | 124 | 7,065,600 | 0 | 3,534 |
|
0 | none | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* > 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is *min*( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output": "504262064"
},
{
"input": "3 3\n-54481850 -878017339 -486296116",
"output": "-54481850"
},
{
"input": "2 2\n-333653905 224013643",
"output": "224013643"
},
{
"input": "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50",
"output": "-14"
},
{
"input": "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29 494 224 -80 -491 -197 157 130 -52 233 -426 252 -61 -51 203 -50 195 -442 -38 385 232 -243 -49 163 340 -200 406 -254 -29 227 -194 193 487 -325 230 146 421 158 20 447 -97 479 493 -130 164 -471 -198 -330 -152 359 -554 319 544 -444 235 281 -467 337 -385 227 -366 -210 266 69 -261 525 526 -234 -355 177 109 275 -301 7 -41 553 -284 540",
"output": "553"
},
{
"input": "39 1\n676941771 -923780377 -163050076 -230110947 -208029500 329620771 13954060 158950156 -252501602 926390671 -678745080 -921892226 -100127643 610420285 602175224 -839193819 471391946 910035173 777969600 -736144413 -489685522 60986249 830784148 278642552 -375298304 197973611 -354482364 187294011 636628282 25350767 636184407 -550869740 53830680 -42049274 -451383278 900048257 93225803 877923341 -279506435",
"output": "-923780377"
},
{
"input": "3 2\n1 5 3",
"output": "3"
},
{
"input": "5 2\n1 2 5 4 3",
"output": "3"
},
{
"input": "3 2\n1 3 2",
"output": "2"
},
{
"input": "3 2\n1 3 1",
"output": "1"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "-2"
},
{
"input": "5 2\n1 2 3 5 4",
"output": "4"
},
{
"input": "5 2\n1 1 11 1 1",
"output": "1"
},
{
"input": "3 3\n3 8 4",
"output": "8"
},
{
"input": "6 3\n4 3 1 5 6 2",
"output": "6"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "5 2\n2 5 4 3 1",
"output": "2"
},
{
"input": "5 2\n-1 1 5 4 3",
"output": "3"
},
{
"input": "5 2\n5 2 1 9 3",
"output": "5"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "5 2\n1 5 3 4 1",
"output": "1"
},
{
"input": "3 2\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
},
{
"input": "2 2\n5 2",
"output": "5"
},
{
"input": "7 3\n1 1 1 10 1 1 1",
"output": "10"
},
{
"input": "9 3\n1 2 1 1 5 1 1 1 2",
"output": "5"
},
{
"input": "9 3\n2 2 2 2 9 2 2 2 2",
"output": "9"
},
{
"input": "3 3\n-1000000000 -1000000000 -1000000000",
"output": "-1000000000"
}
] | 233 | 13,619,200 | 3 | 3,550 |
|
858 | Tests Renumeration | [
"greedy",
"implementation"
] | null | null | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "*n*', where *n* is the total number of tests.
Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.
The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.
Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:
- all examples are the first several tests having filenames "1", "2", ..., "*e*", where *e* is the total number of examples; - all other files contain regular tests with filenames "*e*<=+<=1", "*e*<=+<=2", ..., "*n*", where *n* is the total number of all tests. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of files with tests.
*n* lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the *i*-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | [
"5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"2\n1 0\n2 1\n",
"5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n"
] | [
"4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"3\nmove 1 3\nmove 2 1\nmove 3 2",
"5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3\n"
] | none | [
{
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"
},
{
"input": "2\n1 0\n2 1",
"output": "3\nmove 1 odt0m5\nmove 2 1\nmove odt0m5 2"
},
{
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0",
"output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3"
},
{
"input": "4\nir7oz8 1\nvj4v5t 1\nkwkahb 1\nj5s8o1 0",
"output": "4\nmove ir7oz8 1\nmove vj4v5t 2\nmove kwkahb 3\nmove j5s8o1 4"
},
{
"input": "4\n3 1\n1o0bp2 0\n9tn379 0\nv04v6j 1",
"output": "4\nmove 3 1\nmove v04v6j 2\nmove 1o0bp2 4\nmove 9tn379 3"
},
{
"input": "4\n1 0\nsc7czx 0\nfr4033 1\n3 0",
"output": "3\nmove 1 4\nmove fr4033 1\nmove sc7czx 2"
},
{
"input": "4\n4 0\n1 0\n2 0\nizfotg 1",
"output": "2\nmove 1 3\nmove izfotg 1"
},
{
"input": "4\n2 0\n3 0\n1 1\n4 1",
"output": "3\nmove 2 fenwk9\nmove 4 2\nmove fenwk9 4"
},
{
"input": "5\npuusew 1\npvoy4h 0\nwdzx4r 0\n1z84cx 0\nozsuvd 0",
"output": "5\nmove puusew 1\nmove pvoy4h 5\nmove wdzx4r 4\nmove 1z84cx 3\nmove ozsuvd 2"
},
{
"input": "5\n949pnr 1\n9sxhcr 0\n5 1\nx8srx3 1\ncl7ppd 1",
"output": "5\nmove 5 1\nmove 949pnr 2\nmove x8srx3 3\nmove cl7ppd 4\nmove 9sxhcr 5"
},
{
"input": "5\n2 0\n1 0\np2gcxf 1\nwfyoiq 1\nzjw3vg 1",
"output": "5\nmove 2 5\nmove 1 4\nmove p2gcxf 1\nmove wfyoiq 2\nmove zjw3vg 3"
},
{
"input": "5\nogvgi7 0\n3 1\n4 1\n1 1\nm5nhux 0",
"output": "3\nmove 4 2\nmove ogvgi7 5\nmove m5nhux 4"
},
{
"input": "5\nt6kdte 1\n2 1\n4 1\n5 1\n3 1",
"output": "1\nmove t6kdte 1"
},
{
"input": "5\n2 0\n3 1\n4 0\n1 1\n5 1",
"output": "3\nmove 2 bgm0kt\nmove 5 2\nmove bgm0kt 5"
},
{
"input": "1\nsd84r7 1",
"output": "1\nmove sd84r7 1"
},
{
"input": "1\n1 0",
"output": "0"
},
{
"input": "2\n5xzjm4 0\njoa6mr 1",
"output": "2\nmove joa6mr 1\nmove 5xzjm4 2"
},
{
"input": "2\n1 0\nxdkh5a 1",
"output": "2\nmove 1 2\nmove xdkh5a 1"
},
{
"input": "2\n1 0\n2 0",
"output": "0"
},
{
"input": "3\nz1nwrd 1\nt0xrja 0\n106qy1 0",
"output": "3\nmove z1nwrd 1\nmove t0xrja 3\nmove 106qy1 2"
},
{
"input": "3\nt4hdos 0\ndhje0g 0\n3 0",
"output": "2\nmove t4hdos 2\nmove dhje0g 1"
},
{
"input": "3\n3 0\n26mp5s 0\n1 1",
"output": "1\nmove 26mp5s 2"
},
{
"input": "3\n2 1\n1 0\n3 0",
"output": "3\nmove 2 4s2egb\nmove 1 2\nmove 4s2egb 1"
},
{
"input": "1\nprzvln 0",
"output": "1\nmove przvln 1"
},
{
"input": "2\nkfsipl 0\n1jj1ol 0",
"output": "2\nmove kfsipl 2\nmove 1jj1ol 1"
},
{
"input": "3\n2x7a4g 0\n27lqe6 0\nzfo3sp 0",
"output": "3\nmove 2x7a4g 3\nmove 27lqe6 2\nmove zfo3sp 1"
},
{
"input": "1\nxzp9ni 1",
"output": "1\nmove xzp9ni 1"
},
{
"input": "1\nabbdf7 1",
"output": "1\nmove abbdf7 1"
},
{
"input": "2\ndbif39 1\ne8dkf8 0",
"output": "2\nmove dbif39 1\nmove e8dkf8 2"
},
{
"input": "2\n2 0\njkwekx 1",
"output": "1\nmove jkwekx 1"
},
{
"input": "3\nn3pmj8 0\n2alui6 0\ne7lf4u 1",
"output": "3\nmove e7lf4u 1\nmove n3pmj8 3\nmove 2alui6 2"
},
{
"input": "3\ndr1lp8 0\n1 0\n6a2egk 1",
"output": "3\nmove 1 3\nmove 6a2egk 1\nmove dr1lp8 2"
},
{
"input": "4\nyi9ta0 1\nmeljgm 0\nf7bqon 0\n5bbvun 0",
"output": "4\nmove yi9ta0 1\nmove meljgm 4\nmove f7bqon 3\nmove 5bbvun 2"
},
{
"input": "4\n0la3gu 0\nzhrmyb 1\n3iprc0 0\n3 0",
"output": "3\nmove zhrmyb 1\nmove 0la3gu 4\nmove 3iprc0 2"
},
{
"input": "1\n1 1",
"output": "0"
},
{
"input": "1\n1 1",
"output": "0"
},
{
"input": "2\n17dgbb 0\n2 1",
"output": "2\nmove 2 1\nmove 17dgbb 2"
},
{
"input": "2\n1 0\n2 1",
"output": "3\nmove 1 nupgt5\nmove 2 1\nmove nupgt5 2"
},
{
"input": "3\nscrn8k 0\n3 1\nycvm9s 0",
"output": "3\nmove 3 1\nmove scrn8k 3\nmove ycvm9s 2"
},
{
"input": "3\nt0dfz3 0\n3 0\n1 1",
"output": "1\nmove t0dfz3 2"
},
{
"input": "4\nkgw83p 0\np3p3ch 0\n4 1\n0te9lv 0",
"output": "4\nmove 4 1\nmove kgw83p 4\nmove p3p3ch 3\nmove 0te9lv 2"
},
{
"input": "4\n3 1\nnj94jx 0\n3a5ad1 0\n1 0",
"output": "4\nmove 1 4\nmove 3 1\nmove nj94jx 3\nmove 3a5ad1 2"
},
{
"input": "2\no9z069 1\n5hools 1",
"output": "2\nmove o9z069 1\nmove 5hools 2"
},
{
"input": "2\nyzzyab 1\n728oq0 1",
"output": "2\nmove yzzyab 1\nmove 728oq0 2"
},
{
"input": "2\nqy2kmc 1\nqb4crj 1",
"output": "2\nmove qy2kmc 1\nmove qb4crj 2"
},
{
"input": "3\nunw560 1\n0iswxk 0\ndonjp9 1",
"output": "3\nmove unw560 1\nmove donjp9 2\nmove 0iswxk 3"
},
{
"input": "3\n2 0\nuv8c54 1\n508bb0 1",
"output": "3\nmove 2 3\nmove uv8c54 1\nmove 508bb0 2"
},
{
"input": "3\n9afh0z 1\n0qcaht 1\n3 0",
"output": "2\nmove 9afh0z 1\nmove 0qcaht 2"
},
{
"input": "4\n2kk04q 0\nkdktvk 1\nc4i5k8 1\nawaock 0",
"output": "4\nmove kdktvk 1\nmove c4i5k8 2\nmove 2kk04q 4\nmove awaock 3"
},
{
"input": "4\n2 0\nmqbjos 0\n6mhijg 1\n6wum8y 1",
"output": "4\nmove 2 4\nmove 6mhijg 1\nmove 6wum8y 2\nmove mqbjos 3"
},
{
"input": "4\n4 0\npa613p 1\nuuizq7 1\n2 0",
"output": "3\nmove 2 3\nmove pa613p 1\nmove uuizq7 2"
},
{
"input": "5\nw0g96a 1\nv99tdi 0\nmywrle 0\nweh22w 1\n9hywt4 0",
"output": "5\nmove w0g96a 1\nmove weh22w 2\nmove v99tdi 5\nmove mywrle 4\nmove 9hywt4 3"
},
{
"input": "5\n5 0\n12qcjd 1\nuthzbz 0\nb3670z 0\nl2u93o 1",
"output": "4\nmove 12qcjd 1\nmove l2u93o 2\nmove uthzbz 4\nmove b3670z 3"
},
{
"input": "5\n0jc7xb 1\n2 0\n1m7l9s 0\n9xzkau 1\n1 0",
"output": "5\nmove 2 5\nmove 1 4\nmove 0jc7xb 1\nmove 9xzkau 2\nmove 1m7l9s 3"
},
{
"input": "2\n1 1\nvinxur 1",
"output": "1\nmove vinxur 2"
},
{
"input": "2\n1qe46n 1\n1 1",
"output": "1\nmove 1qe46n 2"
},
{
"input": "2\n1 1\ng5jlzp 1",
"output": "1\nmove g5jlzp 2"
},
{
"input": "3\nc8p28p 1\n2 1\nvk4gdf 0",
"output": "2\nmove c8p28p 1\nmove vk4gdf 3"
},
{
"input": "3\n2 1\n3 0\nhs9j9t 1",
"output": "1\nmove hs9j9t 1"
},
{
"input": "3\n2 1\n1 0\nomitxh 1",
"output": "2\nmove 1 3\nmove omitxh 1"
},
{
"input": "4\n4 1\nu9do88 1\n787at9 0\nfcud6k 0",
"output": "4\nmove 4 1\nmove u9do88 2\nmove 787at9 4\nmove fcud6k 3"
},
{
"input": "4\n3 0\nqvw4ow 1\nne0ng9 0\n1 1",
"output": "2\nmove qvw4ow 2\nmove ne0ng9 4"
},
{
"input": "4\ng6ugrm 1\n1 1\n3 0\n2 0",
"output": "2\nmove 2 4\nmove g6ugrm 2"
},
{
"input": "5\n5 1\nz9zr7d 0\ne8rwo4 1\nrfpjp6 0\ngz6dhj 0",
"output": "5\nmove 5 1\nmove e8rwo4 2\nmove z9zr7d 5\nmove rfpjp6 4\nmove gz6dhj 3"
},
{
"input": "5\n5sn77g 0\nsetddt 1\nbz16cb 0\n4 1\n2 0",
"output": "5\nmove 4 1\nmove 2 5\nmove setddt 2\nmove 5sn77g 4\nmove bz16cb 3"
},
{
"input": "5\n1 1\nx2miqh 1\n3 0\n2 0\n1rq643 0",
"output": "3\nmove 2 5\nmove x2miqh 2\nmove 1rq643 4"
},
{
"input": "2\n1 1\n2 1",
"output": "0"
},
{
"input": "2\n1 1\n2 1",
"output": "0"
},
{
"input": "2\n2 1\n1 1",
"output": "0"
},
{
"input": "3\n3 1\nav5vex 0\n1 1",
"output": "2\nmove 3 2\nmove av5vex 3"
},
{
"input": "3\n3 1\n1 0\n2 1",
"output": "3\nmove 3 q62zhl\nmove 1 3\nmove q62zhl 1"
},
{
"input": "3\n3 1\n1 0\n2 1",
"output": "3\nmove 3 dlzik6\nmove 1 3\nmove dlzik6 1"
},
{
"input": "4\ny9144q 0\n3 1\n2 1\ns0bdnf 0",
"output": "3\nmove 3 1\nmove y9144q 4\nmove s0bdnf 3"
},
{
"input": "4\n4 1\n1 0\n3 1\nmod9zl 0",
"output": "4\nmove 4 2\nmove 1 4\nmove 3 1\nmove mod9zl 3"
},
{
"input": "4\n4 1\n3 1\n1 0\n2 0",
"output": "5\nmove 4 dlzik6\nmove 1 4\nmove 3 1\nmove 2 3\nmove dlzik6 2"
},
{
"input": "5\n1 1\nnoidnv 0\n3 1\nx3xiiz 0\n1lfa9v 0",
"output": "4\nmove 3 2\nmove noidnv 5\nmove x3xiiz 4\nmove 1lfa9v 3"
},
{
"input": "5\n1 1\nvsyajx 0\n783b38 0\n4 0\n2 1",
"output": "2\nmove vsyajx 5\nmove 783b38 3"
},
{
"input": "5\n3 1\n5 0\ncvfl8i 0\n4 1\n2 0",
"output": "4\nmove 3 1\nmove 2 3\nmove 4 2\nmove cvfl8i 4"
},
{
"input": "3\nbxo0pe 1\nbt50pa 1\n2tx68t 1",
"output": "3\nmove bxo0pe 1\nmove bt50pa 2\nmove 2tx68t 3"
},
{
"input": "3\nj9rnac 1\noetwfz 1\nd6n3ww 1",
"output": "3\nmove j9rnac 1\nmove oetwfz 2\nmove d6n3ww 3"
},
{
"input": "3\naf2f6j 1\nmjni5l 1\njvyxgc 1",
"output": "3\nmove af2f6j 1\nmove mjni5l 2\nmove jvyxgc 3"
},
{
"input": "3\nr2qlj2 1\nt8wf1y 1\nigids8 1",
"output": "3\nmove r2qlj2 1\nmove t8wf1y 2\nmove igids8 3"
},
{
"input": "4\nuilh9a 0\n4lxxh9 1\nkqdpzy 1\nn1d7hd 1",
"output": "4\nmove 4lxxh9 1\nmove kqdpzy 2\nmove n1d7hd 3\nmove uilh9a 4"
},
{
"input": "4\n3 0\niipymv 1\nvakd5b 1\n2ktczv 1",
"output": "4\nmove 3 4\nmove iipymv 1\nmove vakd5b 2\nmove 2ktczv 3"
},
{
"input": "4\nq4b449 1\n3 0\ncjg1x2 1\ne878er 1",
"output": "4\nmove 3 4\nmove q4b449 1\nmove cjg1x2 2\nmove e878er 3"
},
{
"input": "4\n9f4aoa 1\n4 0\nf4m1ec 1\nqyr2h6 1",
"output": "3\nmove 9f4aoa 1\nmove f4m1ec 2\nmove qyr2h6 3"
},
{
"input": "5\n73s1nt 1\nsbngv2 0\n4n3qri 1\nbyhzp8 1\nadpjs4 0",
"output": "5\nmove 73s1nt 1\nmove 4n3qri 2\nmove byhzp8 3\nmove sbngv2 5\nmove adpjs4 4"
},
{
"input": "5\n7ajg8o 1\np7cqxy 1\n3qrp34 0\nh93m07 1\n2 0",
"output": "5\nmove 2 5\nmove 7ajg8o 1\nmove p7cqxy 2\nmove h93m07 3\nmove 3qrp34 4"
},
{
"input": "5\ny0wnwz 1\n5 0\n0totai 1\n1 0\nym8xwz 1",
"output": "4\nmove 1 4\nmove y0wnwz 1\nmove 0totai 2\nmove ym8xwz 3"
},
{
"input": "5\n5 0\n4 0\n5nvzu4 1\nvkpzzk 1\nzamzcz 1",
"output": "3\nmove 5nvzu4 1\nmove vkpzzk 2\nmove zamzcz 3"
},
{
"input": "6\np1wjw9 1\nueksby 0\nu1ixfc 1\nj3lk2e 1\n36iskv 0\n9imqi1 0",
"output": "6\nmove p1wjw9 1\nmove u1ixfc 2\nmove j3lk2e 3\nmove ueksby 6\nmove 36iskv 5\nmove 9imqi1 4"
},
{
"input": "6\n6slonw 1\nptk9mc 1\n57a4nq 0\nhiq2f7 1\n2 0\nc0gtv3 0",
"output": "6\nmove 2 6\nmove 6slonw 1\nmove ptk9mc 2\nmove hiq2f7 3\nmove 57a4nq 5\nmove c0gtv3 4"
},
{
"input": "6\n5 0\n2 0\ncbhvyf 1\nl1z5mg 0\nwkwhby 1\nx7fdh9 1",
"output": "5\nmove 2 6\nmove cbhvyf 1\nmove wkwhby 2\nmove x7fdh9 3\nmove l1z5mg 4"
},
{
"input": "6\n1t68ks 1\npkbj1g 1\n5 0\n5pw8wm 1\n1 0\n4 0",
"output": "4\nmove 1 6\nmove 1t68ks 1\nmove pkbj1g 2\nmove 5pw8wm 3"
},
{
"input": "3\n1 1\n7ph5fw 1\ntfxz1j 1",
"output": "2\nmove 7ph5fw 2\nmove tfxz1j 3"
},
{
"input": "3\norwsz0 1\nmbt097 1\n3 1",
"output": "2\nmove orwsz0 1\nmove mbt097 2"
},
{
"input": "3\n1 1\nzwfnx2 1\n7g8t6z 1",
"output": "2\nmove zwfnx2 2\nmove 7g8t6z 3"
},
{
"input": "3\nqmf7iz 1\ndjwdce 1\n1 1",
"output": "2\nmove qmf7iz 2\nmove djwdce 3"
},
{
"input": "4\n4i2i2a 0\n4 1\npf618n 1\nlx6nmh 1",
"output": "4\nmove 4 1\nmove pf618n 2\nmove lx6nmh 3\nmove 4i2i2a 4"
},
{
"input": "4\nxpteku 1\n1 0\n4 1\n73xpqz 1",
"output": "4\nmove 4 2\nmove 1 4\nmove xpteku 1\nmove 73xpqz 3"
},
{
"input": "4\n1wp56i 1\n2 1\n1 0\n6m76jb 1",
"output": "3\nmove 1 4\nmove 1wp56i 1\nmove 6m76jb 3"
},
{
"input": "4\n3 1\nyumiqt 1\n1 0\nt19jus 1",
"output": "3\nmove 1 4\nmove yumiqt 1\nmove t19jus 2"
},
{
"input": "5\nynagvf 1\n3 1\nojz4mm 1\ndovec3 0\nnc1jye 0",
"output": "4\nmove ynagvf 1\nmove ojz4mm 2\nmove dovec3 5\nmove nc1jye 4"
},
{
"input": "5\n5 1\nwje9ts 1\nkytn5q 1\n7frk8z 0\n3 0",
"output": "5\nmove 5 1\nmove 3 5\nmove wje9ts 2\nmove kytn5q 3\nmove 7frk8z 4"
},
{
"input": "5\n1 0\n4 1\n3 0\nlog9cm 1\nu5m0ls 1",
"output": "5\nmove 4 2\nmove 1 5\nmove 3 4\nmove log9cm 1\nmove u5m0ls 3"
},
{
"input": "5\nh015vv 1\n3 1\n1 0\n9w2keb 1\n2 0",
"output": "4\nmove 1 5\nmove 2 4\nmove h015vv 1\nmove 9w2keb 2"
},
{
"input": "6\n0zluka 0\nqp7q8l 1\nwglqu8 1\n9i7kta 0\nnwf8m3 0\n3 1",
"output": "5\nmove qp7q8l 1\nmove wglqu8 2\nmove 0zluka 6\nmove 9i7kta 5\nmove nwf8m3 4"
},
{
"input": "6\n3 1\n1h3t85 1\n5 0\nrf2ikt 0\n3vhl6e 1\n5l3oka 0",
"output": "4\nmove 1h3t85 1\nmove 3vhl6e 2\nmove rf2ikt 6\nmove 5l3oka 4"
},
{
"input": "6\n2 0\n3 0\nw9h0pv 1\n5 1\nq92z4i 0\n6qb4ia 1",
"output": "6\nmove 5 1\nmove 2 6\nmove 3 5\nmove w9h0pv 2\nmove 6qb4ia 3\nmove q92z4i 4"
},
{
"input": "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0",
"output": "4\nmove 4 2\nmove 1 4\nmove 410jiy 1\nmove xc98l2 3"
},
{
"input": "3\n1 1\nc9qyld 1\n3 1",
"output": "1\nmove c9qyld 2"
},
{
"input": "3\ngdm5ri 1\n1 1\n2 1",
"output": "1\nmove gdm5ri 3"
},
{
"input": "3\n3 1\n2 1\ni19lnk 1",
"output": "1\nmove i19lnk 1"
},
{
"input": "3\ncxbbpd 1\n3 1\n1 1",
"output": "1\nmove cxbbpd 2"
},
{
"input": "4\nwy6i6o 0\n1 1\n3 1\niy1dq6 1",
"output": "2\nmove iy1dq6 2\nmove wy6i6o 4"
},
{
"input": "4\n4 1\nwgh8s0 1\n1 0\n2 1",
"output": "3\nmove 4 3\nmove 1 4\nmove wgh8s0 1"
},
{
"input": "4\nhex0ur 1\n4 1\n3 0\n2 1",
"output": "3\nmove 4 1\nmove 3 4\nmove hex0ur 3"
},
{
"input": "4\n4 1\n1 1\n3 0\n4soxj3 1",
"output": "3\nmove 4 2\nmove 3 4\nmove 4soxj3 3"
},
{
"input": "5\n5sbtul 1\n2 1\n8i2duz 0\n5 1\n4b85z6 0",
"output": "4\nmove 5 1\nmove 5sbtul 3\nmove 8i2duz 5\nmove 4b85z6 4"
},
{
"input": "5\n3 1\n4 0\nejo0a4 1\ngqzdbk 0\n1 1",
"output": "2\nmove ejo0a4 2\nmove gqzdbk 5"
},
{
"input": "5\n2y4agr 1\n5 0\n3 0\n1 1\n4 1",
"output": "3\nmove 4 2\nmove 3 4\nmove 2y4agr 3"
},
{
"input": "5\n2 0\n1 1\nq4hyeg 1\n5 0\n4 1",
"output": "3\nmove 4 3\nmove 2 4\nmove q4hyeg 2"
},
{
"input": "6\n5 1\nrdm6fu 0\n4 1\noclx1h 0\n7l3kg1 1\nq25te0 0",
"output": "6\nmove 5 1\nmove 4 2\nmove 7l3kg1 3\nmove rdm6fu 6\nmove oclx1h 5\nmove q25te0 4"
},
{
"input": "6\n1 0\np4tuyt 0\n5 1\n2 1\nwrrcmu 1\n3r4wqz 0",
"output": "5\nmove 5 3\nmove 1 6\nmove wrrcmu 1\nmove p4tuyt 5\nmove 3r4wqz 4"
},
{
"input": "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9mqv 1",
"output": "4\nmove 5 2\nmove 1 5\nmove 1n9mqv 1\nmove xhfzge 4"
},
{
"input": "6\nhmpfsz 1\n6 0\n5 1\n4 0\n1 0\n3 1",
"output": "3\nmove 5 2\nmove 1 5\nmove hmpfsz 1"
},
{
"input": "3\n1 1\n3 1\n2 1",
"output": "0"
},
{
"input": "3\n2 1\n3 1\n1 1",
"output": "0"
},
{
"input": "3\n2 1\n1 1\n3 1",
"output": "0"
},
{
"input": "3\n1 1\n2 1\n3 1",
"output": "0"
},
{
"input": "4\n3 1\n1 1\n4 1\nd1cks2 0",
"output": "2\nmove 4 2\nmove d1cks2 4"
},
{
"input": "4\n4 0\n3 1\n1 1\n2 1",
"output": "0"
},
{
"input": "4\n2 1\n4 1\n1 0\n3 1",
"output": "3\nmove 4 k989jx\nmove 1 4\nmove k989jx 1"
},
{
"input": "4\n4 1\n1 1\n3 1\n2 0",
"output": "3\nmove 4 vmncdr\nmove 2 4\nmove vmncdr 2"
},
{
"input": "5\n4 1\nhvshea 0\naio11n 0\n2 1\n3 1",
"output": "3\nmove 4 1\nmove hvshea 5\nmove aio11n 4"
},
{
"input": "5\n5 0\nts7a1c 0\n4 1\n1 1\n2 1",
"output": "2\nmove 4 3\nmove ts7a1c 4"
},
{
"input": "5\n4 0\n3 1\n5 0\n2 1\n1 1",
"output": "0"
},
{
"input": "5\n3 1\n5 0\n4 1\n1 1\n2 0",
"output": "3\nmove 4 k989jx\nmove 2 4\nmove k989jx 2"
},
{
"input": "6\neik3kw 0\n5 1\nzoonoj 0\n2 1\n1 1\nivzfie 0",
"output": "4\nmove 5 3\nmove eik3kw 6\nmove zoonoj 5\nmove ivzfie 4"
},
{
"input": "6\n7igwk9 0\n6 1\n5 1\ndx2yu0 0\n2 0\n1 1",
"output": "5\nmove 6 3\nmove 2 6\nmove 5 2\nmove 7igwk9 5\nmove dx2yu0 4"
},
{
"input": "6\nc3py3h 0\n2 1\n4 0\n3 0\n1 1\n5 1",
"output": "3\nmove 3 6\nmove 5 3\nmove c3py3h 5"
},
{
"input": "6\n1 1\n3 0\n2 1\n6 1\n4 0\n5 0",
"output": "3\nmove 3 byoday\nmove 6 3\nmove byoday 6"
},
{
"input": "20\nphp8vy 1\nkeeona 0\n8 0\nwzf4eb 0\n16 1\n9 0\nf2548d 0\n11 0\nyszsig 0\nyyf4q2 0\n1pon1p 1\njvpwuo 0\nd9stsx 0\ne14bkx 1\n5 0\n17 0\nsbklx4 0\nsfms2u 1\n6 0\n18 1",
"output": "16\nmove 16 1\nmove 18 2\nmove 5 20\nmove 6 19\nmove php8vy 3\nmove 1pon1p 4\nmove e14bkx 5\nmove sfms2u 6\nmove keeona 18\nmove wzf4eb 16\nmove f2548d 15\nmove yszsig 14\nmove yyf4q2 13\nmove jvpwuo 12\nmove d9stsx 10\nmove sbklx4 7"
},
{
"input": "4\n3 1\n4 1\n1 0\n2 0",
"output": "5\nmove 3 gcfqe4\nmove 1 3\nmove 4 1\nmove 2 4\nmove gcfqe4 2"
},
{
"input": "1\n01 1",
"output": "1\nmove 01 1"
},
{
"input": "2\n01 0\n02 1",
"output": "2\nmove 02 1\nmove 01 2"
}
] | 46 | 0 | 0 | 3,560 |
|
818 | Multicolored Cars | [
"data structures",
"implementation"
] | null | null | Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after *i*-th car *cnt**A*(*i*) and *cnt**B*(*i*).
- If *cnt**A*(*i*)<=><=*cnt**B*(*i*) for every *i* then the winner is Alice. - If *cnt**B*(*i*)<=≥<=*cnt**A*(*i*) for every *i* then the winner is Bob. - Otherwise it's a draw.
Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color *A* and Bob now wants to choose such color *B* that he will win the game (draw is not a win). Help him find this color.
If there are multiple solutions, print any of them. If there is no such color then print -1. | The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice.
The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their appearance. | Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106). | [
"4 1\n2 1 4 2\n",
"5 2\n2 2 4 5 3\n",
"3 10\n1 2 3\n"
] | [
"2\n",
"-1\n",
"4\n"
] | Let's consider availability of colors in the first example:
- *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning one for Bob. - All the other colors also have *cnt*<sub class="lower-index">*j*</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), thus they are not available.
In the third example every color is acceptable except for 10. | [
{
"input": "4 1\n2 1 4 2",
"output": "2"
},
{
"input": "5 2\n2 2 4 5 3",
"output": "-1"
},
{
"input": "3 10\n1 2 3",
"output": "4"
},
{
"input": "1 1\n2",
"output": "3"
},
{
"input": "1 2\n2",
"output": "-1"
},
{
"input": "10 6\n8 5 1 6 6 5 10 6 9 8",
"output": "-1"
},
{
"input": "7 2\n1 2 2 1 1 1 1",
"output": "-1"
},
{
"input": "8 2\n1 1 3 2 3 2 3 2",
"output": "3"
},
{
"input": "10 9\n6 4 7 1 8 9 5 9 4 5",
"output": "-1"
},
{
"input": "6 1\n2 3 3 1 1 2",
"output": "3"
},
{
"input": "4 1\n2 1 1 2",
"output": "-1"
},
{
"input": "5 1\n3 2 1 2 1",
"output": "2"
},
{
"input": "5 3\n1 2 3 2 3",
"output": "2"
},
{
"input": "1 1000000\n1",
"output": "2"
},
{
"input": "6 3\n1 2 3 2 3 2",
"output": "2"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "6 2\n5 3 2 4 4 2",
"output": "-1"
},
{
"input": "6 1\n5 2 1 4 2 1",
"output": "2"
},
{
"input": "6 1\n2 2 2 1 1 1",
"output": "2"
},
{
"input": "5 2\n3 1 1 2 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "30 1\n2 2 2 2 2 3 3 3 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 1 1 1",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "-1"
},
{
"input": "5 3\n1 2 2 3 3",
"output": "2"
},
{
"input": "10 1000000\n1 2 3 4 5 6 7 8 9 10",
"output": "11"
},
{
"input": "6 1\n3 1 2 2 3 1",
"output": "3"
},
{
"input": "5 1\n2 3 3 1 1",
"output": "3"
},
{
"input": "9 1\n2 3 3 1 4 1 3 2 1",
"output": "3"
},
{
"input": "10 9\n8 9 1 1 1 1 1 1 1 9",
"output": "-1"
},
{
"input": "13 2\n3 3 3 2 1 1 1 1 1 2 3 2 2",
"output": "3"
},
{
"input": "5 1\n2 3 1 3 1",
"output": "3"
},
{
"input": "8 7\n6 7 2 2 4 5 4 4",
"output": "6"
},
{
"input": "2 7\n6 7",
"output": "6"
},
{
"input": "3 5\n9 5 7",
"output": "9"
},
{
"input": "6 2\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 3\n1000 2 3 2 2 3",
"output": "2"
},
{
"input": "10 5\n1 1 1 1 1 5 5 5 5 5",
"output": "1"
},
{
"input": "4 9\n4 9 9 4",
"output": "-1"
},
{
"input": "4 1\n2 1 3 3",
"output": "2"
},
{
"input": "19 3\n1 2 3 1 2 3 1 2 3 5 5 5 5 5 5 5 5 2 3",
"output": "2"
},
{
"input": "15 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1 5",
"output": "5"
},
{
"input": "14 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1",
"output": "5"
},
{
"input": "8 5\n1 2 5 1 2 5 2 5",
"output": "2"
},
{
"input": "5 1000000\n1 2 1000000 2 1",
"output": "1"
},
{
"input": "8 2\n1 2 1 3 2 3 3 3",
"output": "1"
},
{
"input": "9 10\n4 9 7 3 3 3 10 3 10",
"output": "3"
},
{
"input": "6 2\n5 3 9 2 10 1",
"output": "3"
},
{
"input": "10 4\n7 5 4 4 1 5 7 9 10 6",
"output": "-1"
},
{
"input": "2 1\n9 1",
"output": "9"
},
{
"input": "3 7\n5 7 1",
"output": "5"
},
{
"input": "6 3\n1 3 5 4 2 3",
"output": "-1"
},
{
"input": "7 1\n7 3 1 4 5 8 5",
"output": "3"
},
{
"input": "2 3\n6 3",
"output": "6"
},
{
"input": "10 8\n2 8 8 9 6 9 1 3 2 4",
"output": "-1"
},
{
"input": "6 1\n1 7 8 4 8 6",
"output": "-1"
}
] | 2,000 | 9,216,000 | 0 | 3,561 |
|
899 | Shovel Sale | [
"constructive algorithms",
"math"
] | null | null | There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.
Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.
You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=109) — the number of shovels in Polycarp's shop. | Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.
Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.
It is guaranteed that for every *n*<=≤<=109 the answer doesn't exceed 2·109. | [
"7\n",
"14\n",
"50\n"
] | [
"3\n",
"9\n",
"1\n"
] | In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:
- 2 and 7; - 3 and 6; - 4 and 5.
In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp:
- 1 and 8; - 2 and 7; - 3 and 6; - 4 and 5; - 5 and 14; - 6 and 13; - 7 and 12; - 8 and 11; - 9 and 10.
In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for *n* = 50. | [
{
"input": "7",
"output": "3"
},
{
"input": "14",
"output": "9"
},
{
"input": "50",
"output": "1"
},
{
"input": "999999999",
"output": "499999999"
},
{
"input": "15",
"output": "11"
},
{
"input": "3",
"output": "3"
},
{
"input": "6500",
"output": "1501"
},
{
"input": "4",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "10",
"output": "5"
},
{
"input": "499999",
"output": "1249995"
},
{
"input": "6",
"output": "2"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "4"
},
{
"input": "11",
"output": "6"
},
{
"input": "12",
"output": "7"
},
{
"input": "5",
"output": "1"
},
{
"input": "16",
"output": "13"
},
{
"input": "17",
"output": "15"
},
{
"input": "18",
"output": "17"
},
{
"input": "19",
"output": "18"
},
{
"input": "20",
"output": "20"
},
{
"input": "21",
"output": "22"
},
{
"input": "22",
"output": "24"
},
{
"input": "23",
"output": "26"
},
{
"input": "24",
"output": "28"
},
{
"input": "25",
"output": "31"
},
{
"input": "26",
"output": "34"
},
{
"input": "27",
"output": "37"
},
{
"input": "28",
"output": "40"
},
{
"input": "29",
"output": "42"
},
{
"input": "30",
"output": "45"
},
{
"input": "31",
"output": "48"
},
{
"input": "32",
"output": "51"
},
{
"input": "33",
"output": "54"
},
{
"input": "34",
"output": "57"
},
{
"input": "35",
"output": "61"
},
{
"input": "36",
"output": "65"
},
{
"input": "37",
"output": "69"
},
{
"input": "38",
"output": "73"
},
{
"input": "39",
"output": "76"
},
{
"input": "40",
"output": "80"
},
{
"input": "41",
"output": "84"
},
{
"input": "42",
"output": "88"
},
{
"input": "43",
"output": "92"
},
{
"input": "44",
"output": "96"
},
{
"input": "45",
"output": "101"
},
{
"input": "46",
"output": "106"
},
{
"input": "47",
"output": "111"
},
{
"input": "48",
"output": "116"
},
{
"input": "49",
"output": "120"
},
{
"input": "51",
"output": "2"
},
{
"input": "100",
"output": "50"
},
{
"input": "99",
"output": "49"
},
{
"input": "101",
"output": "51"
},
{
"input": "4999",
"output": "12495"
},
{
"input": "4998",
"output": "12491"
},
{
"input": "4992",
"output": "12461"
},
{
"input": "5000",
"output": "1"
},
{
"input": "5001",
"output": "2"
},
{
"input": "10000",
"output": "5000"
},
{
"input": "10001",
"output": "5001"
},
{
"input": "49839",
"output": "124196"
},
{
"input": "4999999",
"output": "12499995"
},
{
"input": "49999999",
"output": "124999995"
},
{
"input": "499999999",
"output": "1249999995"
},
{
"input": "999",
"output": "499"
},
{
"input": "9999",
"output": "4999"
},
{
"input": "99999",
"output": "49999"
},
{
"input": "999999",
"output": "499999"
},
{
"input": "9999999",
"output": "4999999"
},
{
"input": "99999999",
"output": "49999999"
},
{
"input": "2",
"output": "1"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "764675465",
"output": "264675466"
},
{
"input": "499999998",
"output": "1249999991"
},
{
"input": "167959139",
"output": "135918279"
},
{
"input": "641009859",
"output": "141009860"
},
{
"input": "524125987",
"output": "24125988"
},
{
"input": "702209411",
"output": "202209412"
},
{
"input": "585325539",
"output": "85325540"
},
{
"input": "58376259",
"output": "8376260"
},
{
"input": "941492387",
"output": "441492388"
},
{
"input": "824608515",
"output": "324608516"
},
{
"input": "2691939",
"output": "3575818"
},
{
"input": "802030518",
"output": "302030519"
},
{
"input": "685146646",
"output": "185146647"
},
{
"input": "863230070",
"output": "363230071"
},
{
"input": "41313494",
"output": "85253976"
},
{
"input": "219396918",
"output": "238793836"
},
{
"input": "102513046",
"output": "52513046"
},
{
"input": "985629174",
"output": "485629175"
},
{
"input": "458679894",
"output": "1043399471"
},
{
"input": "341796022",
"output": "575388066"
},
{
"input": "519879446",
"output": "19879447"
},
{
"input": "452405440",
"output": "1012027201"
},
{
"input": "335521569",
"output": "556564707"
},
{
"input": "808572289",
"output": "308572290"
},
{
"input": "691688417",
"output": "191688418"
},
{
"input": "869771841",
"output": "369771842"
},
{
"input": "752887969",
"output": "252887970"
},
{
"input": "930971393",
"output": "430971394"
},
{
"input": "109054817",
"output": "59054817"
},
{
"input": "992170945",
"output": "492170946"
},
{
"input": "170254369",
"output": "140508739"
},
{
"input": "248004555",
"output": "296009110"
}
] | 46 | 0 | 0 | 3,563 |
|
234 | Weather | [
"dp",
"implementation"
] | null | null | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last *n* days. Thus, he got a sequence of numbers *t*1,<=*t*2,<=...,<=*t**n*, where the *i*-th number is the temperature on the *i*-th day.
Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer *k* (1<=≤<=*k*<=≤<=*n*<=-<=1) such that *t*1<=<<=0,<=*t*2<=<<=0,<=...,<=*t**k*<=<<=0 and *t**k*<=+<=1<=><=0,<=*t**k*<=+<=2<=><=0,<=...,<=*t**n*<=><=0. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.
You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single spaces. | Print a single integer — the answer to the given task. | [
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] | [
"1\n",
"2\n"
] | Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number. | [
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "7\n-1 -2 -3 3 -1 3 4",
"output": "1"
},
{
"input": "2\n3 -5",
"output": "2"
},
{
"input": "50\n4 -8 0 -1 -3 -9 0 -2 0 1 -1 0 7 -10 9 7 0 -10 5 0 1 -6 9 -9 3 -3 3 7 4 -8 -8 3 3 -1 0 2 -6 10 7 -1 -6 -3 -4 2 3 0 -4 0 7 -9",
"output": "26"
},
{
"input": "90\n52 -89 17 64 11 -61 92 51 42 -92 -14 -100 21 -88 73 -11 84 72 -80 -78 5 -70 -70 80 91 -89 87 -74 63 -79 -94 52 82 79 81 40 69 -15 33 -52 18 30 -39 99 84 -98 44 69 -75 0 60 -89 51 -92 83 73 16 -43 17 0 51 9 -53 86 86 -50 0 -80 3 0 86 0 -76 -45 0 -32 45 81 47 15 -62 21 4 -82 77 -67 -64 -12 0 -50",
"output": "42"
},
{
"input": "10\n-19 -29 -21 -6 29 89 -74 -22 18 -13",
"output": "3"
},
{
"input": "100\n-782 365 -283 769 -58 224 1000 983 7 595 -963 -267 -934 -187 -609 693 -316 431 859 -753 865 -421 861 -728 -793 621 -311 414 -101 -196 120 84 633 -362 989 94 206 19 -949 -629 489 376 -391 165 50 22 -209 735 565 61 -321 -256 890 34 343 -326 984 -268 -609 385 717 81 372 -391 271 -89 297 -510 797 -425 -276 573 510 560 165 -482 511 541 -491 60 168 -805 235 -657 -679 -617 -212 816 -98 901 380 103 608 -257 -643 333 8 355 743 -801",
"output": "40"
}
] | 342 | 15,872,000 | 3 | 3,565 |
|
400 | Inna and Huge Candy Matrix | [
"implementation",
"math"
] | null | null | Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*).
The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.
Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! | The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105).
Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell. | For each of the *p* candies, print on a single line its space-separated new coordinates. | [
"3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n"
] | [
"1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n"
] | Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix: | [
{
"input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3",
"output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1"
},
{
"input": "5 5 0 0 0 1\n1 4",
"output": "1 4"
},
{
"input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n13 75\n9 9\n3 63\n8 49\n5 1\n1 67\n13 31\n9 35\n3 53\n13 73\n5 71\n1 32\n5 49\n1 41\n14 69",
"output": "4 21\n14 65\n10 25\n1 63\n4 30\n14 19\n10 7\n6 51\n13 49\n2 75\n6 9\n12 63\n7 49\n10 1\n14 67\n2 31\n6 35\n12 53\n2 73\n10 71\n14 32\n10 49\n14 41\n1 69"
},
{
"input": "63 67 18046757 61758841 85367218 68\n22 30\n25 40\n56 58\n29 11\n34 63\n28 66\n51 5\n39 64\n1 23\n24 61\n19 47\n10 31\n55 28\n52 26\n38 7\n28 31\n13 27\n37 42\n10 52\n19 33\n7 36\n13 1\n46 40\n21 41\n1 1\n6 35\n10 4\n46 9\n21 57\n1 49\n34 14\n14 35\n43 4\n1 41\n25 22\n18 25\n27 23\n43 17\n34 23\n29 4\n50 40\n43 67\n55 37\n4 60\n35 32\n22 58\n22 12\n9 2\n42 44\n20 57\n5 37\n22 48\n26 8\n33 1\n61 28\n55 18\n21 1\n1 2\n36 29\n45 65\n1 41\n22 46\n25 67\n25 41\n36 42\n8 66\n52 60\n28 50",
"output": "38 42\n28 39\n10 8\n57 35\n5 30\n2 36\n63 13\n4 25\n45 63\n7 40\n21 45\n37 54\n40 9\n42 12\n61 26\n37 36\n41 51\n26 27\n16 54\n35 45\n32 57\n67 51\n28 18\n27 43\n67 63\n33 58\n64 54\n59 18\n11 43\n19 63\n54 30\n33 50\n64 21\n27 63\n46 39\n43 46\n45 37\n51 21\n45 30\n64 35\n28 14\n1 21\n31 9\n8 60\n36 29\n10 42\n56 42\n66 55\n24 22\n11 44\n31 59\n20 42\n60 38\n67 31\n40 3\n50 9\n67 43\n66 63\n39 28\n3 19\n27 63\n22 42\n1 39\n27 39\n26 28\n2 56\n8 12\n18 36"
},
{
"input": "75 18 163006189 147424057 443319537 71\n56 7\n1 5\n17 4\n67 13\n45 1\n55 9\n46 14\n23 10\n10 1\n1 1\n14 9\n18 16\n25 9\n22 4\n73 13\n51 7\n43 13\n59 1\n62 15\n37 6\n43 11\n66 17\n61 13\n45 1\n16 7\n46 7\n25 1\n52 13\n74 7\n16 17\n34 11\n37 16\n24 5\n10 11\n20 5\n74 1\n57 7\n72 10\n21 11\n66 13\n46 1\n46 13\n65 1\n68 11\n14 13\n72 11\n58 1\n16 15\n49 1\n53 10\n30 1\n75 1\n45 4\n42 13\n52 10\n25 1\n31 1\n26 1\n21 7\n27 4\n55 10\n61 1\n37 3\n13 18\n24 1\n11 3\n14 17\n34 5\n49 4\n56 13\n19 11",
"output": "20 7\n75 5\n59 4\n9 13\n31 1\n21 9\n30 14\n53 10\n66 1\n75 1\n62 9\n58 16\n51 9\n54 4\n3 13\n25 7\n33 13\n17 1\n14 15\n39 6\n33 11\n10 17\n15 13\n31 1\n60 7\n30 7\n51 1\n24 13\n2 7\n60 17\n42 11\n39 16\n52 5\n66 11\n56 5\n2 1\n19 7\n4 10\n55 11\n10 13\n30 1\n30 13\n11 1\n8 11\n62 13\n4 11\n18 1\n60 15\n27 1\n23 10\n46 1\n1 1\n31 4\n34 13\n24 10\n51 1\n45 1\n50 1\n55 7\n49 4\n21 10\n15 1\n39 3\n63 18\n52 1\n65 3\n62 17\n42 5\n27 4\n20 13\n57 11"
},
{
"input": "99 65 100328801 11658361 60379320 41\n46 61\n92 23\n46 16\n60 56\n50 42\n24 19\n43 54\n40 1\n41 16\n19 34\n57 59\n84 20\n33 3\n82 59\n74 53\n26 65\n83 30\n76 14\n73 55\n58 33\n97 62\n10 18\n70 1\n56 27\n64 25\n25 57\n28 21\n96 2\n10 41\n99 59\n25 15\n1 3\n46 27\n38 65\n34 25\n64 55\n37 53\n78 43\n70 64\n64 49\n4 12",
"output": "61 46\n23 92\n16 46\n56 60\n42 50\n19 24\n54 43\n1 40\n16 41\n34 19\n59 57\n20 84\n3 33\n59 82\n53 74\n65 26\n30 83\n14 76\n55 73\n33 58\n62 97\n18 10\n1 70\n27 56\n25 64\n57 25\n21 28\n2 96\n41 10\n59 99\n15 25\n3 1\n27 46\n65 38\n25 34\n55 64\n53 37\n43 78\n64 70\n49 64\n12 4"
},
{
"input": "60 1 884622497 447787585 45746569 5\n41 1\n3 1\n57 1\n1 1\n28 1",
"output": "20 1\n58 1\n4 1\n60 1\n33 1"
},
{
"input": "29 9 101222353 522378781 221562741 21\n8 1\n12 8\n21 7\n29 2\n12 3\n1 4\n18 9\n28 6\n2 3\n10 8\n16 4\n3 9\n14 4\n15 3\n16 6\n28 7\n18 1\n12 1\n23 1\n11 1\n18 4",
"output": "22 1\n18 8\n9 7\n1 2\n18 3\n29 4\n12 9\n2 6\n28 3\n20 8\n14 4\n27 9\n16 4\n15 3\n14 6\n2 7\n12 1\n18 1\n7 1\n19 1\n12 4"
},
{
"input": "14 33 331499150 82809609 266661996 75\n9 10\n1 1\n8 8\n13 26\n3 1\n5 1\n8 13\n3 19\n1 13\n1 6\n13 1\n12 19\n5 25\n3 10\n6 19\n6 23\n7 1\n11 7\n11 16\n7 32\n8 30\n1 2\n11 2\n13 25\n8 7\n9 33\n9 1\n1 7\n1 30\n14 32\n9 10\n11 7\n12 5\n11 31\n7 10\n7 21\n9 28\n3 23\n11 31\n9 12\n5 14\n9 7\n10 11\n5 14\n5 14\n4 16\n3 32\n3 16\n13 28\n5 10\n2 8\n4 11\n8 4\n11 15\n1 12\n5 17\n14 10\n13 12\n7 7\n2 32\n3 25\n4 5\n4 31\n10 23\n10 28\n5 8\n5 31\n4 25\n3 25\n13 7\n1 26\n6 4\n9 33\n5 4\n1 14",
"output": "6 10\n14 1\n7 8\n2 26\n12 1\n10 1\n7 13\n12 19\n14 13\n14 6\n2 1\n3 19\n10 25\n12 10\n9 19\n9 23\n8 1\n4 7\n4 16\n8 32\n7 30\n14 2\n4 2\n2 25\n7 7\n6 33\n6 1\n14 7\n14 30\n1 32\n6 10\n4 7\n3 5\n4 31\n8 10\n8 21\n6 28\n12 23\n4 31\n6 12\n10 14\n6 7\n5 11\n10 14\n10 14\n11 16\n12 32\n12 16\n2 28\n10 10\n13 8\n11 11\n7 4\n4 15\n14 12\n10 17\n1 10\n2 12\n8 7\n13 32\n12 25\n11 5\n11 31\n5 23\n5 28\n10 8\n10 31\n11 25\n12 25\n2 7\n14 26\n9 4\n6 33\n10 4\n14 14"
},
{
"input": "26 89 146819986 242756320 184308201 43\n20 71\n12 22\n3 73\n9 48\n1 32\n5 20\n1 18\n19 57\n23 77\n1 4\n17 86\n1 13\n16 64\n1 56\n7 63\n18 38\n17 82\n21 43\n5 16\n9 39\n7 23\n5 53\n19 8\n25 10\n11 69\n11 7\n16 47\n25 48\n20 87\n14 16\n1 16\n14 43\n22 43\n11 89\n7 3\n1 57\n5 43\n21 1\n1 21\n3 85\n5 7\n19 16\n7 15",
"output": "71 7\n22 15\n73 24\n48 18\n32 26\n20 22\n18 26\n57 8\n77 4\n4 26\n86 10\n13 26\n64 11\n56 26\n63 20\n38 9\n82 10\n43 6\n16 22\n39 18\n23 20\n53 22\n8 8\n10 2\n69 16\n7 16\n47 11\n48 2\n87 7\n16 13\n16 26\n43 13\n43 5\n89 16\n3 20\n57 26\n43 22\n1 6\n21 26\n85 24\n7 22\n16 8\n15 20"
},
{
"input": "57 62 402127657 5834146 166754152 26\n55 15\n3 10\n10 21\n25 45\n28 50\n54 39\n1 57\n5 11\n13 54\n52 17\n52 9\n28 3\n37 25\n29 15\n55 33\n23 25\n28 1\n46 7\n39 25\n20 43\n33 49\n52 47\n22 11\n37 37\n52 48\n25 53",
"output": "15 3\n10 55\n21 48\n45 33\n50 30\n39 4\n57 57\n11 53\n54 45\n17 6\n9 6\n3 30\n25 21\n15 29\n33 3\n25 35\n1 30\n7 12\n25 19\n43 38\n49 25\n47 6\n11 36\n37 21\n48 6\n53 33"
},
{
"input": "83 53 263444877 330109611 453128994 25\n47 7\n40 13\n47 53\n23 37\n57 23\n4 38\n39 25\n42 41\n61 23\n74 6\n48 5\n56 53\n48 37\n13 37\n34 32\n49 4\n43 32\n14 1\n75 15\n59 18\n25 14\n46 23\n47 48\n72 3\n55 17",
"output": "47 37\n41 44\n1 37\n17 61\n31 27\n16 80\n29 45\n13 42\n31 23\n48 10\n49 36\n1 28\n17 36\n17 71\n22 50\n50 35\n22 41\n53 70\n39 9\n36 25\n40 59\n31 38\n6 37\n51 12\n37 29"
},
{
"input": "65 66 68528825 50348481 104442753 7\n1 49\n54 47\n16 37\n1 34\n51 29\n36 17\n11 16",
"output": "65 49\n12 47\n50 37\n65 34\n15 29\n30 17\n55 16"
},
{
"input": "63 5 311153546 666957619 681867949 3\n14 3\n22 1\n14 2",
"output": "3 50\n5 42\n4 50"
},
{
"input": "1 9 549924215 115901887 855235569 1\n1 6",
"output": "1 4"
},
{
"input": "85 26 48272945 423830401 423026164 3\n35 1\n50 17\n55 2",
"output": "1 35\n17 50\n2 55"
},
{
"input": "67 61 443905131 226973811 158369983 1\n52 51",
"output": "16 51"
},
{
"input": "1 13 348638338 31146449 81215464 3\n1 4\n1 10\n1 6",
"output": "1 4\n1 10\n1 6"
},
{
"input": "68 45 637151929 93583345 392834373 10\n52 11\n28 1\n67 21\n33 29\n43 28\n30 17\n39 30\n52 37\n11 7\n11 26",
"output": "17 11\n41 1\n2 21\n36 29\n26 28\n39 17\n30 30\n17 37\n58 7\n58 26"
},
{
"input": "25 45 20761261 857816695 7926985 1\n1 26",
"output": "25 26"
},
{
"input": "1 1 0 0 0 2\n1 1\n1 1",
"output": "1 1\n1 1"
},
{
"input": "2 2 1 0 0 4\n1 1\n1 2\n2 2\n2 1",
"output": "1 2\n2 2\n2 1\n1 1"
},
{
"input": "2 2 0 1 0 4\n1 1\n1 2\n2 2\n2 1",
"output": "1 2\n1 1\n2 1\n2 2"
},
{
"input": "2 2 0 0 1 4\n1 1\n1 2\n2 2\n2 1",
"output": "2 1\n1 1\n1 2\n2 2"
},
{
"input": "2 1 1 0 0 2\n1 1\n2 1",
"output": "1 2\n1 1"
},
{
"input": "2 1 0 1 0 2\n1 1\n2 1",
"output": "1 1\n2 1"
},
{
"input": "2 1 0 0 1 2\n1 1\n2 1",
"output": "1 1\n1 2"
},
{
"input": "1 1 0 1 0 2\n1 1\n1 1",
"output": "1 1\n1 1"
}
] | 46 | 0 | 0 | 3,567 |
|
0 | none | [
"none"
] | null | null | For an array $b$ of length $m$ we define the function $f$ as
where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$
You are given an array $a$ and a few queries. Each query is represented as two integers $l$ and $r$. The answer is the maximum value of $f$ on all continuous subsegments of the array $a_l, a_{l+1}, \ldots, a_r$. | The first line contains a single integer $n$ ($1 \le n \le 5000$) — the length of $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$) — the elements of the array.
The third line contains a single integer $q$ ($1 \le q \le 100\,000$) — the number of queries.
Each of the next $q$ lines contains a query represented as two integers $l$, $r$ ($1 \le l \le r \le n$). | Print $q$ lines — the answers for the queries. | [
"3\n8 4 1\n2\n2 3\n1 2\n",
"6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n"
] | [
"5\n12\n",
"60\n30\n12\n3\n"
] | In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are $[3,6]$, for second query — $[2,5]$, for third — $[3,4]$, for fourth — $[1,2]$. | [
{
"input": "3\n8 4 1\n2\n2 3\n1 2",
"output": "5\n12"
},
{
"input": "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2",
"output": "60\n30\n12\n3"
}
] | 93 | 0 | 0 | 3,574 |
|
817 | Imbalanced Array | [
"data structures",
"divide and conquer",
"dsu",
"sortings"
] | null | null | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of array [1,<=4,<=1] is 9, because there are 6 different subsegments of this array:
- [1] (from index 1 to index 1), imbalance value is 0; - [1,<=4] (from index 1 to index 2), imbalance value is 3; - [1,<=4,<=1] (from index 1 to index 3), imbalance value is 3; - [4] (from index 2 to index 2), imbalance value is 0; - [4,<=1] (from index 2 to index 3), imbalance value is 3; - [1] (from index 3 to index 3), imbalance value is 0;
You have to determine the imbalance value of the array *a*. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one integer — the imbalance value of *a*. | [
"3\n1 4 1\n"
] | [
"9\n"
] | none | [
{
"input": "3\n1 4 1",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10\n1 4 4 3 5 2 4 2 4 5",
"output": "123"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "245"
},
{
"input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5 2 3 5 4 5 4 4 3 5 2",
"output": "1480"
},
{
"input": "30\n2 2 9 1 10 8 3 3 1 4 6 10 2 2 1 4 1 1 1 1 1 2 4 7 6 7 5 10 8 9",
"output": "3147"
},
{
"input": "30\n6 19 12 6 25 24 12 2 24 14 10 10 24 19 11 29 10 22 7 1 9 1 2 27 7 24 20 25 20 28",
"output": "10203"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "426927"
}
] | 2,000 | 12,083,200 | 0 | 3,599 |
|
0 | none | [
"none"
] | null | null | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework. | The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105). | Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes). | [
"aa\n2\n",
"abc\n5\n",
"abab\n7\n"
] | [
"a\n",
"bc\n",
"b\n"
] | In the second sample before string "bc" follow strings "a", "ab", "abc", "b". | [
{
"input": "aa\n2",
"output": "a"
},
{
"input": "abc\n5",
"output": "bc"
},
{
"input": "abab\n7",
"output": "b"
},
{
"input": "codeforces\n1",
"output": "c"
},
{
"input": "cccc\n8",
"output": "ccc"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n27",
"output": "b"
},
{
"input": "cba\n6",
"output": "cba"
},
{
"input": "z\n100000",
"output": "No such line."
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n17416",
"output": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
},
{
"input": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n32912",
"output": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n84480",
"output": "No such line."
},
{
"input": "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n83252",
"output": "No such line."
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n18883",
"output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
},
{
"input": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n14594",
"output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n87315",
"output": "No such line."
},
{
"input": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n27016",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n9184",
"output": "ssssssssssssssssssssssssssss"
},
{
"input": "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n99590",
"output": "No such line."
},
{
"input": "aaaaaaaaaa\n90",
"output": "No such line."
}
] | 2,000 | 15,052,800 | 0 | 3,609 |
|
290 | Greedy Petya | [
"*special",
"dfs and similar",
"graphs",
"greedy"
] | null | null | Petya is an unexperienced programming contestant. Recently he has come across the following problem:
You are given a non-directed graph which consists of *n* nodes and *m* edges. Your task is to determine whether the graph contains a Hamiltonian path.
Petya wrote a quick bug-free code which he believes solves this problem. After that Petya decided to give this problem for April Fools Day contest. Unfortunately, Petya might have made a mistake, and it's quite possible that his algorithm is wrong. But this isn't a good excuse to leave the contest without submitting this problem, is it? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=20; 0<=≤<=*m*<=≤<=400). Next *m* lines contain pairs of integers *v**i*,<=*u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*). | Follow the format of Petya's code output. | [
"2 3\n1 2\n2 1\n1 1\n",
"3 0\n",
"10 20\n3 10\n4 6\n4 9\n7 5\n8 8\n3 10\n9 7\n5 2\n9 2\n10 6\n10 4\n1 1\n7 2\n8 4\n7 2\n1 8\n5 4\n10 2\n8 5\n5 2\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | none | [] | 62 | 0 | 0 | 3,619 |
|
1,003 | Binary String Constructing | [
"constructive algorithms"
] | null | null | You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, for the string "01010" there are four indices $i$ such that $1 \le i < n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$).
Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1. | The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x < a + b)$. | Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. | [
"2 2 1\n",
"3 3 3\n",
"5 3 6\n"
] | [
"1100\n",
"101100\n",
"01010100\n"
] | All possible answers for the first example:
- 1100; - 0011.
All possible answers for the second example:
- 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011. | [
{
"input": "2 2 1",
"output": "1100"
},
{
"input": "3 3 3",
"output": "101100"
},
{
"input": "5 3 6",
"output": "01010100"
},
{
"input": "100 1 2",
"output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 1 1",
"output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
},
{
"input": "1 100 1",
"output": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 100 2",
"output": "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "7 8 7",
"output": "101010111110000"
},
{
"input": "100 100 199",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010"
},
{
"input": "50 47 18",
"output": "0101010101010101011111111111111111111111111111111111111100000000000000000000000000000000000000000"
},
{
"input": "2 3 3",
"output": "10110"
},
{
"input": "100 100 100",
"output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111"
},
{
"input": "2 2 2",
"output": "1001"
},
{
"input": "3 4 6",
"output": "1010101"
},
{
"input": "1 1 1",
"output": "10"
},
{
"input": "5 6 2",
"output": "10000011111"
},
{
"input": "5 4 2",
"output": "011110000"
},
{
"input": "2 3 4",
"output": "10101"
},
{
"input": "3 3 2",
"output": "100011"
},
{
"input": "100 99 100",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000"
},
{
"input": "3 2 1",
"output": "00011"
},
{
"input": "12 74 22",
"output": "10101010101010101010100111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "6 84 12",
"output": "101010101010111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "3 2 4",
"output": "01010"
},
{
"input": "66 11 22",
"output": "01010101010101010101010000000000000000000000000000000000000000000000000000000"
},
{
"input": "83 83 83",
"output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010111111111111111111111111111111111111111111000000000000000000000000000000000000000000"
},
{
"input": "9 89 18",
"output": "10101010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "2 1 2",
"output": "010"
},
{
"input": "52 12 17",
"output": "0101010101010101000000000000000000000000000000000000000000001111"
},
{
"input": "55 56 110",
"output": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"
},
{
"input": "67 81 40",
"output": "1010101010101010101010101010101010101010000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "15 26 24",
"output": "10101010101010101010101000011111111111111"
},
{
"input": "7 99 14",
"output": "1010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "99 41 17",
"output": "01010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111"
},
{
"input": "91 87 11",
"output": "0101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "73 61 122",
"output": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101000000000000"
},
{
"input": "10 40 1",
"output": "11111111111111111111111111111111111111110000000000"
},
{
"input": "10 6 10",
"output": "0101010101100000"
},
{
"input": "78 67 117",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000111111111"
},
{
"input": "3 5 6",
"output": "10101011"
},
{
"input": "30 34 44",
"output": "1010101010101010101010101010101010101010101000000000111111111111"
},
{
"input": "2 15 4",
"output": "10101111111111111"
},
{
"input": "4 9 6",
"output": "1010100111111"
}
] | 327 | 30,208,000 | 0 | 3,628 |
|
300 | Coach | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.
Help the coach and divide the teams the way he wants. | The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team.
It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once. | If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team.
If there are multiple answers, you are allowed to print any of them. | [
"3 0\n",
"6 4\n1 2\n2 3\n3 4\n5 6\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"3 2 1 \n",
"-1\n",
"3 2 1 \n"
] | none | [
{
"input": "3 0",
"output": "3 2 1 "
},
{
"input": "6 4\n1 2\n2 3\n3 4\n5 6",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "3 2 1 "
},
{
"input": "6 3\n1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n13 15",
"output": "6 4 1 \n11 7 2 \n12 5 3 \n14 9 8 \n15 13 10 "
},
{
"input": "3 1\n1 3",
"output": "3 2 1 "
},
{
"input": "15 13\n1 9\n1 11\n2 7\n2 12\n3 8\n3 15\n4 10\n5 6\n5 14\n6 14\n7 12\n8 15\n9 11",
"output": "11 9 1 \n12 7 2 \n14 6 5 \n15 8 3 \n13 10 4 "
},
{
"input": "36 27\n1 34\n2 18\n2 20\n3 9\n3 21\n4 5\n4 25\n5 25\n6 13\n6 22\n8 23\n8 31\n9 21\n10 14\n11 17\n11 19\n13 22\n15 24\n15 26\n17 19\n18 20\n23 31\n24 26\n28 29\n28 33\n29 33\n32 36",
"output": "19 17 11 \n20 18 2 \n21 9 3 \n22 13 6 \n25 5 4 \n26 24 15 \n31 23 8 \n33 29 28 \n14 10 7 \n34 12 1 \n36 32 16 \n35 30 27 "
},
{
"input": "18 12\n1 10\n2 4\n2 8\n3 15\n3 18\n4 8\n5 6\n9 13\n12 14\n12 16\n14 16\n15 18",
"output": "8 4 2 \n16 14 12 \n18 15 3 \n7 6 5 \n11 10 1 \n17 13 9 "
},
{
"input": "39 27\n1 2\n1 25\n2 25\n4 16\n5 22\n5 28\n6 7\n6 26\n7 26\n8 24\n10 31\n10 38\n11 17\n11 21\n12 35\n12 37\n13 34\n17 21\n18 23\n19 39\n22 28\n27 29\n27 36\n29 36\n31 38\n32 33\n35 37",
"output": "21 17 11 \n25 2 1 \n26 7 6 \n28 22 5 \n36 29 27 \n37 35 12 \n38 31 10 \n16 4 3 \n23 18 9 \n24 14 8 \n33 32 15 \n34 20 13 \n39 30 19 "
},
{
"input": "12 7\n1 2\n4 5\n6 12\n7 8\n9 10\n9 11\n10 11",
"output": "-1"
},
{
"input": "33 22\n3 9\n3 28\n4 12\n5 11\n5 31\n6 18\n8 15\n8 29\n9 28\n10 22\n11 31\n13 14\n15 29\n16 23\n16 27\n17 25\n17 32\n19 21\n20 30\n23 27\n24 33\n25 32",
"output": "-1"
},
{
"input": "18 8\n1 14\n2 16\n4 7\n5 11\n8 9\n8 12\n9 12\n10 18",
"output": "12 9 8 \n7 4 3 \n11 6 5 \n14 13 1 \n16 15 2 \n18 17 10 "
},
{
"input": "27 21\n1 3\n2 9\n2 11\n5 16\n5 25\n7 26\n8 14\n8 22\n9 11\n10 17\n10 27\n12 21\n13 20\n13 23\n14 22\n15 18\n15 19\n16 25\n17 27\n18 19\n20 23",
"output": "11 9 2 \n19 18 15 \n22 14 8 \n23 20 13 \n25 16 5 \n27 17 10 \n4 3 1 \n21 12 6 \n26 24 7 "
},
{
"input": "24 21\n1 14\n2 6\n3 4\n3 19\n4 19\n5 7\n5 21\n7 21\n8 18\n8 23\n9 15\n9 16\n10 12\n10 17\n11 22\n12 17\n13 20\n13 24\n15 16\n18 23\n20 24",
"output": "-1"
},
{
"input": "45 31\n1 5\n2 45\n3 29\n3 30\n4 16\n4 32\n6 40\n7 13\n7 25\n8 42\n10 31\n11 20\n11 26\n12 27\n12 34\n13 25\n14 24\n14 43\n15 36\n15 37\n16 32\n18 19\n18 33\n19 33\n20 26\n23 41\n24 43\n27 34\n28 39\n29 30\n36 37",
"output": "25 13 7 \n26 20 11 \n30 29 3 \n32 16 4 \n33 19 18 \n34 27 12 \n37 36 15 \n43 24 14 \n9 5 1 \n31 17 10 \n39 28 21 \n40 22 6 \n41 35 23 \n42 38 8 \n45 44 2 "
},
{
"input": "18 9\n1 16\n2 17\n4 6\n5 18\n7 8\n7 15\n8 15\n9 11\n10 13",
"output": "-1"
},
{
"input": "6 6\n1 6\n1 3\n3 6\n2 4\n4 5\n2 5",
"output": "5 4 2 \n6 3 1 "
},
{
"input": "48 48\n7 39\n39 45\n7 45\n25 26\n26 31\n25 31\n4 11\n11 19\n4 19\n8 16\n16 37\n8 37\n14 22\n22 33\n14 33\n6 12\n12 46\n6 46\n29 44\n44 48\n29 48\n15 27\n27 41\n15 41\n3 24\n24 34\n3 34\n13 20\n20 47\n13 47\n5 9\n9 36\n5 36\n21 40\n40 43\n21 43\n2 35\n35 38\n2 38\n23 28\n28 42\n23 42\n1 10\n10 32\n1 32\n17 18\n18 30\n17 30",
"output": "19 11 4 \n30 18 17 \n31 26 25 \n32 10 1 \n33 22 14 \n34 24 3 \n36 9 5 \n37 16 8 \n38 35 2 \n41 27 15 \n42 28 23 \n43 40 21 \n45 39 7 \n46 12 6 \n47 20 13 \n48 44 29 "
},
{
"input": "12 9\n1 2\n2 4\n1 3\n5 6\n6 8\n5 7\n9 10\n10 12\n9 11",
"output": "-1"
},
{
"input": "9 7\n1 2\n3 4\n5 6\n7 8\n2 3\n2 5\n2 7",
"output": "-1"
},
{
"input": "9 3\n4 5\n6 7\n8 9",
"output": "5 4 1 \n7 6 2 \n9 8 3 "
},
{
"input": "6 2\n3 4\n5 6",
"output": "4 3 1 \n6 5 2 "
},
{
"input": "9 7\n1 2\n2 3\n1 3\n4 5\n4 6\n4 7\n4 8",
"output": "-1"
},
{
"input": "6 1\n1 2",
"output": "3 2 1 \n6 5 4 "
},
{
"input": "48 1\n1 2",
"output": "3 2 1 \n6 5 4 \n9 8 7 \n12 11 10 \n15 14 13 \n18 17 16 \n21 20 19 \n24 23 22 \n27 26 25 \n30 29 28 \n33 32 31 \n36 35 34 \n39 38 37 \n42 41 40 \n45 44 43 \n48 47 46 "
}
] | 62 | 0 | -1 | 3,630 |
|
613 | Peter and Snow Blower | [
"binary search",
"geometry",
"ternary search"
] | null | null | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
Peter decided to tie his car to point *P* and now he is wondering what is the area of the region that will be cleared from snow. Help him. | The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
All the numbers in the input are integers that do not exceed 1<=000<=000 in their absolute value. | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"3 0 0\n0 1\n-1 2\n1 2\n",
"4 1 -1\n0 0\n1 2\n2 0\n1 1\n"
] | [
"12.566370614359172464\n",
"21.991148575128551812\n"
] | In the first sample snow will be removed from that area: | [
{
"input": "3 0 0\n0 1\n-1 2\n1 2",
"output": "12.566370614359172464"
},
{
"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1",
"output": "21.991148575128551812"
},
{
"input": "3 0 0\n-1 1\n0 3\n1 1",
"output": "25.132741228718344928"
},
{
"input": "3 -4 2\n-3 2\n5 -5\n5 3",
"output": "405.26545231308331191"
},
{
"input": "3 -84 8\n-83 8\n21 -62\n3 53",
"output": "50026.721415763865583"
},
{
"input": "6 -94 -51\n-93 -51\n48 -25\n61 27\n73 76\n-10 87\n-48 38",
"output": "138283.48383306192359"
},
{
"input": "5 -94 52\n-93 52\n-78 -56\n-54 -81\n56 -87\n97 85",
"output": "131381.40477312514811"
},
{
"input": "10 -100 90\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93",
"output": "198410.42563011697403"
},
{
"input": "11 -97 -15\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49",
"output": "133558.52848206287476"
},
{
"input": "10 -500 420\n-499 420\n-489 -173\n-455 -480\n160 -464\n374 -437\n452 -352\n481 -281\n465 75\n326 392\n-398 468",
"output": "4719573.802783449531"
},
{
"input": "10 -498 -161\n-497 -161\n-427 -458\n-325 -475\n349 -500\n441 -220\n473 28\n475 62\n468 498\n-444 492\n-465 264",
"output": "4295926.8918542123392"
},
{
"input": "5 -1 -1\n0 0\n8 5\n10 7\n7 5\n2 5",
"output": "574.91145560693214023"
},
{
"input": "5 -1 -1\n0 0\n20 3\n26 17\n23 21\n98 96",
"output": "60343.711690152746165"
},
{
"input": "10 -1 -1\n0 0\n94 7\n100 52\n87 48\n37 26\n74 61\n59 57\n87 90\n52 90\n26 73",
"output": "50337.739088469255101"
},
{
"input": "10 -1 -1\n0 0\n78 22\n53 24\n78 50\n46 39\n45 56\n21 46\n2 7\n24 97\n5 59",
"output": "32129.068068262814194"
},
{
"input": "49 -1 -1\n0 0\n95 2\n47 1\n42 1\n93 7\n56 6\n47 7\n63 13\n98 24\n94 27\n90 28\n86 28\n17 6\n64 24\n42 19\n66 35\n63 35\n98 60\n75 48\n28 18\n71 46\n69 46\n99 68\n64 47\n56 43\n72 58\n35 29\n82 81\n68 69\n79 84\n72 77\n79 86\n54 59\n35 39\n20 23\n73 86\n80 97\n79 100\n69 99\n29 45\n26 63\n23 56\n12 33\n13 39\n25 85\n27 96\n6 23\n4 47\n1 60",
"output": "52147.296456936975932"
},
{
"input": "49 -1 -1\n0 0\n69 2\n74 7\n62 10\n64 15\n93 22\n78 22\n56 17\n86 29\n24 9\n91 43\n8 4\n90 50\n99 57\n39 23\n81 50\n91 58\n67 46\n95 66\n52 39\n91 69\n69 54\n93 84\n93 98\n70 80\n85 98\n30 39\n55 79\n41 59\n50 72\n57 88\n58 92\n58 94\n37 63\n43 87\n30 63\n19 40\n38 81\n40 86\n38 100\n2 6\n30 100\n23 89\n16 62\n11 49\n12 64\n9 52\n5 62\n1 88",
"output": "58543.579099645794717"
},
{
"input": "27 -999899 136015\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816",
"output": "16600304470662.964855"
},
{
"input": "19 -995486 -247212\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864",
"output": "16257949833603.158278"
},
{
"input": "15 -994057 554462\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633",
"output": "19694832748836.689348"
},
{
"input": "23 -999840 738880\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292",
"output": "21831930831113.094931"
},
{
"input": "20 -999719 -377746\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031",
"output": "18331542740428.216614"
},
{
"input": "26 -999922 -339832\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509",
"output": "18127026556380.411608"
},
{
"input": "22 -999930 -362070\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326",
"output": "18335297542813.80731"
},
{
"input": "29 -999961 689169\n-999960 689169\n-999927 -938525\n-999735 -989464\n-993714 -997911\n-870186 -999686\n-796253 -999950\n-139940 -999968\n969552 -999972\n985446 -999398\n992690 -997295\n999706 -973137\n999898 -848630\n999997 -192297\n999969 773408\n999495 960350\n999143 981671\n998324 993987\n997640 998103\n986157 998977\n966840 999418\n670113 999809\n477888 999856\n129160 999900\n-373564 999947\n-797543 999976\n-860769 999903\n-995496 999355\n-998771 984570\n-999768 927157",
"output": "21409384775316.574772"
},
{
"input": "3 -3 3\n-3 2\n5 -5\n5 3",
"output": "399.0305992005743379"
},
{
"input": "3 -9 7\n-9 6\n3 -6\n4 2",
"output": "980.17690792001545219"
},
{
"input": "5 -9 8\n-9 7\n-6 -1\n-3 -6\n1 -3\n10 8",
"output": "1130.9820337250702449"
},
{
"input": "6 -6 -1\n-6 -2\n0 -7\n8 -9\n9 -1\n5 10\n-5 0",
"output": "816.18577140262825159"
},
{
"input": "10 -99 91\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93",
"output": "198309.89857373595223"
},
{
"input": "11 -96 -14\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49",
"output": "131821.20868619133483"
},
{
"input": "13 -98 25\n-98 24\n-96 10\n-80 -71\n-71 -78\n-31 -99\n82 -98\n92 -39\n94 -2\n94 40\n90 80\n50 96\n-41 97\n-86 80",
"output": "149316.61930888936332"
},
{
"input": "17 -99 -53\n-99 -54\n-97 -71\n-67 -99\n-61 -99\n56 -98\n82 -85\n95 -47\n90 -2\n82 30\n63 87\n54 95\n-12 99\n-38 99\n-87 89\n-90 87\n-95 67\n-96 49",
"output": "144023.17094830233827"
},
{
"input": "19 -995485 -247211\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864",
"output": "16257930301545.657524"
},
{
"input": "15 -994056 554463\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633",
"output": "19694830011124.045712"
},
{
"input": "23 -999839 738881\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292",
"output": "21831929255745.74826"
},
{
"input": "20 -999718 -377745\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031",
"output": "18331521646100.671528"
},
{
"input": "26 -999921 -339831\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509",
"output": "18127005627407.454252"
},
{
"input": "22 -999929 -362069\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326",
"output": "18335276455623.960732"
},
{
"input": "27 -999898 136016\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816",
"output": "16600299044211.965457"
},
{
"input": "13 -1000000 -1000000\n-1000000 0\n0 -1000000\n999417 840\n999781 33421\n999994 131490\n999993 998865\n962080 999911\n629402 999973\n378696 999988\n53978 999788\n25311 999558\n6082 999282\n1565 998489",
"output": "23547598153913.984406"
},
{
"input": "16 -1000000 -1000000\n-1000000 0\n0 -1000000\n999744 572\n999931 96510\n1000000 254372\n999939 748173\n999894 953785\n999683 986098\n999051 999815\n980586 999969\n637250 999988\n118331 999983\n27254 999966\n9197 999405\n4810 997733\n1661 995339",
"output": "23547697574489.259052"
},
{
"input": "4 0 0\n1 -1\n1 3\n3 3\n3 -1",
"output": "53.407075111026482965"
},
{
"input": "3 0 0\n-10 1\n0 2\n1 1",
"output": "314.1592653589793116"
},
{
"input": "3 0 0\n-1 1\n4 1\n0 2",
"output": "50.265482457436689849"
}
] | 46 | 0 | 0 | 3,642 |
|
440 | Balancer | [
"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 | [
{
"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"
}
] | 500 | 921,600 | 0 | 3,646 |
|
452 | Magic Trick | [
"combinatorics",
"math",
"probabilities"
] | null | null | Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards.
The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful.
You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case. | First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks. | On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6. | [
"2 2\n",
"4 4\n",
"1 2\n"
] | [
"0.6666666666666666\n",
"0.4000000000000000\n",
"1.0000000000000000\n"
] | In the first sample, with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/64c94d13eeb330b494061e86538db66574ad0f7d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Alex will perform the trick with two cards with the same value from two different decks. In this case the trick is guaranteed to succeed.
With the remaining <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/14b21b617fcd2e25700376368355f7bbf975d8de.png" style="max-width: 100.0%;max-height: 100.0%;"/> probability he took two different cards, and the probability of pulling off the trick is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
The resulting probability is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f54a03c9fa9df64ba08161730756d50b780a5f43.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "2 2",
"output": "0.6666666666666666"
},
{
"input": "4 4",
"output": "0.4000000000000000"
},
{
"input": "1 2",
"output": "1.0000000000000000"
},
{
"input": "2 1",
"output": "0.5000000000000000"
},
{
"input": "10 10",
"output": "0.1818181818181818"
},
{
"input": "1000 1000",
"output": "0.0019980019980020"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "987 123",
"output": "0.0020170953866492"
},
{
"input": "999 999",
"output": "0.0020000000000000"
},
{
"input": "1 999",
"output": "1.0000000000000000"
},
{
"input": "998 1",
"output": "0.0010020040080160"
},
{
"input": "2 987",
"output": "0.7498732894069944"
},
{
"input": "555 543",
"output": "0.0035970508143694"
},
{
"input": "321 123",
"output": "0.0061956542837219"
},
{
"input": "2 3",
"output": "0.7000000000000000"
},
{
"input": "461 1000",
"output": "0.0043315295751250"
},
{
"input": "678 231",
"output": "0.0029413109179425"
}
] | 155 | 1,638,400 | 3 | 3,648 |
|
851 | Arpa and an exam about geometry | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"input": "49152 0 0 0 0 81920",
"output": "No"
},
{
"input": "1 -1 4 4 2 -3",
"output": "No"
},
{
"input": "-2 -2 1 4 -2 0",
"output": "No"
},
{
"input": "5 0 4 -2 0 1",
"output": "No"
},
{
"input": "-4 -3 2 -1 -3 4",
"output": "No"
},
{
"input": "-3 -3 5 2 3 -1",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 1000000000",
"output": "No"
},
{
"input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564",
"output": "No"
},
{
"input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734",
"output": "No"
},
{
"input": "419578772 -125025887 169314071 89851312 961404059 21419450",
"output": "No"
},
{
"input": "-607353321 -620687860 248029390 477864359 728255275 -264646027",
"output": "No"
},
{
"input": "299948862 -648908808 338174789 841279400 -850322448 350263551",
"output": "No"
},
{
"input": "48517753 416240699 7672672 272460100 -917845051 199790781",
"output": "No"
},
{
"input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665",
"output": "No"
},
{
"input": "-685673792 -488079395 909733355 385950193 -705890324 256550506",
"output": "No"
},
{
"input": "-326038504 547872194 49630307 713863100 303770000 -556852524",
"output": "No"
},
{
"input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000",
"output": "Yes"
},
{
"input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000",
"output": "Yes"
},
{
"input": "-999999999 -1000000000 0 0 1000000000 999999999",
"output": "Yes"
},
{
"input": "-1000000000 -999999999 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1 -1000000000 0 1000000000 1 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 1 0 0 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 0 0 0 -1000000000",
"output": "No"
},
{
"input": "0 1 1 2 2 3",
"output": "No"
},
{
"input": "999999999 1000000000 0 0 -1000000000 -999999999",
"output": "Yes"
},
{
"input": "0 0 1 1 2 0",
"output": "Yes"
},
{
"input": "0 0 1 1 2 2",
"output": "No"
},
{
"input": "1 1 2 2 3 3",
"output": "No"
},
{
"input": "0 2 0 3 0 4",
"output": "No"
},
{
"input": "1 1 1 2 1 3",
"output": "No"
},
{
"input": "0 0 3 4 3 9",
"output": "Yes"
},
{
"input": "589824 196608 262144 196608 0 0",
"output": "Yes"
},
{
"input": "0 0 1000000000 1 1000000000 -999999999",
"output": "No"
},
{
"input": "0 0 2 45 0 90",
"output": "Yes"
},
{
"input": "0 0 0 2 0 1",
"output": "No"
},
{
"input": "0 2 4 5 4 0",
"output": "Yes"
},
{
"input": "0 0 2 0 4 0",
"output": "No"
},
{
"input": "1 1 3 3 5 5",
"output": "No"
},
{
"input": "1 1 2 2 3 1",
"output": "Yes"
}
] | 61 | 5,529,600 | 0 | 3,660 |
|
920 | SUM and REPLACE | [
"brute force",
"data structures",
"dsu",
"number theory"
] | null | null | Let *D*(*x*) be the number of positive divisors of a positive integer *x*. For example, *D*(2)<==<=2 (2 is divisible by 1 and 2), *D*(6)<==<=4 (6 is divisible by 1, 2, 3 and 6).
You are given an array *a* of *n* integers. You have to process two types of queries:
1. REPLACE *l* *r* — for every replace *a**i* with *D*(*a**i*); 1. SUM *l* *r* — calculate .
Print the answer for each SUM query. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the elements of the array.
Then *m* lines follow, each containing 3 integers *t**i*, *l**i*, *r**i* denoting *i*-th query. If *t**i*<==<=1, then *i*-th query is REPLACE *l**i* *r**i*, otherwise it's SUM *l**i* *r**i* (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
There is at least one SUM query. | For each SUM query print the answer to it. | [
"7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7\n"
] | [
"30\n13\n4\n22\n"
] | none | [
{
"input": "7 6\n6 4 1 10 3 2 4\n2 1 7\n2 4 5\n1 3 5\n2 4 4\n1 5 7\n2 1 7",
"output": "30\n13\n4\n22"
},
{
"input": "4 2\n1 1 1 3\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 9\n1 1 10\n2 1 10",
"output": "12"
},
{
"input": "4 2\n1 1 3 1\n1 1 4\n2 1 4",
"output": "5"
},
{
"input": "5 3\n1 1 1 1 3\n2 1 5\n1 1 5\n2 1 5",
"output": "7\n6"
},
{
"input": "7 10\n1 1 1 1 1 1 1\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n1 1 7\n2 1 7",
"output": "7"
}
] | 2,000 | 19,558,400 | 0 | 3,673 |
|
665 | Buses Between Cities | [
"implementation"
] | null | null | Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* minutes.
The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.
You know the time when Simion departed from the city *A* to the city *B*. Calculate the number of buses Simion will meet to be sure in his counting. | The first line contains two integers *a*,<=*t**a* (1<=≤<=*a*,<=*t**a*<=≤<=120) — the frequency of the buses from the city *A* to the city *B* and the travel time. Both values are given in minutes.
The second line contains two integers *b*,<=*t**b* (1<=≤<=*b*,<=*t**b*<=≤<=120) — the frequency of the buses from the city *B* to the city *A* and the travel time. Both values are given in minutes.
The last line contains the departure time of Simion from the city *A* in the format hh:mm. It is guaranteed that there are a bus from the city *A* at that time. Note that the hours and the minutes are given with exactly two digits. | Print the only integer *z* — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities *A* and *B*. | [
"10 30\n10 35\n05:20\n",
"60 120\n24 100\n13:00\n"
] | [
"5\n",
"9\n"
] | In the first example Simion departs form the city *A* at 05:20 AM and arrives to the city *B* at 05:50 AM. He will meet the first 5 buses from the city *B* that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city *B* at 05:50 AM, but he will not count it.
Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed). | [
{
"input": "10 30\n10 35\n05:20",
"output": "5"
},
{
"input": "60 120\n24 100\n13:00",
"output": "9"
},
{
"input": "30 60\n60 60\n22:30",
"output": "2"
},
{
"input": "30 60\n10 60\n23:30",
"output": "8"
},
{
"input": "5 45\n4 60\n21:00",
"output": "26"
},
{
"input": "1 1\n1 1\n10:28",
"output": "1"
},
{
"input": "4 1\n5 4\n18:40",
"output": "1"
},
{
"input": "8 8\n1 1\n13:24",
"output": "8"
},
{
"input": "20 4\n1 20\n06:20",
"output": "23"
},
{
"input": "15 24\n23 6\n21:15",
"output": "1"
},
{
"input": "30 19\n21 4\n10:30",
"output": "1"
},
{
"input": "31 15\n36 25\n07:04",
"output": "1"
},
{
"input": "24 3\n54 9\n18:12",
"output": "0"
},
{
"input": "18 69\n62 54\n08:00",
"output": "2"
},
{
"input": "33 58\n70 78\n22:36",
"output": "2"
},
{
"input": "68 34\n84 78\n10:40",
"output": "1"
},
{
"input": "15 14\n32 65\n05:45",
"output": "2"
},
{
"input": "40 74\n100 42\n05:40",
"output": "2"
},
{
"input": "65 49\n24 90\n07:10",
"output": "6"
},
{
"input": "1 1\n1 1\n23:59",
"output": "1"
},
{
"input": "23 118\n118 20\n23:24",
"output": "0"
},
{
"input": "3 88\n17 38\n22:33",
"output": "8"
},
{
"input": "3 1\n2 3\n05:03",
"output": "1"
},
{
"input": "1 1\n3 2\n08:44",
"output": "0"
},
{
"input": "1 3\n1 2\n21:43",
"output": "4"
},
{
"input": "2 28\n2 12\n05:12",
"output": "19"
},
{
"input": "60 120\n17 120\n23:00",
"output": "11"
},
{
"input": "1 55\n1 54\n23:59",
"output": "54"
},
{
"input": "66 75\n1 82\n06:06",
"output": "141"
},
{
"input": "1 90\n1 88\n23:59",
"output": "88"
},
{
"input": "1 120\n1 100\n23:59",
"output": "100"
}
] | 186 | 23,244,800 | 3 | 3,674 |
|
412 | Pattern | [
"implementation",
"strings"
] | null | null | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.
Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given *n* patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns.
It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters. | In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them. | [
"2\n?ab\n??b\n",
"2\na\nb\n",
"1\n?a?b\n"
] | [
"xab\n",
"?\n",
"cacb\n"
] | Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on. | [
{
"input": "2\n?ab\n??b",
"output": "xab"
},
{
"input": "2\na\nb",
"output": "?"
},
{
"input": "1\n?a?b",
"output": "cacb"
},
{
"input": "1\n?",
"output": "x"
},
{
"input": "3\nabacaba\nabacaba\nabacaba",
"output": "abacaba"
},
{
"input": "3\nabc?t\n?bc?z\nab??t",
"output": "abcx?"
},
{
"input": "4\nabc\ndef\n???\nxyz",
"output": "???"
},
{
"input": "2\n?????\n?????",
"output": "xxxxx"
},
{
"input": "2\na\na",
"output": "a"
},
{
"input": "3\nabc\n???\naxc",
"output": "a?c"
},
{
"input": "1\n?m??x?xxexxx?xxmxx??",
"output": "cmccxcxxexxxcxxmxxcc"
},
{
"input": "2\nhszhh?zszs\nhhzhz?zzhs",
"output": "h?zh?cz??s"
},
{
"input": "3\neddzde\needded\nzdde?z",
"output": "??d???"
},
{
"input": "4\nff?o?\nfk?of\nk?kof\nfk?oo",
"output": "??ko?"
},
{
"input": "5\nyigi\ne?gi\niig?\n?eg?\n??gi",
"output": "??gi"
},
{
"input": "100\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz\nz",
"output": "z"
},
{
"input": "100\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?\nb?",
"output": "bc"
},
{
"input": "1\nq",
"output": "q"
},
{
"input": "2\n?\n?",
"output": "x"
},
{
"input": "2\n?\na",
"output": "a"
},
{
"input": "2\n?\nb",
"output": "b"
},
{
"input": "3\n?\na\na",
"output": "a"
},
{
"input": "3\na\n?\na",
"output": "a"
},
{
"input": "3\na\nb\n?",
"output": "?"
},
{
"input": "3\n?\na\nb",
"output": "?"
},
{
"input": "3\nb\n?\na",
"output": "?"
},
{
"input": "2\n???\naaa",
"output": "aaa"
},
{
"input": "2\n??\nss",
"output": "ss"
}
] | 218 | 4,198,400 | 3 | 3,678 |
|
312 | Whose sentence is it? | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iapelala.\nCFPlbUgObrXLejPNu.F\nZSUfvisiHyrIMjMlala.\nmiao. lala.\nd,IWSeumytrVlala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's"
},
{
"input": "10\nmiao.,taUvXPVlala.\nmiao.txEeId.X_lala.\nLZIeAEd JaeBVlala.\ncKPIsWpwIlala.\nfYp.eSvn,g\nKMx,nFEslala.\nmiao.QtMyxYqiajjuM\nDutxNkCqywgcnCYskcd\ngFLKACjeqfD\n,Ss UmY.wJvcX",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.Plala.\nDVm,VYslala.\nmiao.rlala.\nmiao.,KQNL.fO_.QRc\nUBLCKEUePlala.\nIouS.Alala.\nmiao.lala.\nmiao.rlala.\nEJZwRJeKlala.\nmiao.Olala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nRainbow's\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.grFTpju.jCLRnZ\ng.pVHYA_Usnm\nlloWONolcMFElala.\nAW,n.JJkOTe.Nd\n.bP.HvKlala.\nGziqPGQa,lala.\nmiao.,QkOCH.vFlala.\n.PUtOwImvUsoeh \nmiao.Z,KIds.R\nmiao.,_MDzoaAiJlala.",
"output": "Rainbow's\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.xWfjV\nHFVrGCDQXyZ,Sbm\nLMDS.xVkTCAY.vm\nmiao.lLBglala.\nnl,jRPyClala.\nFYnHoXlala.\nmiao. oxaHE\n.WTrw_mNpOQCa\nHOk..wHYoyMhl\nQX,XpMuPIROM",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nJBQqiXlala.\npUNUWQRiMPCXv\nAiLnfNHWznwkC.lala.\nmiao.Dl_Oy\nxJJJkVkdfOzQBH_SmKh\nfgD_IHvdHiorE,W\nmiao.usBKixglala.\nwCpqPUzEtD\nmiao.rlala.\nmiao.JylcGvWlala.",
"output": "Freda's\nOMG>.< I don't know!\nFreda's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao..FLhPl_Wjslala.\nmiao. tdEGtfdJlala.\nGAzEUlala.\nKCcmOa .aKBlZyYsdu.V\nmiao.lala.\njKylnM,FXK\nmiao.GBWqjGH.v\nmiao.RefxS Cni.\nOxaaEihuHQR_s,\nmiao.a,Axtlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nNo.I_aTXlala.\nmiao.JKSCoRZS\nnOBMIlala.\nmiao.nlala.\nmiao._xqxoHIIlala.\nmiao.NJPy SWyiUDWc\nmiao.cCnahFaqqj.Xqp\nnreSMDeXPPYAQxI,W\nAktPajWimdd_qRn\nmiao.QHwKCYlala.",
"output": "Freda's\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\n \n,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ ,.._ \n \nmiao.miao.miao.\nlala.lala.lala.\nlala.miao.\nmiaolala. \nmiao.lala\nmiaolala_\n,.._ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nduClyjMIPsEuWmx_Ce.byVoizYlTM,sF\nuZHsNip_,Mwtg,FZjM_LzPC,_pSvEOyTHfAOvoZXvxCZdgYDTCDdCAoSVZWyxXGcLgWlala.\nEGtJFPAvTEcqjkhaGxdduaQ_rmUzF.WaU, EIuX B,aVzFFpFrxpwADXuayRD azDfj \n_tJqYzXyqc.,u.F,mUYukveBPWnPq,f,dJnPHuBazdnbRHfzwNUdRbheAIjcoaPcnLvocrzcioxCapb R\n.YUBeb_zmwUt.QQuUdQIiOXtqshcsycEe,HLytHlala.\ndJndLqGBHt.GfpN.BgvsbXoLh_DIzAJOtFDmLSCYEztvPcS_GHPxivzV,NPMmSAtfk.Mg.w,A UcCt_lCD.csEzyJJBYtSMkzqiA\nmiao.qlala.\nmiao.FmDlY\nmiao.UQI.aJmnanNvRLskuVaMybDMsOlala.\nmiao.lala.",
"output": "OMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nmiao.vyscfysAtWcPkpFHdwZqAQ,UPPcjhKQTlala.\nmiao.KESqus DybUuYFoWVpo..LWZh.UqEdUsTHFlKfzqkThAUPklala.\nUNoE vfZIAdxkiWKhsHPfsqRPTNQoHgAxooVLYxRzugHjo jaEHWQFF\nCCmdIwr.UkoiYWK.Z,,ZesMpISTXNgnpYnJaWquCyL,gO\n.JvOayhXK_bgoYbfAtnXg\nbvdSzRrXoGxVgWvdXnsjEnEfxDzIQo_aZVGDGrzwuAMtzVAHioMBx_DHuTxyieGbGuSRNUojOREqxBBxvCgqAOMzwIWT\nMBuaWduZmRaOGyIPzWOsBVeqtDrblAbXxmM_uRfqMvnVlLEuhVKlhidN_aigiXyq,ZEDqQAx\nmiao.wCHVCuVKNePKmIUFLL_lala.\nmiao.iAqstXHUv\n pMO yvPkNtnNwmUCao W,wW.OvIMVaEeVYHmqaniWq.ivlala.",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nFreda's"
},
{
"input": "10\nmiao.\nmiao.jrwLBCpNaDCjyoK.PFzbwWU.h.. wfQquG_P..lala.\nmiao.LGlYdKjw__.Chlala.\nW.wtr qG KDOHj.xWxPbXIXjD_,GJZDaAZ,JBHphsjWJwSKcZAIAi\nmiao.pHsGAZQDWPJQwKC.zHjJituLgp.eUrzObTI.wrpect.FMUJqu,Zuslala.\nmiao.YVlOpXccUA_YU igbsbZbhOVwyYTyOjnWqgiTmxwAuFa.flCHn.,MtVbqxZQl_BGHXWkwijGjuL, ,ezyNlala.\nmiao.xCrVSz.aMv UOSOroDlQxWeBmlWe.FA.ZfUmviMlala.\nxebAlala.\nmiao.qVSxqf vOTlala.\nD.oBUwsLQRgXAoNkQJhQN.w.oMhuvtujnmiwgQYMfjlNTSHh .lSKgI.OEp",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nZXXzYlTiQU\nkXE.DdcbOojSaSgjMcFBPubKHefEVAzbi,PDFgSZIz,lala.\nxEfrTCjKhhwBC.UNmJXgTGUdkQeVDlala.\nLfaEw.jvMmuOBWtfoiJNtDIlQAVWNU,xWK_efBBtfkM\nqtBpqKZMWZMX_NKrUAEKYyQcLZWQlqbM\nmiao.PrJEbUtInremuaKRItqXOrfQEjQcAak VQ\nMpGCq awvQaHRvDr uvtVMKsvZI\nmiao.A.RVGu.szCEp.pXQJwL EuTltlN.WradoTvWHJyhcNSoulala.\nmiao.rzlUHzUdxtDRpWRuc,QZwEBfsKKGHMLGtFymPPQdptLFlzZ_ORWqrlfOrlntuDkpXEvz.CxwAsFYUvpnOnFWG\nmiao.VXUoNBwlgBwcna_n.CgAAcKKUuiVA.doOJKHpMdwNwlHAcLpdfN.Awa SthrlEWpUcuOonUTxIQNszYcHDXxnhArrM..A",
"output": "OMG>.< I don't know!\nFreda's\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's"
},
{
"input": "10\nmiao.qbxBFzrjtWv.yOk\nDBgi,loApO AACrGnwssCHN\nmiao.LV.wbQEE_V.BSAtdTIHTQOJVJ_nGOthbL,nJvQ.UeWFpsa.GGsK_Uv,HQxHS,AN_bkrolala.\nmiao.tBEqk rIQuByGKhfq_iP.BW,nySZEfrfySEcqnnIzxC,lrjIiivbxlkoVXJFiegGFRn NO,txGPhVBcv.CVhMmNO zlala.\nmiao.aBZWDWxk.wkR ,NyCzGxJnJDqBZpetdUPAmmBZDXl_Tbflala.\nmiao. XN,uMwWm. VqloYr..jTLszlala.\n.rshcgfZ.eZOdMu_RMh\nmiao.ahiwpECEe.lala.\nLeoUSroTekQAMSO__M L_ZEeRD_tUihYvQETFB,RzJmFtFiKrU\nBtygQG_OoFEFBL.KsVWTYbtqtalXoStFCZ RINHda.NuLmlkRB.vAQJFvelbsfoJ.T,M sJn",
"output": "Rainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nYoYBCcaqhXLfvKKf.UYMODTHyPZlala.\ncxgWn J.Q\nmiao.nwH.IHntgKYDhdsjU DMTHXEVRyeJP ZaAecCIBJXuv.YjhEmtbjvjKnK.U,oc,x\nmiao.EcQ.FDtRJgmpAzxhq.RwXBLxjyC,IeMqaFoheMPFCGWBcwUAFnbiwlbz_fcsEGPfJaeryCtFocBNEWTlala.\nmiao.W\nmiao. ZQpIeyCXJSnFgAIzu.THfrmyoogYWQzFqblala.\nmiao.ifzdCwnTDcxpvdr OTC.YqPv.MKDp..utICtAsbfYyGlala.\nmiao.\nmiao.tS.U.wH.s,CxORZJsBAHLi,fXeoDJWVBH\nrcUMpeupOVRKrcIRAvU.rP kgUEfoeXcrFPQOBYG.BNvAQPg.XHMWizhLpZNljXc .LQmVXCi",
"output": "Freda's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nlala.\nmiao.milalala.lmmialamiao.la.o.iao.a.ao.\nmialala.o.\nmiao.millala.allala.amiao..miao.miao.lala.ao.miammiao.iao.o.\nmiao.miaomiao..\nlalmiao.amiao..\nmiao.lala.lamiamiaolala..o.lalala.miao..\nmlala.iao.lalamiao..\nlmlala.iao.alalamiao.lmialala.lala.miao.o.alala..lala..lalmiaomiao..lalmiao.a.lalamiao..miao.alala..\nlalllamiao.la.lala.alamiao.lalalala.lala..miao.lamiao.la.lallalamiao..a..a.",
"output": "Freda's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlalllala.ala.lala.a.mmimiao.aomiao.lllala.ala.amiao.la.mialalala.la.o..imiao.miao.amlala.iao.o.\nmilala.alllala.ala.amiao.lamiao..o.\nlala.lalalala..lalalala..\nlala.miao.\nmimiao.ao.lala.\nlalmiao.amlala.iamialala.o.o..\nlalammlala.iaolammiao.imiao.ao.la..iao..\nmiao.mialala.omiao..mlala.iaolala..\nmiamiao.o.llallala.ala.la.miao.ala.miao.mimialmiao.ala.o.alala.miaomiao..olala..\nmialala.lamiao.la.lala.miao.ollala.allala.ala.lmiaommiao.imiao.ao.lallallala.a.miao.a..a..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nFreda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "10\nlamiao.lamiao.mimiao.ao..\nllala.almiaomiao..lala.miao.a.\nlalala.lala.lalala.lala.lalala..la.\nlalala.la.miao.\nmiao.llalallala.miao.a.la.lala.almimiao.ao.a.\nmiao.mlala.ilala.aomilala.ao..\nmilala.ao.\nmmiao.iao.\nmlala.lala.ialalmiao.alala..olala.lala..\nlala.lmlalalalalala...iao.milala.aommiao.iao..alamiaolallala.milala.ao.a..lalalmiao.a..llala.amiao..",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nRainbow's\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "4\n \n miao. \n lala. \n ",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
},
{
"input": "1\nMiao.",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nm",
"output": "OMG>.< I don't know!"
},
{
"input": "1\nMiAo.sdsdlala.",
"output": "Freda's"
},
{
"input": "1\nLalA.",
"output": "OMG>.< I don't know!"
},
{
"input": "3\n.\nm\nl",
"output": "OMG>.< I don't know!\nOMG>.< I don't know!\nOMG>.< I don't know!"
}
] | 124 | 2,048,000 | -1 | 3,681 |
|
932 | Palindromic Supersequence | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".
A palindrome is a string that reads the same forward or backward.
The length of string *B* should be at most 104. It is guaranteed that there always exists such string.
You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpa",
"output": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpaapkxovfyaifzjikpcxhemrcpwhypaabnoeifgfygtiqvuoihntvuvbrlnkywutodwrmvgrumdjzqhfoenxphzrdgtwmljdm..."
},
{
"input": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadco",
"output": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadcoocdafcilhkrgpvtsyrmzilywzgrtebnaldqqcmrfvsfehjkbetprwlvyscuxef..."
},
{
"input": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxar",
"output": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxarraxluhthchsyjjpegbmmzflbvzbunpfhzruoghtlgtearurzueovxcivvfbqlssonqkjiybmbjbzpffixfcdwbrpwyhvzbdjmchzjfnrjdoupimgkyyhfgppveltacqczktdxkawpzdmkmyikyjtqznvjdnkkmikemtyjsgdlheyjltiwcxpfvxqtxwwvgkjcrzbkxkandsekqwxpequ..."
},
{
"input": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjg",
"output": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjggjferujlznjmyalmuspib..."
},
{
"input": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgm",
"output": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgmmgszzmttxopywvrbvmgavsgwqergikztssmlnktgpolmcbrropknnkeiytztyrlqthshvbosemmjbzpsvcytuzynrqygcfoqsywdkrvjftdagjdgjyynfkcdkmwaqhzfewry..."
},
{
"input": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyj",
"output": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyjjycqccvmgjgqjfbxjzrdgbsqyseehcjsyxlbrettpfcjdvjerwvaixetfjxjxkdwcwlmwqkrgrhwzopjnilmonwtxsdonvyuazaqghlplvlisqdqbpvxkjpovqohbarttqoqm..."
},
{
"input": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgd",
"output": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgddgmsixjxsmwpfzyxrnkjqrbrfyprvlvbegdmgsidepusixegsdukxmudmjuqqzkefrzymgkluqqrigtpmznhvswwhqbiiizogjofdvfqdrfabswiclfpkiermnozbdmxieoxornesifoiuxgffjelsvcoofviyorrpwkffvvfjaubzeuzqbdhfjgujqoejsktzfzaypaxipweiawzojidcustlgyfhkbfgwshbdkzneilwwqemqblw..."
},
{
"input": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohlig",
"output": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohliggilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlw..."
},
{
"input": "abcab",
"output": "abcabbacba"
},
{
"input": "baaaaaaa",
"output": "baaaaaaaaaaaaaab"
},
{
"input": "baaaaaa",
"output": "baaaaaaaaaaaab"
},
{
"input": "baaaaaaaaa",
"output": "baaaaaaaaaaaaaaaaaab"
},
{
"input": "baaaaaaaa",
"output": "baaaaaaaaaaaaaaaab"
}
] | 77 | 5,632,000 | 3 | 3,694 |
|
670 | Game of Robots | [
"implementation"
] | null | null | In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the *n*-th robot says his identifier.
Your task is to determine the *k*-th identifier to be pronounced. | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2).
The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different. | Print the *k*-th pronounced identifier (assume that the numeration starts from 1). | [
"2 2\n1 2\n",
"4 5\n10 4 18 3\n"
] | [
"1\n",
"4\n"
] | In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As *k* = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As *k* = 5, the answer equals to 4. | [
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "4 5\n10 4 18 3",
"output": "4"
},
{
"input": "1 1\n4",
"output": "4"
},
{
"input": "2 1\n5 1",
"output": "5"
},
{
"input": "2 2\n1 4",
"output": "1"
},
{
"input": "2 3\n6 7",
"output": "7"
},
{
"input": "3 1\n4 5 6",
"output": "4"
},
{
"input": "3 2\n4 5 6",
"output": "4"
},
{
"input": "3 3\n4 5 6",
"output": "5"
},
{
"input": "3 4\n4 5 6",
"output": "4"
},
{
"input": "3 5\n4 5 6",
"output": "5"
},
{
"input": "3 6\n4 5 6",
"output": "6"
},
{
"input": "4 1\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 2\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 3\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 4\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 5\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 6\n5 1000000000 999999999 12",
"output": "999999999"
},
{
"input": "4 7\n5 1000000000 999999999 12",
"output": "5"
},
{
"input": "4 8\n5 1000000000 999999999 12",
"output": "1000000000"
},
{
"input": "4 9\n5 1000000000 999999999 12",
"output": "999999999"
},
{
"input": "4 10\n5 1000000000 999999999 12",
"output": "12"
}
] | 1,013 | 268,390,400 | 0 | 3,695 |
|
644 | Hostname Aliases | [
"*special",
"binary search",
"data structures",
"implementation",
"sortings",
"strings"
] | null | null | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct. | First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | [
"10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",
"14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n"
] | [
"1\nhttp://abacaba.de http://abacaba.ru \n",
"2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n"
] | none | [
{
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test",
"output": "1\nhttp://abacaba.de http://abacaba.ru "
},
{
"input": "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a",
"output": "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc "
},
{
"input": "10\nhttp://tqr.ekdb.nh/w\nhttp://p.ulz/ifw\nhttp://w.gw.dw.xn/kpe\nhttp://byt.mqii.zkv/j/xt\nhttp://ovquj.rbgrlw/k..\nhttp://bv.plu.e.dslg/j/xt\nhttp://udgci.ufgi.gwbd.s/\nhttp://l.oh.ne.o.r/.vo\nhttp://l.oh.ne.o.r/w\nhttp://tqr.ekdb.nh/.vo",
"output": "2\nhttp://l.oh.ne.o.r http://tqr.ekdb.nh \nhttp://bv.plu.e.dslg http://byt.mqii.zkv "
},
{
"input": "12\nhttp://ickght.ck/mr\nhttp://a.exhel/.b\nhttp://a.exhel/\nhttp://ti.cdm/\nhttp://ti.cdm/x/wd/lm.h.\nhttp://ickght.ck/a\nhttp://ickght.ck\nhttp://c.gcnk.d/.b\nhttp://c.gcnk.d/x/wd/lm.h.\nhttp://ti.cdm/.b\nhttp://a.exhel/x/wd/lm.h.\nhttp://c.gcnk.d/",
"output": "1\nhttp://a.exhel http://c.gcnk.d http://ti.cdm "
},
{
"input": "14\nhttp://jr/kgb\nhttp://ps.p.t.jeua.x.a.q.t\nhttp://gsqqs.n/t/\nhttp://w.afwsnuc.ff.km/cohox/u.\nhttp://u.s.wbumkuqm/\nhttp://u.s.wbumkuqm/cohox/u.\nhttp://nq.dzjkjcwv.f.s/bvm/\nhttp://zoy.shgg\nhttp://gsqqs.n\nhttp://u.s.wbumkuqm/b.pd.\nhttp://w.afwsnuc.ff.km/\nhttp://w.afwsnuc.ff.km/b.pd.\nhttp://nq.dzjkjcwv.f.s/n\nhttp://nq.dzjkjcwv.f.s/ldbw",
"output": "2\nhttp://ps.p.t.jeua.x.a.q.t http://zoy.shgg \nhttp://u.s.wbumkuqm http://w.afwsnuc.ff.km "
},
{
"input": "15\nhttp://l.edzplwqsij.rw/\nhttp://m.e.mehd.acsoinzm/s\nhttp://yg.ttahn.xin.obgez/ap/\nhttp://qqbb.pqkaqcncodxmaae\nhttp://lzi.a.flkp.lnn.k/o/qfr.cp\nhttp://lzi.a.flkp.lnn.k/f\nhttp://p.ngu.gkoq/.szinwwi\nhttp://qqbb.pqkaqcncodxmaae/od\nhttp://qqbb.pqkaqcncodxmaae\nhttp://wsxvmi.qpe.fihtgdvi/e./\nhttp://p.ngu.gkoq/zfoh\nhttp://m.e.mehd.acsoinzm/xp\nhttp://c.gy.p.h.tkrxt.jnsjt/j\nhttp://wsxvmi.qpe.fihtgdvi/grkag.z\nhttp://p.ngu.gkoq/t",
"output": "0"
},
{
"input": "15\nhttp://w.hhjvdn.mmu/.ca.p\nhttp://m.p.p.lar/\nhttp://lgmjun.r.kogpr.ijn/./t\nhttp://bapchpl.mcw.a.lob/d/ym/./g.q\nhttp://uxnjfnjp.kxr.ss.e.uu/jwo./hjl/\nhttp://fd.ezw.ykbb.xhl.t/\nhttp://i.xcb.kr/.ca.p\nhttp://jofec.ry.fht.gt\nhttp://qeo.gghwe.lcr/d/ym/./g.q\nhttp://gt\nhttp://gjvifpf.d/d/ym/./g.q\nhttp://oba\nhttp://rjs.qwd/v/hi\nhttp://fgkj/\nhttp://ivun.naumc.l/.ca.p",
"output": "4\nhttp://gt http://jofec.ry.fht.gt http://oba \nhttp://fd.ezw.ykbb.xhl.t http://fgkj http://m.p.p.lar \nhttp://i.xcb.kr http://ivun.naumc.l http://w.hhjvdn.mmu \nhttp://bapchpl.mcw.a.lob http://gjvifpf.d http://qeo.gghwe.lcr "
},
{
"input": "20\nhttp://gjwr/xsoiagp/\nhttp://gdnmu/j\nhttp://yfygudx.e.aqa.ezh/j\nhttp://mpjxue.cuvipq/\nhttp://a/\nhttp://kr/..n/c.\nhttp://a/xsoiagp/\nhttp://kr/z\nhttp://kr/v.cv/rk/k\nhttp://lvhpz\nhttp://qv.v.jqzhq\nhttp://y.no/\nhttp://kr/n\nhttp://y.no/xsoiagp/\nhttp://kr/ebe/z/\nhttp://olsvbxxw.win.n/j\nhttp://p.ct/j\nhttp://mpjxue.cuvipq/xsoiagp/\nhttp://kr/j\nhttp://gjwr/",
"output": "3\nhttp://lvhpz http://qv.v.jqzhq \nhttp://a http://gjwr http://mpjxue.cuvipq http://y.no \nhttp://gdnmu http://olsvbxxw.win.n http://p.ct http://yfygudx.e.aqa.ezh "
},
{
"input": "1\nhttp://a",
"output": "0"
},
{
"input": "3\nhttp://abacaba.com/test\nhttp://abacaba.de/test\nhttp://abacaba.de/test",
"output": "1\nhttp://abacaba.com http://abacaba.de "
}
] | 0 | 0 | -1 | 3,703 |
|
0 | none | [
"none"
] | null | null | A couple of friends, Axel and Marston are travelling across the country of Bitland. There are *n* towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There can be multiple roads between any pair of towns, and may even be a road from a town to itself. However, no pair of roads shares the starting and the destination towns along with their types simultaneously.
The friends are now located in the town 1 and are planning the travel route. Axel enjoys walking, while Marston prefers biking. In order to choose a route diverse and equally interesting for both friends, they have agreed upon the following procedure for choosing the road types during the travel:
- The route starts with a pedestrian route.- Suppose that a beginning of the route is written in a string *s* of letters P (pedestrain road) and B (biking road). Then, the string is appended to *s*, where stands for the string *s* with each character changed to opposite (that is, all pedestrian roads changed to bike roads, and vice versa).
In the first few steps the route will look as follows: P, PB, PBBP, PBBPBPPB, PBBPBPPBBPPBPBBP, and so on.
After that the friends start travelling from the town 1 via Bitlandian roads, choosing the next road according to the next character of their route type each time. If it is impossible to choose the next road, the friends terminate their travel and fly home instead.
Help the friends to find the longest possible route that can be travelled along roads of Bitland according to the road types choosing procedure described above. If there is such a route with more than 1018 roads in it, print -1 instead. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=2*n*2) — the number of towns and roads in Bitland respectively.
Next *m* lines describe the roads. *i*-th of these lines contains three integers *v**i*, *u**i* and *t**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=1), where *v**i* and *u**i* denote start and destination towns indices of the *i*-th road, and *t**i* decribes the type of *i*-th road (0 for a pedestrian road, 1 for a bike road). It is guaranteed that for each pair of distinct indices *i*, *j* such that 1<=≤<=*i*,<=*j*<=≤<=*m*, either *v**i*<=≠<=*v**j*, or *u**i*<=≠<=*u**j*, or *t**i*<=≠<=*t**j* holds. | If it is possible to find a route with length strictly greater than 1018, print -1. Otherwise, print the maximum length of a suitable path. | [
"2 2\n1 2 0\n2 2 1\n",
"2 3\n1 2 0\n2 2 1\n2 2 0\n"
] | [
"3\n",
"-1\n"
] | In the first sample we can obtain a route of length 3 by travelling along the road 1 from town 1 to town 2, and then following the road 2 twice from town 2 to itself.
In the second sample we can obtain an arbitrarily long route by travelling the road 1 first, and then choosing road 2 or 3 depending on the necessary type. | [] | 0 | 0 | -1 | 3,729 |
|
63 | Settlers' Training | [
"implementation"
] | B. Settlers' Training | 2 | 256 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.
Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.
To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present.
At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one.
You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*). | Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. | [
"4 4\n1 2 2 3\n",
"4 3\n1 1 1 1\n"
] | [
"4",
"5"
] | In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | [
{
"input": "4 4\n1 2 2 3",
"output": "4"
},
{
"input": "4 3\n1 1 1 1",
"output": "5"
},
{
"input": "3 3\n1 2 3",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 5\n1",
"output": "4"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "2 6\n2 5",
"output": "4"
},
{
"input": "6 10\n1 1 3 4 9 9",
"output": "10"
},
{
"input": "7 7\n1 1 1 1 1 1 7",
"output": "11"
},
{
"input": "10 10\n1 1 1 3 3 4 7 8 8 8",
"output": "11"
},
{
"input": "10 13\n1 1 1 1 1 1 1 1 1 1",
"output": "21"
},
{
"input": "10 13\n2 6 6 7 9 9 9 10 12 12",
"output": "11"
},
{
"input": "17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8",
"output": "17"
},
{
"input": "18 24\n3 3 3 4 5 7 8 8 9 9 9 9 10 10 11 11 11 11",
"output": "30"
},
{
"input": "23 2\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2",
"output": "12"
},
{
"input": "37 42\n1 1 1 1 1 2 2 2 2 2 3 4 4 4 4 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8",
"output": "70"
},
{
"input": "44 50\n38 38 38 38 38 38 38 39 39 39 39 39 39 39 40 40 40 40 40 41 41 41 41 41 41 41 42 42 42 43 43 43 44 44 44 44 45 45 45 46 46 46 46 46",
"output": "47"
},
{
"input": "57 100\n2 2 4 7 8 10 12 12 14 15 16 18 19 21 21 22 25 26 26 33 38 40 44 44 44 45 47 47 50 51 51 54 54 54 54 55 56 58 61 65 67 68 68 70 74 75 78 79 83 86 89 90 92 95 96 96 97",
"output": "99"
},
{
"input": "78 10\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "78"
},
{
"input": "96 78\n20 20 20 20 20 21 21 21 22 23 23 24 24 25 25 27 28 29 30 30 30 32 32 32 33 33 33 33 34 34 35 36 37 37 39 39 41 41 41 41 42 42 43 43 43 44 44 45 46 46 48 48 49 50 51 51 51 52 53 55 55 56 56 56 56 57 58 59 60 61 61 61 62 62 62 63 63 64 64 64 65 65 65 66 66 67 68 69 71 72 72 73 73 75 75 75",
"output": "98"
},
{
"input": "100 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 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "198"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n1 1 4 4 5 5 7 9 10 10 11 11 12 12 12 13 14 15 16 16 16 17 18 18 19 20 22 25 26 27 29 32 33 34 34 35 35 35 36 36 37 37 38 39 39 40 41 42 44 44 46 47 47 47 47 50 53 53 53 55 56 56 57 57 58 58 59 59 62 64 64 64 64 68 68 68 69 70 70 71 74 77 77 77 79 80 80 81 84 86 88 88 91 93 94 96 96 99 99 99",
"output": "108"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15",
"output": "184"
},
{
"input": "100 100\n20 20 20 21 21 21 21 21 22 23 23 23 23 23 23 24 24 25 25 26 26 26 26 26 27 27 27 27 28 28 28 28 29 29 29 29 29 30 30 30 30 31 32 32 34 34 34 34 34 34 34 34 35 35 35 36 36 37 37 37 37 37 37 38 38 38 39 40 41 41 42 42 42 42 42 43 43 43 44 44 44 44 44 45 45 45 45 45 46 46 46 46 46 47 47 47 48 48 48 50",
"output": "150"
},
{
"input": "100 2\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "59"
},
{
"input": "30 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49",
"output": "77"
},
{
"input": "40 20\n5 5 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 20 20 20 20 20 20 20 20 20 20",
"output": "31"
},
{
"input": "81 90\n1 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "89"
},
{
"input": "100 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13",
"output": "106"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 100",
"output": "197"
},
{
"input": "100 100\n49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51",
"output": "148"
},
{
"input": "1 100\n1",
"output": "99"
},
{
"input": "4 3\n1 1 2 2",
"output": "4"
},
{
"input": "10 100\n98 99 99 99 99 99 99 100 100 100",
"output": "7"
},
{
"input": "5 100\n1 2 2 100 100",
"output": "100"
}
] | 124 | 102,400 | 3.968809 | 3,736 |
769 | Year of University Entrance | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 2047 2048",
"output": "2048"
},
{
"input": "5\n2043 2042 2041 2044 2040",
"output": "2042"
},
{
"input": "5\n2012 2013 2014 2015 2016",
"output": "2014"
},
{
"input": "1\n2045",
"output": "2045"
},
{
"input": "1\n2046",
"output": "2046"
},
{
"input": "1\n2099",
"output": "2099"
},
{
"input": "1\n2100",
"output": "2100"
},
{
"input": "3\n2011 2010 2012",
"output": "2011"
},
{
"input": "3\n2011 2012 2010",
"output": "2011"
},
{
"input": "3\n2012 2011 2010",
"output": "2011"
},
{
"input": "3\n2010 2012 2011",
"output": "2011"
},
{
"input": "3\n2012 2010 2011",
"output": "2011"
},
{
"input": "3\n2047 2048 2049",
"output": "2048"
},
{
"input": "3\n2047 2049 2048",
"output": "2048"
},
{
"input": "3\n2048 2047 2049",
"output": "2048"
},
{
"input": "3\n2048 2049 2047",
"output": "2048"
},
{
"input": "3\n2049 2048 2047",
"output": "2048"
},
{
"input": "5\n2011 2014 2012 2013 2010",
"output": "2012"
},
{
"input": "5\n2014 2013 2011 2012 2015",
"output": "2013"
},
{
"input": "5\n2021 2023 2024 2020 2022",
"output": "2022"
},
{
"input": "5\n2081 2079 2078 2080 2077",
"output": "2079"
},
{
"input": "5\n2095 2099 2097 2096 2098",
"output": "2097"
},
{
"input": "5\n2097 2099 2100 2098 2096",
"output": "2098"
},
{
"input": "5\n2012 2010 2014 2011 2013",
"output": "2012"
},
{
"input": "5\n2012 2011 2013 2015 2014",
"output": "2013"
},
{
"input": "5\n2023 2024 2022 2021 2020",
"output": "2022"
},
{
"input": "5\n2077 2078 2080 2079 2081",
"output": "2079"
},
{
"input": "5\n2099 2096 2095 2097 2098",
"output": "2097"
},
{
"input": "5\n2097 2100 2098 2096 2099",
"output": "2098"
},
{
"input": "5\n2011 2014 2013 2010 2012",
"output": "2012"
},
{
"input": "5\n2013 2011 2015 2012 2014",
"output": "2013"
},
{
"input": "5\n2024 2020 2021 2023 2022",
"output": "2022"
},
{
"input": "5\n2079 2080 2077 2081 2078",
"output": "2079"
},
{
"input": "5\n2095 2097 2096 2098 2099",
"output": "2097"
},
{
"input": "5\n2099 2096 2100 2097 2098",
"output": "2098"
},
{
"input": "5\n2034 2033 2036 2032 2035",
"output": "2034"
},
{
"input": "5\n2030 2031 2033 2032 2029",
"output": "2031"
},
{
"input": "5\n2093 2092 2094 2096 2095",
"output": "2094"
},
{
"input": "5\n2012 2015 2014 2013 2011",
"output": "2013"
},
{
"input": "5\n2056 2057 2058 2059 2060",
"output": "2058"
}
] | 46 | 4,300,800 | 3 | 3,740 |
|
980 | The Number Games | [
"data structures",
"greedy",
"trees"
] | null | null | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$.
This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove? | The first line of input contains two integers $n$ and $k$ ($1 \leq k < n \leq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next $n-1$ lines each contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts. | Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number. | [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n"
] | [
"1 3 4\n",
"1 3 4 5\n"
] | In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4. | [
{
"input": "6 3\n2 1\n2 6\n4 2\n5 6\n2 3",
"output": "1 3 4"
},
{
"input": "8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5",
"output": "1 3 4 5"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 1\n2 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 3\n1 2",
"output": "1 2"
},
{
"input": "4 2\n4 2\n1 4\n3 2",
"output": "1 3"
},
{
"input": "15 3\n9 11\n11 8\n7 9\n9 14\n12 8\n10 7\n1 14\n1 5\n12 15\n10 3\n5 2\n13 15\n4 13\n6 4",
"output": "1 2 5"
},
{
"input": "15 12\n2 3\n2 14\n4 3\n4 10\n3 5\n1 4\n1 12\n4 15\n3 9\n10 7\n11 2\n12 8\n15 13\n1 6",
"output": "1 2 3 5 6 7 8 9 10 11 12 14"
},
{
"input": "32 16\n32 8\n11 32\n22 8\n22 17\n22 3\n16 22\n8 12\n22 7\n8 27\n11 6\n32 4\n9 8\n10 22\n22 31\n1 22\n21 11\n22 15\n14 32\n32 30\n22 29\n24 11\n18 11\n25 32\n13 8\n2 32\n28 8\n32 5\n11 20\n11 19\n22 23\n26 32",
"output": "1 2 3 4 5 6 7 9 10 12 13 14 15 16 17 18"
},
{
"input": "32 1\n30 25\n30 8\n8 22\n22 20\n21 20\n6 21\n29 6\n4 29\n2 4\n13 2\n1 13\n1 11\n11 24\n31 24\n31 15\n15 14\n27 14\n16 27\n5 16\n12 5\n9 12\n9 18\n3 18\n3 17\n17 19\n19 32\n32 10\n10 26\n7 26\n7 23\n23 28",
"output": "25"
},
{
"input": "32 2\n7 20\n15 20\n7 18\n31 20\n28 15\n20 25\n27 31\n27 6\n27 12\n6 16\n22 6\n21 22\n13 6\n16 5\n23 5\n23 26\n23 24\n23 17\n24 14\n17 4\n29 4\n2 24\n30 29\n1 29\n8 4\n30 32\n11 2\n32 3\n1 9\n11 10\n19 32",
"output": "3 8"
},
{
"input": "64 46\n52 22\n38 52\n28 38\n46 38\n30 38\n30 37\n7 37\n37 48\n48 27\n2 7\n27 11\n32 2\n32 35\n8 11\n59 32\n58 59\n59 24\n58 40\n40 4\n40 49\n40 41\n49 16\n9 16\n5 9\n12 9\n9 62\n3 62\n12 63\n63 25\n64 63\n63 42\n36 42\n45 36\n14 45\n53 45\n39 53\n60 39\n50 39\n50 23\n23 10\n19 50\n20 10\n19 56\n21 56\n31 56\n44 31\n26 31\n1 31\n43 44\n15 26\n15 6\n6 29\n47 6\n18 6\n29 55\n18 54\n33 54\n61 55\n54 17\n61 34\n13 17\n17 51\n57 34",
"output": "1 2 3 4 5 6 7 8 10 11 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 43 44 46 47 48 51 52 54 55 56 57 61"
},
{
"input": "64 63\n11 51\n64 11\n64 39\n11 6\n24 64\n51 63\n43 51\n64 29\n6 22\n47 6\n1 47\n41 22\n41 38\n4 47\n35 47\n41 23\n45 1\n52 35\n26 45\n15 35\n21 35\n23 32\n12 21\n21 62\n25 21\n28 25\n15 54\n57 12\n20 28\n48 57\n8 57\n20 44\n46 28\n18 57\n8 9\n27 9\n48 34\n50 46\n9 56\n9 61\n7 56\n19 61\n61 17\n42 17\n19 58\n58 30\n7 14\n7 59\n31 19\n17 5\n55 14\n13 31\n2 31\n59 40\n55 49\n2 60\n2 53\n36 2\n37 13\n2 16\n53 33\n37 10\n60 3",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63"
},
{
"input": "64 21\n33 48\n33 64\n55 48\n11 55\n18 11\n62 55\n48 57\n17 62\n64 52\n30 48\n49 48\n23 18\n13 11\n9 64\n11 5\n11 45\n2 55\n62 56\n64 36\n33 10\n34 18\n55 43\n3 48\n60 62\n48 32\n33 8\n62 41\n44 11\n33 46\n15 33\n14 62\n11 6\n64 31\n62 20\n64 25\n62 51\n53 33\n62 40\n18 4\n16 62\n21 11\n33 22\n37 33\n59 62\n55 7\n27 64\n24 64\n39 64\n19 62\n54 55\n33 61\n47 48\n58 55\n42 55\n38 11\n50 18\n28 48\n11 26\n11 1\n62 35\n64 29\n12 33\n18 63",
"output": "1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 19 20 21 22 23"
}
] | 140 | 20,172,800 | 0 | 3,743 |
|
645 | Mischievous Mess Makers | [
"greedy",
"math"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=<<=*j* and *p**i*<=><=*p**j*. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0. | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "100000 40000",
"output": "4799960000"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "100 45",
"output": "4905"
},
{
"input": "9 2",
"output": "26"
},
{
"input": "456 78",
"output": "58890"
},
{
"input": "100000 50000",
"output": "4999950000"
},
{
"input": "100000 50001",
"output": "4999950000"
},
{
"input": "100000 50002",
"output": "4999950000"
},
{
"input": "100000 50003",
"output": "4999950000"
},
{
"input": "100000 49998",
"output": "4999949994"
},
{
"input": "100000 49997",
"output": "4999949985"
},
{
"input": "99999 49998",
"output": "4999849998"
},
{
"input": "99999 49997",
"output": "4999849991"
},
{
"input": "99999 49996",
"output": "4999849980"
},
{
"input": "99999 50000",
"output": "4999850001"
},
{
"input": "99999 50001",
"output": "4999850001"
},
{
"input": "99999 50002",
"output": "4999850001"
},
{
"input": "30062 9",
"output": "540945"
},
{
"input": "13486 3",
"output": "80895"
},
{
"input": "29614 7",
"output": "414491"
},
{
"input": "13038 8",
"output": "208472"
},
{
"input": "96462 6",
"output": "1157466"
},
{
"input": "22599 93799",
"output": "255346101"
},
{
"input": "421 36817",
"output": "88410"
},
{
"input": "72859 65869",
"output": "2654180511"
},
{
"input": "37916 5241",
"output": "342494109"
},
{
"input": "47066 12852",
"output": "879423804"
},
{
"input": "84032 21951",
"output": "2725458111"
},
{
"input": "70454 75240",
"output": "2481847831"
},
{
"input": "86946 63967",
"output": "3779759985"
},
{
"input": "71128 11076",
"output": "1330260828"
},
{
"input": "46111 64940",
"output": "1063089105"
},
{
"input": "46111 64940",
"output": "1063089105"
},
{
"input": "56500 84184",
"output": "1596096750"
},
{
"input": "60108 83701",
"output": "1806455778"
},
{
"input": "1 2",
"output": "0"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "1 6",
"output": "0"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "3 4",
"output": "3"
},
{
"input": "3 5",
"output": "3"
},
{
"input": "4 1",
"output": "5"
},
{
"input": "4 2",
"output": "6"
},
{
"input": "4 3",
"output": "6"
},
{
"input": "4 4",
"output": "6"
},
{
"input": "4 5",
"output": "6"
},
{
"input": "5 1",
"output": "7"
},
{
"input": "5 3",
"output": "10"
},
{
"input": "5 4",
"output": "10"
},
{
"input": "5 5",
"output": "10"
},
{
"input": "6 1",
"output": "9"
},
{
"input": "6 2",
"output": "14"
},
{
"input": "6 3",
"output": "15"
},
{
"input": "7 2",
"output": "18"
},
{
"input": "7 3",
"output": "21"
},
{
"input": "7 4",
"output": "21"
},
{
"input": "10 2",
"output": "30"
},
{
"input": "60982 2",
"output": "243918"
},
{
"input": "23426 23",
"output": "1076515"
},
{
"input": "444 3",
"output": "2643"
},
{
"input": "18187 433",
"output": "15374531"
},
{
"input": "6895 3544",
"output": "23767065"
},
{
"input": "56204 22352",
"output": "1513297456"
},
{
"input": "41977 5207",
"output": "382917573"
},
{
"input": "78147 2321",
"output": "351981971"
},
{
"input": "99742 62198",
"output": "4974183411"
},
{
"input": "72099 38339",
"output": "2599096851"
},
{
"input": "82532 4838",
"output": "751762306"
},
{
"input": "79410 33144",
"output": "3066847464"
},
{
"input": "11021 3389",
"output": "51726307"
},
{
"input": "66900 7572",
"output": "898455660"
},
{
"input": "99999 49999",
"output": "4999850001"
},
{
"input": "100000 49999",
"output": "4999949999"
},
{
"input": "100000 100000",
"output": "4999950000"
},
{
"input": "100000 1",
"output": "199997"
},
{
"input": "4 100",
"output": "6"
},
{
"input": "100000 1234",
"output": "243753254"
}
] | 62 | 1,331,200 | 3 | 3,749 |
|
174 | Problem About Equation | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
"input": "3 5\n1 2 1",
"output": "2.000000\n1.000000\n2.000000"
},
{
"input": "10 95\n0 0 0 0 0 1 1 1 1 1",
"output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000"
},
{
"input": "3 5\n1 2 3",
"output": "2.666667\n1.666667\n0.666667"
},
{
"input": "3 5\n1 3 2",
"output": "2.666667\n0.666667\n1.666667"
},
{
"input": "3 5\n2 1 3",
"output": "1.666667\n2.666667\n0.666667"
},
{
"input": "3 5\n2 3 1",
"output": "1.666667\n0.666667\n2.666667"
},
{
"input": "3 5\n3 1 2",
"output": "0.666667\n2.666667\n1.666667"
},
{
"input": "3 5\n3 2 1",
"output": "0.666667\n1.666667\n2.666667"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "2 1\n2 2",
"output": "0.500000\n0.500000"
},
{
"input": "3 2\n2 1 2",
"output": "0.333333\n1.333333\n0.333333"
},
{
"input": "3 3\n2 2 1",
"output": "0.666667\n0.666667\n1.666667"
},
{
"input": "3 3\n3 1 2",
"output": "0.000000\n2.000000\n1.000000"
},
{
"input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72",
"output": "-1"
},
{
"input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6",
"output": "-1"
},
{
"input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92",
"output": "-1"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99",
"output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..."
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100",
"output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..."
},
{
"input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99",
"output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..."
},
{
"input": "10 100\n52 52 51 52 52 52 51 51 52 52",
"output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000"
},
{
"input": "10 100\n13 13 13 13 12 13 12 13 12 12",
"output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000"
},
{
"input": "10 100\n50 51 47 51 48 46 49 51 46 51",
"output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000"
},
{
"input": "10 100\n13 13 9 12 12 11 13 8 10 13",
"output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000"
},
{
"input": "93 91\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",
"output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..."
},
{
"input": "93 97\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..."
},
{
"input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99",
"output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..."
},
{
"input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..."
},
{
"input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99",
"output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..."
},
{
"input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52",
"output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923"
},
{
"input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13",
"output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118"
},
{
"input": "9 91\n52 51 50 52 52 51 50 48 51",
"output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889"
},
{
"input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12",
"output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529"
},
{
"input": "2 3\n1 1",
"output": "1.500000\n1.500000"
},
{
"input": "2 90\n0 89",
"output": "89.500000\n0.500000"
},
{
"input": "4 17\n3 4 8 1",
"output": "5.250000\n4.250000\n0.250000\n7.250000"
},
{
"input": "2 9\n5 5",
"output": "4.500000\n4.500000"
},
{
"input": "7 28\n1 3 9 10 9 6 10",
"output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143"
},
{
"input": "5 11\n1 2 3 4 5",
"output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000"
},
{
"input": "3 1\n100 100 100",
"output": "0.333333\n0.333333\n0.333333"
},
{
"input": "5 50\n2 2 3 2 2",
"output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000"
},
{
"input": "3 3\n2 2 3",
"output": "1.333333\n1.333333\n0.333333"
},
{
"input": "2 52\n2 100",
"output": "-1"
},
{
"input": "3 2\n2 2 3",
"output": "1.000000\n1.000000\n0.000000"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000"
},
{
"input": "2 4\n1 2",
"output": "2.500000\n1.500000"
},
{
"input": "5 49\n1 2 3 4 5",
"output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"
}
] | 248 | 6,758,400 | 3 | 3,756 |
|
630 | Lucky Numbers | [
"combinatorics",
"math"
] | null | null | The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. | The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. | Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. | [
"2\n"
] | [
"6"
] | none | [
{
"input": "2",
"output": "6"
},
{
"input": "1",
"output": "2"
},
{
"input": "3",
"output": "14"
},
{
"input": "5",
"output": "62"
},
{
"input": "12",
"output": "8190"
},
{
"input": "34",
"output": "34359738366"
},
{
"input": "43",
"output": "17592186044414"
},
{
"input": "49",
"output": "1125899906842622"
},
{
"input": "54",
"output": "36028797018963966"
},
{
"input": "55",
"output": "72057594037927934"
}
] | 31 | 0 | 3 | 3,762 |
|
474 | Worms | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile. | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 77 | 2,355,200 | 0 | 3,772 |
|
908 | New Year and Entity Enumeration | [
"bitmasks",
"combinatorics",
"dp",
"math"
] | null | null | You are given an integer *m*.
Let *M*<==<=2*m*<=-<=1.
You are also given a set of *n* integers denoted as the set *T*. The integers will be provided in base 2 as *n* binary strings of length *m*.
A set of integers *S* is called "good" if the following hold.
1. If , then . 1. If , then 1. 1. All elements of *S* are less than or equal to *M*.
Here, and refer to the bitwise XOR and bitwise AND operators, respectively.
Count the number of good sets *S*, modulo 109<=+<=7. | The first line will contain two integers *m* and *n* (1<=≤<=*m*<=≤<=1<=000, 1<=≤<=*n*<=≤<=*min*(2*m*,<=50)).
The next *n* lines will contain the elements of *T*. Each line will contain exactly *m* zeros and ones. Elements of *T* will be distinct. | Print a single integer, the number of good sets modulo 109<=+<=7. | [
"5 3\n11010\n00101\n11000\n",
"30 2\n010101010101010010101010101010\n110110110110110011011011011011\n"
] | [
"4\n",
"860616440\n"
] | An example of a valid set *S* is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}. | [
{
"input": "5 3\n11010\n00101\n11000",
"output": "4"
},
{
"input": "30 2\n010101010101010010101010101010\n110110110110110011011011011011",
"output": "860616440"
},
{
"input": "30 10\n001000000011000111000010010000\n000001100001010000000000000100\n000110100010100000000000101000\n110000010000000001000000000000\n100001000000000010010101000101\n001001000000000100000000110000\n000000010000100000001000000000\n001000010001000000001000000010\n000000110000000001001010000000\n000011001000000000010001000000",
"output": "80"
}
] | 608 | 13,107,200 | 3 | 3,775 |
|
131 | Opposites Attract | [
"implementation",
"math"
] | null | null | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to any number of customers.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1,<=*t*2,<=...,<=*t**n*. For example, if *t*<==<=(1,<=<=-<=1,<=1,<=<=-<=1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself. | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests. | Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | [
"5\n-3 3 0 0 3\n",
"3\n0 0 0\n"
] | [
"3\n",
"3\n"
] | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | [
{
"input": "5\n-3 3 0 0 3",
"output": "3"
},
{
"input": "3\n0 0 0",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "2\n-3 3",
"output": "1"
},
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "4\n1 -1 1 -1",
"output": "4"
},
{
"input": "10\n1 -1 2 -2 3 -3 4 -4 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"output": "10"
},
{
"input": "4\n4 4 4 -1",
"output": "0"
},
{
"input": "2\n10 -10",
"output": "1"
},
{
"input": "2\n-10 10",
"output": "1"
},
{
"input": "3\n-1 -1 2",
"output": "0"
},
{
"input": "2\n-1 2",
"output": "0"
},
{
"input": "7\n0 10 -10 10 -10 10 10",
"output": "8"
},
{
"input": "5\n-3 2 1 -1 3",
"output": "2"
},
{
"input": "4\n-10 10 -10 10",
"output": "4"
},
{
"input": "4\n1 -1 2 -2",
"output": "2"
}
] | 122 | 0 | 0 | 3,788 |
|
350 | TL | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist. | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 310 | 0 | 0 | 3,792 |
|
160 | Find Pair | [
"implementation",
"math",
"sortings"
] | null | null | You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing *n* (not necessarily different) integers *a*1, *a*2, ..., *a**n*. We are interested in all possible pairs of numbers (*a**i*, *a**j*), (1<=≤<=*i*,<=*j*<=≤<=*n*). In other words, let's consider all *n*2 pairs of numbers, picked from the given array.
For example, in sequence *a*<==<={3,<=1,<=5} are 9 pairs of numbers: (3,<=3),<=(3,<=1),<=(3,<=5),<=(1,<=3),<=(1,<=1),<=(1,<=5),<=(5,<=3),<=(5,<=1),<=(5,<=5).
Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (*p*1, *q*1) is lexicographically less than pair (*p*2, *q*2) only if either *p*1 < *p*2, or *p*1 = *p*2 and *q*1 < *q*2.
Then the sequence, mentioned above, will be sorted like that: (1,<=1),<=(1,<=3),<=(1,<=5),<=(3,<=1),<=(3,<=3),<=(3,<=5),<=(5,<=1),<=(5,<=3),<=(5,<=5)
Let's number all the pair in the sorted list from 1 to *n*2. Your task is formulated like this: you should find the *k*-th pair in the ordered list of all possible pairs of the array you've been given. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*2). The second line contains the array containing *n* integers *a*1, *a*2, ..., *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). The numbers in the array can coincide. All numbers are separated with spaces.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout, streams or the %I64d specificator instead. | In the single line print two numbers — the sought *k*-th pair. | [
"2 4\n2 1\n",
"3 2\n3 1 5\n"
] | [
"2 2\n",
"1 3\n"
] | In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2).
The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). | [
{
"input": "2 4\n2 1",
"output": "2 2"
},
{
"input": "3 2\n3 1 5",
"output": "1 3"
},
{
"input": "3 3\n1 1 2",
"output": "1 1"
},
{
"input": "1 1\n-4",
"output": "-4 -4"
},
{
"input": "3 7\n5 4 3",
"output": "5 3"
},
{
"input": "3 6\n10 1 3",
"output": "3 10"
},
{
"input": "4 12\n-1 -2 -3 -4",
"output": "-2 -1"
},
{
"input": "5 10\n1 2 2 1 3",
"output": "1 3"
},
{
"input": "5 13\n3 3 3 4 5",
"output": "3 5"
},
{
"input": "8 26\n4 4 1 1 1 3 3 5",
"output": "3 1"
},
{
"input": "10 90\n2 1 1 1 1 1 2 1 2 2",
"output": "2 2"
},
{
"input": "10 6\n3 1 1 3 2 2 2 3 3 3",
"output": "1 2"
},
{
"input": "10 18\n1 1 1 3 4 4 4 1 2 3",
"output": "1 2"
},
{
"input": "50 622\n4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2 3 7 9 10 2 9 9 7 3 8 6 10 6 5 4 8 1 1 5 6 8 9 5 9 5 3 2",
"output": "3 3"
},
{
"input": "50 2069\n9 97 15 22 69 27 7 23 84 73 74 60 94 43 98 13 4 63 49 7 31 93 23 6 75 32 63 49 32 99 43 68 48 16 54 20 38 40 65 34 28 21 55 79 50 2 18 22 95 25",
"output": "75 28"
},
{
"input": "100 9043\n4 1 4 2 1 4 2 2 1 1 4 2 4 2 4 1 4 2 2 1 2 2 2 2 1 1 2 3 2 1 1 3 2 3 1 4 2 2 2 4 1 4 3 3 4 3 4 1 1 4 2 2 4 4 4 4 4 1 1 2 3 1 3 4 1 3 1 4 1 3 2 2 3 2 3 1 2 3 4 3 3 2 3 4 4 4 2 3 2 1 1 2 2 4 1 2 3 2 2 1",
"output": "4 3"
},
{
"input": "100 4755\n5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3 1",
"output": "3 3"
},
{
"input": "100 6819\n4 3 4 6 2 5 2 2 5 6 6 6 1 3 1 3 2 2 2 3 4 5 2 1 6 4 5 3 2 3 4 4 4 3 5 6 3 2 4 5 2 3 2 1 1 6 4 1 5 6 4 3 4 2 4 1 3 2 3 1 2 2 5 1 3 2 5 1 3 2 4 5 1 3 5 5 5 2 6 6 6 3 1 5 4 6 3 3 4 3 1 4 1 1 1 1 2 4 2 6",
"output": "4 4"
},
{
"input": "10 50\n1 1 -9 -9 -9 7 7 7 7 7",
"output": "1 7"
},
{
"input": "9 76\n1 1 2 2 2 2 3 3 9",
"output": "9 2"
},
{
"input": "5 15\n1 1 1 2 2",
"output": "1 2"
},
{
"input": "5 7\n1 3 3 3 5",
"output": "3 1"
},
{
"input": "10 91\n1 1 1 1 1 1 1 1 1 2",
"output": "2 1"
},
{
"input": "5 20\n1 2 2 3 3",
"output": "3 2"
},
{
"input": "6 36\n1 1 2 2 2 2",
"output": "2 2"
},
{
"input": "5 16\n1 1 2 2 3",
"output": "2 2"
},
{
"input": "5 17\n1 3 3 5 5",
"output": "5 1"
},
{
"input": "5 17\n1 3 3 3 5",
"output": "3 3"
},
{
"input": "10 25\n1 2 2 3 4 5 6 7 8 9",
"output": "2 7"
},
{
"input": "10 90\n1 1 1 1 1 1 1 1 1 2",
"output": "1 2"
},
{
"input": "4 5\n3 1 3 1",
"output": "1 3"
},
{
"input": "3 5\n1 1 2",
"output": "1 2"
},
{
"input": "5 3\n0 1 2 3 4",
"output": "0 2"
}
] | 1,000 | 179,916,800 | 0 | 3,795 |
|
765 | Code obfuscation | [
"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. | [
{
"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"
}
] | 156 | 2,355,200 | 3 | 3,802 |
|
522 | Closest Equals | [
"*special",
"data structures"
] | null | null | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that:
- both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l**j*<=≤<=*x*,<=*y*<=≤<=*r**j*; - the values of the elements are equal, that is *a**x*<==<=*a**y*.
The text above understands distance as |*x*<=-<=*y*|. | The first line of the input contains a pair of integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Next *m* lines contain the queries, one per line. Each query is given by a pair of numbers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the indexes of the query range limits. | Print *m* integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query. | [
"5 3\n1 1 2 3 2\n1 5\n2 4\n3 5\n",
"6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6\n"
] | [
"1\n-1\n2\n",
"2\n2\n3\n-1\n2\n"
] | none | [
{
"input": "5 3\n1 1 2 3 2\n1 5\n2 4\n3 5",
"output": "1\n-1\n2"
},
{
"input": "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6",
"output": "2\n2\n3\n-1\n2"
},
{
"input": "10 6\n2 2 1 5 6 4 9 8 5 4\n1 2\n1 10\n2 10\n2 9\n5 5\n2 8",
"output": "1\n1\n4\n5\n-1\n-1"
},
{
"input": "1 1\n1\n1 1",
"output": "-1"
},
{
"input": "1 3\n1\n1 1\n1 1\n1 1",
"output": "-1\n-1\n-1"
},
{
"input": "2 1\n1 1\n1 2",
"output": "1"
},
{
"input": "2 1\n1 1\n1 1",
"output": "-1"
},
{
"input": "2 5\n1 1\n1 1\n1 2\n2 2\n1 2\n1 1",
"output": "-1\n1\n-1\n1\n-1"
},
{
"input": "2 4\n1 2\n1 1\n1 2\n2 2\n1 2",
"output": "-1\n-1\n-1\n-1"
}
] | 108 | 20,172,800 | 0 | 3,808 |
|
920 | Connected Components? | [
"data structures",
"dfs and similar",
"dsu",
"graphs"
] | null | null | You are given an undirected graph consisting of *n* vertices and edges. Instead of giving you the edges that exist in the graph, we give you *m* unordered pairs (*x*,<=*y*) such that there is no edge between *x* and *y*, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices *X* such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to *X* violates this rule. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=200000, ).
Then *m* lines follow, each containing a pair of integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*) denoting that there is no edge between *x* and *y*. Each pair is listed at most once; (*x*,<=*y*) and (*y*,<=*x*) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices. | Firstly print *k* — the number of connected components in this graph.
Then print *k* integers — the sizes of components. You should output these integers in non-descending order. | [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n"
] | [
"2\n1 4 "
] | none | [
{
"input": "5 5\n1 2\n3 4\n3 2\n4 2\n2 5",
"output": "2\n1 4 "
},
{
"input": "8 15\n2 1\n4 5\n2 4\n3 4\n2 5\n3 5\n2 6\n3 6\n5 6\n4 6\n2 7\n3 8\n2 8\n3 7\n6 7",
"output": "1\n8 "
},
{
"input": "12 58\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n4 5\n4 6\n4 8\n4 11\n4 12\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n7 8\n7 9\n7 10\n7 11\n7 12\n8 9\n8 10\n8 11\n9 10\n9 11\n9 12\n10 12",
"output": "4\n1 1 1 9 "
},
{
"input": "5 7\n1 2\n2 3\n3 4\n1 5\n2 5\n3 5\n4 5",
"output": "2\n1 4 "
},
{
"input": "6 10\n1 2\n1 3\n1 4\n1 6\n2 3\n2 4\n2 5\n3 5\n3 6\n4 6",
"output": "1\n6 "
},
{
"input": "8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8",
"output": "3\n1 2 5 "
},
{
"input": "4 3\n2 1\n3 1\n4 2",
"output": "1\n4 "
},
{
"input": "6 9\n1 2\n1 4\n1 5\n2 3\n2 5\n2 6\n3 5\n4 6\n5 6",
"output": "1\n6 "
},
{
"input": "2 0",
"output": "1\n2 "
},
{
"input": "8 18\n1 4\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 8\n4 7\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8",
"output": "1\n8 "
},
{
"input": "4 3\n1 2\n3 1\n4 3",
"output": "1\n4 "
},
{
"input": "8 23\n2 7\n7 5\n8 6\n8 2\n6 3\n3 5\n8 1\n8 4\n8 3\n3 4\n1 2\n2 6\n5 2\n6 4\n7 6\n6 5\n7 8\n7 1\n5 4\n3 7\n1 4\n3 1\n3 2",
"output": "3\n1 3 4 "
},
{
"input": "4 4\n2 1\n3 1\n1 4\n3 2",
"output": "2\n1 3 "
},
{
"input": "2 1\n1 2",
"output": "2\n1 1 "
},
{
"input": "4 3\n1 3\n1 4\n2 3",
"output": "1\n4 "
},
{
"input": "3 1\n2 3",
"output": "1\n3 "
},
{
"input": "5 4\n1 4\n2 3\n4 3\n4 2",
"output": "1\n5 "
},
{
"input": "10 36\n7 8\n7 9\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 9\n2 10\n4 5\n4 6\n4 7\n4 8\n4 10\n6 7\n6 9\n6 10\n1 2\n1 3\n1 4\n8 9\n1 5\n8 10\n1 7\n1 8\n1 9\n1 10\n3 4\n3 6\n3 7\n3 9\n5 6\n5 7\n5 9\n5 10",
"output": "2\n2 8 "
},
{
"input": "10 34\n7 10\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 10\n4 5\n4 6\n4 7\n4 8\n4 9\n6 7\n6 8\n6 9\n6 10\n1 2\n1 3\n1 5\n8 9\n1 6\n1 7\n1 8\n1 9\n1 10\n3 4\n3 5\n3 6\n3 8\n3 10\n5 6\n5 9\n5 10",
"output": "1\n10 "
},
{
"input": "12 56\n9 5\n2 6\n9 8\n5 4\n1 11\n1 6\n4 1\n1 10\n10 3\n8 4\n5 1\n9 1\n5 10\n2 7\n11 5\n6 11\n5 8\n7 6\n3 2\n12 7\n8 6\n12 3\n1 2\n8 1\n2 11\n10 12\n4 6\n5 12\n2 4\n10 2\n7 3\n12 11\n7 10\n7 1\n9 2\n11 9\n9 10\n8 7\n11 3\n7 9\n5 7\n4 12\n3 5\n12 2\n4 10\n9 12\n5 2\n9 4\n11 8\n8 2\n3 6\n4 11\n8 10\n6 10\n3 9\n3 4",
"output": "3\n1 4 7 "
},
{
"input": "11 49\n10 3\n6 4\n11 3\n7 6\n10 6\n6 1\n4 3\n10 2\n4 5\n9 2\n10 1\n5 7\n1 5\n9 7\n2 11\n8 6\n3 9\n2 5\n9 5\n6 5\n1 4\n11 9\n1 7\n8 10\n3 6\n3 7\n11 5\n6 9\n4 10\n8 7\n4 9\n8 2\n4 2\n8 11\n7 4\n9 10\n8 1\n10 7\n3 2\n5 8\n8 9\n1 3\n2 7\n10 11\n5 3\n10 5\n4 11\n1 11\n8 3",
"output": "5\n1 1 1 2 6 "
}
] | 2,292 | 268,390,400 | 0 | 3,809 |
|
0 | none | [
"none"
] | null | null | A factory produces thimbles in bulk. Typically, it can produce up to *a* thimbles a day. However, some of the machinery is defective, so it can currently only produce *b* thimbles each day. The factory intends to choose a *k*-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of *a* thimbles per day after the *k* days are complete.
Initially, no orders are pending. The factory receives updates of the form *d**i*, *a**i*, indicating that *a**i* new orders have been placed for the *d**i*-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day *p**i*. Help the owner answer his questions. | The first line contains five integers *n*, *k*, *a*, *b*, and *q* (1<=≤<=*k*<=≤<=*n*<=≤<=200<=000, 1<=≤<=*b*<=<<=*a*<=≤<=10 000, 1<=≤<=*q*<=≤<=200<=000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next *q* lines contain the descriptions of the queries. Each query is of one of the following two forms:
- 1 *d**i* *a**i* (1<=≤<=*d**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=10 000), representing an update of *a**i* orders on day *d**i*, or - 2 *p**i* (1<=≤<=*p**i*<=≤<=*n*<=-<=*k*<=+<=1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day *p**i*?
It's guaranteed that the input will contain at least one query of the second type. | For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all *n* days. | [
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n"
] | [
"3\n6\n4\n",
"7\n1\n"
] | Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.
For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. | [
{
"input": "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3",
"output": "3\n6\n4"
},
{
"input": "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2",
"output": "7\n1"
},
{
"input": "1 1 2 1 1\n2 1",
"output": "0"
}
] | 93 | 0 | 0 | 3,815 |
|
769 | k-Interesting Pairs Of Integers | [
"*special",
"bitmasks",
"brute force",
"meet-in-the-middle"
] | null | null | Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits.
Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. | Print the number of pairs (*i*, *j*) so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. | [
"4 1\n0 3 2 1\n",
"6 0\n200 100 100 100 200 200\n"
] | [
"4\n",
"6\n"
] | In the first test there are 4 k-interesting pairs:
- (1, 3), - (1, 4), - (2, 3), - (2, 4).
In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), - (5, 6). | [
{
"input": "4 1\n0 3 2 1",
"output": "4"
},
{
"input": "6 0\n200 100 100 100 200 200",
"output": "6"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "2 0\n0 0",
"output": "1"
},
{
"input": "2 0\n10000 10000",
"output": "1"
},
{
"input": "2 0\n0 10000",
"output": "0"
},
{
"input": "2 1\n0 1",
"output": "1"
},
{
"input": "2 1\n0 2",
"output": "1"
},
{
"input": "3 1\n0 1 2",
"output": "2"
},
{
"input": "3 2\n0 3 3",
"output": "2"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "10 0\n1 1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8192 8192 8192 8192 8192 8192 8191 8191 8192 8192 8191 8191 8192 8192 8192 8191 8191 8192 8191 8191 8191 8191 8191 8191 8192 8191 8191 8192 8191 8191 8192 8192 8191 8192 8192 8192 8192 8192 8192 8192 8191 8192 8192 8192 8191 8191 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8192 8192 8191 8192 8192 8192 8192 8191 8192 8191 8191 8192 8191 8192 8192 8191 8191",
"output": "2400"
}
] | 62 | 4,915,200 | 0 | 3,817 |
|
19 | Points | [
"data structures"
] | D. Points | 2 | 256 | Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types:
- add x y — on the sheet of paper Bob marks a point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is not yet marked on Bob's sheet at the time of the request. - remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is already marked on Bob's sheet at the time of the request. - find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (*x*,<=*y*). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete.
Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please! | The first input line contains number *n* (1<=≤<=*n*<=≤<=2·105) — amount of requests. Then there follow *n* lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109. | For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*,<=*y*). If there are no points strictly above and to the right of point (*x*,<=*y*), output -1. | [
"7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n",
"13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n"
] | [
"1 1\n3 4\n1 1\n",
"7 7\n-1\n5 5\n"
] | none | [] | 2,000 | 819,200 | 0 | 3,822 |
899 | Months and Years | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.
In this problem you are given *n* (1<=≤<=*n*<=≤<=24) integers *a*1,<=*a*2,<=...,<=*a**n*, and you have to check if these integers could be durations in days of *n* consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is *a*1 days, duration of the next month is *a*2 days, and so on. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.
In the fifth example the months are: December — January — February (non-leap year). | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31",
"output": "No"
},
{
"input": "4\n31 29 31 30",
"output": "Yes"
},
{
"input": "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "8\n31 29 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "1\n29",
"output": "Yes"
},
{
"input": "8\n31 29 31 30 31 31 31 31",
"output": "No"
},
{
"input": "1\n31",
"output": "Yes"
},
{
"input": "11\n30 31 30 31 31 30 31 30 31 31 28",
"output": "Yes"
},
{
"input": "21\n30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31",
"output": "Yes"
},
{
"input": "4\n31 28 28 30",
"output": "No"
},
{
"input": "2\n30 31",
"output": "Yes"
},
{
"input": "7\n28 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "4\n28 31 30 31",
"output": "Yes"
},
{
"input": "17\n28 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31",
"output": "No"
},
{
"input": "9\n31 31 29 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "4\n31 28 31 30",
"output": "Yes"
},
{
"input": "21\n30 31 30 31 31 28 31 30 31 30 31 29 30 31 30 31 31 28 31 30 31",
"output": "No"
},
{
"input": "2\n31 31",
"output": "Yes"
},
{
"input": "17\n31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "4\n30 31 30 31",
"output": "Yes"
},
{
"input": "12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "12\n31 29 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "11\n30 31 30 31 31 30 31 30 31 29 28",
"output": "No"
},
{
"input": "22\n31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "14\n31 30 31 31 28 31 30 31 30 31 31 30 31 30",
"output": "Yes"
},
{
"input": "12\n31 30 31 31 28 31 30 31 30 31 31 30",
"output": "Yes"
},
{
"input": "4\n31 29 29 30",
"output": "No"
},
{
"input": "7\n28 28 30 31 30 31 31",
"output": "No"
},
{
"input": "9\n29 31 29 31 30 31 30 31 31",
"output": "No"
},
{
"input": "17\n31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "2\n31 29",
"output": "Yes"
},
{
"input": "12\n31 28 31 30 31 30 31 31 30 31 28 31",
"output": "No"
},
{
"input": "2\n29 31",
"output": "Yes"
},
{
"input": "12\n31 29 31 30 31 30 31 30 30 31 30 31",
"output": "No"
},
{
"input": "12\n31 28 31 30 31 29 31 31 30 31 30 31",
"output": "No"
},
{
"input": "22\n31 30 31 30 31 31 30 31 30 31 31 28 31 30 28 30 31 31 30 31 30 31",
"output": "No"
},
{
"input": "14\n31 30 31 31 28 31 30 31 30 31 31 30 29 30",
"output": "No"
},
{
"input": "19\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31",
"output": "Yes"
},
{
"input": "20\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "1\n28",
"output": "Yes"
},
{
"input": "1\n29",
"output": "Yes"
},
{
"input": "17\n31 30 31 30 31 31 29 31 30 31 31 31 31 30 31 30 31",
"output": "No"
},
{
"input": "1\n30",
"output": "Yes"
},
{
"input": "1\n31",
"output": "Yes"
},
{
"input": "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31",
"output": "Yes"
},
{
"input": "24\n28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "12\n31 30 31 31 28 28 30 31 30 31 31 30",
"output": "No"
},
{
"input": "24\n29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "24\n28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31",
"output": "Yes"
},
{
"input": "24\n31 29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31",
"output": "No"
},
{
"input": "13\n28 31 30 31 30 31 31 30 31 30 31 31 28",
"output": "Yes"
},
{
"input": "15\n31 31 28 31 30 31 30 31 31 30 31 30 31 31 29",
"output": "Yes"
},
{
"input": "23\n31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31",
"output": "Yes"
},
{
"input": "24\n31 30 31 30 31 31 30 31 30 31 31 30 31 30 31 30 31 31 30 31 30 31 31 30",
"output": "No"
},
{
"input": "23\n29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31",
"output": "No"
},
{
"input": "15\n31 31 29 31 30 31 30 31 31 30 31 30 31 31 28",
"output": "Yes"
},
{
"input": "12\n31 30 31 30 31 30 31 31 30 31 30 31",
"output": "No"
}
] | 31 | 0 | 0 | 3,829 |
|
653 | Bear and Compressing | [
"brute force",
"dfs and similar",
"dp",
"strings"
] | null | null | Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.
You are given a set of *q* possible operations. Limak can perform them in any order, any operation may be applied any number of times. The *i*-th operation is described by a string *a**i* of length two and a string *b**i* of length one. No two of *q* possible operations have the same string *a**i*.
When Limak has a string *s* he can perform the *i*-th operation on *s* if the first two letters of *s* match a two-letter string *a**i*. Performing the *i*-th operation removes first two letters of *s* and inserts there a string *b**i*. See the notes section for further clarification.
You may note that performing an operation decreases the length of a string *s* exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any *a**i*.
Limak wants to start with a string of length *n* and perform *n*<=-<=1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows. | The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations.
The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guaranteed that *a**i*<=≠<=*a**j* for *i*<=≠<=*j* and that all *a**i* and *b**i* consist of only first six lowercase English letters. | Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input. | [
"3 5\nab a\ncc c\nca a\nee c\nff d\n",
"2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n",
"6 2\nbb a\nba a\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a".
Other three strings may be compressed as follows:
- "cab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "cca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "eea" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a"
In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a". | [
{
"input": "3 5\nab a\ncc c\nca a\nee c\nff d",
"output": "4"
},
{
"input": "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c",
"output": "1"
},
{
"input": "6 2\nbb a\nba a",
"output": "0"
},
{
"input": "2 5\nfe b\nbb a\naf b\nfd b\nbf c",
"output": "1"
},
{
"input": "3 4\neb b\nbd a\ncd d\nbb b",
"output": "2"
},
{
"input": "3 36\nab b\nbb a\naf c\nbd b\ncd a\nff c\nce a\nae a\ncb a\nba a\nad d\ndb a\nbf a\nbe a\ncc b\ndc a\nbc a\nca e\naa e\nec b\nac e\ned b\ndf d\nfa b\nea a\nef b\nee a\nda c\ncf a\nfe d\ndd f\nde a\neb f\nfd a\nfc a\nfb a",
"output": "86"
},
{
"input": "4 20\naf a\nad a\nac a\nbe a\nbc a\naa a\nab a\nbb a\neb a\nbd a\nbf a\ndc a\nea a\ncf a\ncd a\ncb a\nee a\nca a\nba a\nce a",
"output": "500"
},
{
"input": "6 4\nca a\nbe f\nad a\ncf a",
"output": "3"
},
{
"input": "2 15\nbc c\nbd a\nab b\nca a\ndf b\naa c\nae b\nac c\ncd a\nba e\nad d\nbb d\ned a\nfa a\nbf b",
"output": "5"
},
{
"input": "2 36\nad a\nae f\nac a\naa a\ncb b\nde e\nbe a\nea d\ncd b\nab a\nbf a\nba d\ncc c\ndc a\naf a\nca e\nda c\nbb c\nee b\nbd a\ned b\ndf b\nfd c\ndb d\nbc a\ncf d\nff d\ndd a\neb c\nce a\nfa c\nfe b\nec c\nef b\nfb a\nfc a",
"output": "14"
},
{
"input": "3 20\nca a\nbf d\nac a\nad b\neb a\naf a\nbe c\nbd a\ncb a\ncd c\nce b\nbc c\nbb a\ndd f\ndc e\ncf e\nfc e\naa d\nba c\nae d",
"output": "29"
},
{
"input": "4 35\nae f\nad d\naa a\neb d\nfb a\nce b\naf c\nfe c\nca a\nab a\nbd d\nbc a\nbe a\nbb f\nba c\ncb a\ncd a\nac c\ncc b\nbf b\ndb a\nfa a\ned b\nea a\nee d\nec a\ncf d\ndd a\nfc a\ndf a\nff a\ndc b\nef d\nde e\nda b",
"output": "529"
},
{
"input": "5 10\nba a\nbb c\nad a\nac c\nbc b\nfa b\nab b\nbe a\nbf a\naa b",
"output": "184"
},
{
"input": "5 20\nbd a\nac a\nad a\ncc a\naf a\nbe a\nbb a\ncb a\nca a\nab a\nbc a\nae a\ndb a\naa a\nbf a\nde a\nba a\ncf a\nda a\ned a",
"output": "4320"
},
{
"input": "5 20\naf f\nae f\naa f\nbd f\nfc f\ndd f\nba f\nac f\nbe f\neb f\nad f\ncb f\nce f\ncf f\nbc f\nca f\nde f\nab f\nbf f\ncc f",
"output": "0"
},
{
"input": "5 36\nac a\ncc c\nae f\nca a\nba a\nbe c\ndc e\nbc a\naa a\nad d\naf b\ncd c\ndf c\nbf b\nfb e\nef a\nbb b\nbd a\nce b\nab b\ndb c\nda b\ncf d\nfd c\nfa a\ncb c\nfe a\nea a\nfc e\ndd d\nde a\neb a\nec a\ned d\nee c\nff a",
"output": "2694"
},
{
"input": "6 1\nbf a",
"output": "0"
},
{
"input": "6 5\naa b\nad d\nba b\ndc d\nac a",
"output": "1"
},
{
"input": "6 15\nad b\ncb b\naf b\nae c\nbc e\nbd a\nac a\nda b\nab c\ncc d\nce f\ndc b\nca a\nba c\nbb a",
"output": "744"
},
{
"input": "6 15\naf a\nae a\nbc a\ncc a\nbe a\nff a\nab a\nbd a\nce a\nad a\ndb a\nee a\nba a\nda a\naa a",
"output": "9375"
},
{
"input": "6 15\nab b\nbd b\nae b\ncd b\nac b\nba b\ndc b\nbc b\nbb b\nbf b\nef b\naa b\ndd b\ncf b\nfc b",
"output": "0"
},
{
"input": "6 24\nab b\ncb b\naf a\nde c\ndb c\nad b\nca c\nbe c\nda e\nbb a\nbf a\nae a\nbc c\nba a\naa a\ncc f\ndc a\nac b\ncf c\ndd b\ndf a\ncd d\nbd d\neb b",
"output": "7993"
},
{
"input": "6 35\ndc c\nba b\nae e\nab a\naa b\nbb a\nbe b\ndb b\naf b\ncd b\nde b\ncf d\nac b\neb a\ndd a\nce b\nad c\ncc a\ncb c\nbc a\nbd b\ndf d\nea e\nfe c\nbf a\nfc a\nef d\nec b\nda c\ned b\nca a\nff a\nee b\nfb b\nfa e",
"output": "15434"
},
{
"input": "6 36\nbf f\nbb d\nff f\nac a\nad c\nbd e\ndd a\naa c\nab a\nba b\naf a\nda c\nce f\nea c\nde a\nca f\ndc f\nec b\ncc a\nae b\nbe b\nbc c\nee e\ncb b\nfb a\ncd d\ndb a\nef a\ncf d\neb c\ndf b\nfd a\ned a\nfe c\nfa b\nfc a",
"output": "15314"
},
{
"input": "6 1\naa a",
"output": "1"
},
{
"input": "6 1\nbb a",
"output": "0"
},
{
"input": "6 1\nba a",
"output": "0"
},
{
"input": "6 1\nab a",
"output": "1"
},
{
"input": "6 36\nac a\naf a\ndb a\nab a\ncb a\nef a\nad a\nbd a\nfe a\nde a\nbe a\nbb a\naa a\nae a\ndf a\nbc a\nbf a\nce a\nba a\nfd a\ndc a\neb a\ncd a\nca a\nee a\ncc a\ncf a\ndd a\nda a\nec a\nfc a\nfa a\nea a\ned a\nff a\nfb a",
"output": "46656"
},
{
"input": "6 36\naf f\nbd f\nba f\nbf f\nac f\nbe f\nbc f\nef f\naa f\neb f\nab f\nae f\nda f\ndc f\ncd f\nea f\ncb f\nad f\nbb f\ncc f\nce f\ndf f\nfa f\ncf f\ned f\nfe f\nfd f\nee f\ndb f\nde f\ndd f\nca f\nfb f\nec f\nff f\nfc f",
"output": "0"
},
{
"input": "6 36\naa a\nab f\nac a\nad b\nae c\naf d\nba f\nbb a\nbc b\nbd c\nbe d\nbf e\nca f\ncb a\ncc b\ncd c\nce d\ncf e\nda f\ndb a\ndc b\ndd c\nde d\ndf e\nea f\neb a\nec b\ned c\nee d\nef e\nfa f\nfb a\nfc b\nfd c\nfe d\nff e",
"output": "9331"
},
{
"input": "5 5\nab a\ncc c\nca a\nee c\nff d",
"output": "8"
}
] | 108 | 5,324,800 | 3 | 3,833 |
|
963 | Alternating Sum | [
"math",
"number theory"
] | null | null | You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative remainder of division of $\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$ by $10^{9} + 9$.
Note that the modulo is unusual! | The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$.
The second line contains a sequence of length $k$ consisting of characters '+' and '-'.
If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$.
Note that only the first $k$ members of the sequence are given, the rest can be obtained using the periodicity property. | Output a single integer — value of given expression modulo $10^{9} + 9$. | [
"2 2 3 3\n+-+\n",
"4 1 5 1\n-\n"
] | [
"7\n",
"999999228\n"
] | In the first example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7
In the second example:
$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$. | [
{
"input": "2 2 3 3\n+-+",
"output": "7"
},
{
"input": "4 1 5 1\n-",
"output": "999999228"
},
{
"input": "1 1 4 2\n-+",
"output": "3"
},
{
"input": "3 1 4 4\n+--+",
"output": "45"
},
{
"input": "5 1 1 6\n++---+",
"output": "0"
},
{
"input": "5 2 2 6\n+--++-",
"output": "0"
},
{
"input": "686653196 115381398 884618610 3\n+-+",
"output": "542231211"
},
{
"input": "608663287 430477711 172252358 8\n-+--+-+-",
"output": "594681696"
},
{
"input": "904132655 827386249 118827660 334\n+++-+++++--+++----+-+-+-+-+--+-+---++--++--++--+-+-+++-+++--+-+-+----+-+-++++-----+--++++------+++-+-+-++-++++++++-+-++-+++--+--++------+--+-+++--++--+---++-++-+-+-++---++-++--+-+-++-+------+-+----+++-+++--+-+-+--+--+--+------+--+---+--+-++--+++---+-+-++--------+-++--++-+-+-+-+-+-+--+-++++-+++--+--++----+--+-++-++--+--+-+-++-+-++++-",
"output": "188208979"
},
{
"input": "234179195 430477711 115381398 12\n++++-+-+-+++",
"output": "549793323"
},
{
"input": "75952547 967294208 907708706 252\n++--++--+++-+-+--++--++++++---+++-++-+-----++++--++-+-++------+-+-+-++-+-+-++++------++---+-++++---+-+-++++--++++++--+-+++-++--+--+---++++---+-+++-+++--+-+--+++++---+--++-++++--++++-+-++-+++-++-----+-+++++----++--+++-+-+++++-+--++-++-+--+-++++--+-+-+-+",
"output": "605712499"
},
{
"input": "74709071 801809249 753674746 18\n++++++-+-+---+-+--",
"output": "13414893"
},
{
"input": "743329 973758 92942 82\n++----+-++++----+--+++---+--++++-+-+---+++++--+--+++++++--++-+++----+--+++++-+--+-",
"output": "299311566"
},
{
"input": "18111 291387 518587 2\n++",
"output": "724471355"
},
{
"input": "996144 218286 837447 1\n-",
"output": "549104837"
},
{
"input": "179358 828426 548710 67\n++++---+--++----+-+-++++----+--+---+------++-+-++++--+----+---+-+--",
"output": "759716474"
},
{
"input": "397521 174985 279760 1\n+",
"output": "25679493"
},
{
"input": "613632 812232 482342 1\n-",
"output": "891965141"
},
{
"input": "936810 183454 647048 1\n+",
"output": "523548992"
},
{
"input": "231531 250371 921383 28\n++-+------+--+--++++--+-+++-",
"output": "134450934"
},
{
"input": "947301 87242 360762 97\n--+++--+++-++--++-++--++--+++---+++--++++--+++++--+-++-++-----+-++-+--++-----+-++-+--++-++-+-----",
"output": "405016159"
},
{
"input": "425583346 814209084 570987274 1\n+",
"output": "63271171"
},
{
"input": "354062556 688076879 786825319 1\n+",
"output": "545304776"
},
{
"input": "206671954 13571766 192250278 1\n+",
"output": "717117421"
},
{
"input": "23047921 621656196 160244047 1\n-",
"output": "101533009"
},
{
"input": "806038018 740585177 987616107 293\n-+++++--++++---++-+--+-+---+-++++--+--+++--++---++++++++--+++++-+-++-+--+----+--+++-+-++-+++-+-+-+----------++-+-+++++++-+-+-+-++---+++-+-+-------+-+-++--++-++-++-++-+---+--++-++--+++--+++-+-+----++--+-+-++-+---+---+-+-+++------+-+++-+---++-+--+++----+++++---++-++--+----+++-+--+++-+------+-++",
"output": "441468166"
},
{
"input": "262060935 184120408 148332034 148\n+--+-------+-+-+--++-+++--++-+-++++++--++-+++-+++--+-------+-+--+++-+-+-+---++-++-+-++---+--+-+-+--+------+++--+--+-+-+---+---+-+-++++---+++--+++---",
"output": "700325386"
},
{
"input": "919350941 654611542 217223605 186\n++-++-+++++-+++--+---+++++++-++-+----+-++--+-++--++--+++-+++---+--+--++-+-+++-+-+++-++---+--+++-+-+++--+-+-------+-++------++---+-+---++-++-++---+-+--+-+--+++++---+--+--++++-++-++--+--++",
"output": "116291420"
},
{
"input": "289455627 906207104 512692624 154\n-------++--+++---++-++------++----------+--+++-+-+++---+---+++--++++++--+-+-+--+---+-+-++-++--+-++--++++---+-+---+-----+--+-+---------+++-++---++-+-+-----",
"output": "48198216"
},
{
"input": "258833760 515657142 791267045 1\n-",
"output": "935800888"
},
{
"input": "691617927 66917103 843055237 8\n--+++---",
"output": "147768186"
},
{
"input": "379582849 362892355 986900829 50\n++-++---+-+++++--++++--+--++--++-----+------++--+-",
"output": "927469713"
},
{
"input": "176799169 363368399 841293419 1\n+",
"output": "746494802"
},
{
"input": "144808247 203038656 166324035 4\n-+-+",
"output": "909066471"
},
{
"input": "477607531 177367565 20080950 2\n++",
"output": "928662830"
},
{
"input": "682074525 289438443 917164266 1\n+",
"output": "28048785"
},
{
"input": "938449224 59852396 219719125 1\n-",
"output": "648647459"
},
{
"input": "395171426 872478622 193568600 147\n+---++---+-+--+++++--+---+-++++-+-++---++++--+--+-+-++-+-++--------++---+++-+---++---+---+-+--+-++++-+++-+-+-++-+--+++-++-+-+-+-++++++-+---+---++--",
"output": "460881399"
},
{
"input": "403493428 317461491 556701240 1\n-",
"output": "936516261"
},
{
"input": "917751169 330191895 532837377 70\n-+-+++++++--++---++-+++++-+++-----+-+++---+--+-+-++-++-+-+-++-++-+----",
"output": "908035409"
},
{
"input": "252089413 552678586 938424519 1\n-",
"output": "627032736"
},
{
"input": "649316142 320010793 200197645 1\n-",
"output": "323650777"
},
{
"input": "116399299 784781190 299072480 5\n++++-",
"output": "754650814"
}
] | 0 | 0 | -1 | 3,837 |
|
550 | Two Substrings | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 46 | 0 | 0 | 3,840 |
|
333 | Secrets | [
"greedy"
] | null | null | Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.
One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?
The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of *n* marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least *n* marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want. | The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017).
Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.
In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives. | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "3"
},
{
"input": "10",
"output": "4"
},
{
"input": "100000000000000000",
"output": "33333333333333334"
},
{
"input": "99999999999999999",
"output": "3703703703703704"
},
{
"input": "50031545098999707",
"output": "1"
},
{
"input": "16677181699666569",
"output": "1"
},
{
"input": "72900000000000",
"output": "33333333334"
},
{
"input": "99999999999999997",
"output": "33333333333333333"
},
{
"input": "58061299250691018",
"output": "32"
},
{
"input": "49664023559436051",
"output": "128191526"
},
{
"input": "66708726798666276",
"output": "2"
},
{
"input": "29442431889534807",
"output": "48"
},
{
"input": "70414767176369958",
"output": "13"
},
{
"input": "93886356235159944",
"output": "51"
},
{
"input": "97626528902553453",
"output": "551104613133"
},
{
"input": "52013157885656046",
"output": "880847395988"
},
{
"input": "37586570003500923",
"output": "548"
},
{
"input": "34391854792828422",
"output": "582429080812"
},
{
"input": "205891132094649",
"output": "1"
},
{
"input": "243",
"output": "1"
},
{
"input": "5559060566555523",
"output": "1"
},
{
"input": "81",
"output": "1"
},
{
"input": "108",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "1129718145924",
"output": "2"
}
] | 184 | 0 | 3 | 3,842 |
|
22 | System Administrator | [
"graphs"
] | C. System Administrator | 1 | 256 | Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index *v* fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers. | The first input line contains 3 space-separated integer numbers *n*, *m*, *v* (3<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105,<=1<=≤<=*v*<=≤<=*n*), *n* — amount of servers, *m* — amount of direct connections, *v* — index of the server that fails and leads to the failure of the whole system. | If it is impossible to connect the servers in the required way, output -1. Otherwise output *m* lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any. | [
"5 6 3\n",
"6 100 1\n"
] | [
"1 2\n2 3\n3 4\n4 5\n1 3\n3 5\n",
"-1\n"
] | none | [
{
"input": "5 6 3",
"output": "1 3\n2 3\n4 3\n5 3\n1 2\n1 4"
},
{
"input": "6 100 1",
"output": "-1"
},
{
"input": "10 26 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8"
},
{
"input": "20 155 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n5 19\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16..."
},
{
"input": "30 393 29",
"output": "1 29\n2 29\n3 29\n4 29\n5 29\n6 29\n7 29\n8 29\n9 29\n10 29\n11 29\n12 29\n13 29\n14 29\n15 29\n16 29\n17 29\n18 29\n19 29\n20 29\n21 29\n22 29\n23 29\n24 29\n25 29\n26 29\n27 29\n28 29\n30 29\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n3 4\n3 5\n3 6\n..."
},
{
"input": "50 535 8",
"output": "1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n16 8\n17 8\n18 8\n19 8\n20 8\n21 8\n22 8\n23 8\n24 8\n25 8\n26 8\n27 8\n28 8\n29 8\n30 8\n31 8\n32 8\n33 8\n34 8\n35 8\n36 8\n37 8\n38 8\n39 8\n40 8\n41 8\n42 8\n43 8\n44 8\n45 8\n46 8\n47 8\n48 8\n49 8\n50 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41..."
},
{
"input": "100 4283 65",
"output": "1 65\n2 65\n3 65\n4 65\n5 65\n6 65\n7 65\n8 65\n9 65\n10 65\n11 65\n12 65\n13 65\n14 65\n15 65\n16 65\n17 65\n18 65\n19 65\n20 65\n21 65\n22 65\n23 65\n24 65\n25 65\n26 65\n27 65\n28 65\n29 65\n30 65\n31 65\n32 65\n33 65\n34 65\n35 65\n36 65\n37 65\n38 65\n39 65\n40 65\n41 65\n42 65\n43 65\n44 65\n45 65\n46 65\n47 65\n48 65\n49 65\n50 65\n51 65\n52 65\n53 65\n54 65\n55 65\n56 65\n57 65\n58 65\n59 65\n60 65\n61 65\n62 65\n63 65\n64 65\n66 65\n67 65\n68 65\n69 65\n70 65\n71 65\n72 65\n73 65\n74 65\n75 65\n76..."
},
{
"input": "1000 51277 488",
"output": "1 488\n2 488\n3 488\n4 488\n5 488\n6 488\n7 488\n8 488\n9 488\n10 488\n11 488\n12 488\n13 488\n14 488\n15 488\n16 488\n17 488\n18 488\n19 488\n20 488\n21 488\n22 488\n23 488\n24 488\n25 488\n26 488\n27 488\n28 488\n29 488\n30 488\n31 488\n32 488\n33 488\n34 488\n35 488\n36 488\n37 488\n38 488\n39 488\n40 488\n41 488\n42 488\n43 488\n44 488\n45 488\n46 488\n47 488\n48 488\n49 488\n50 488\n51 488\n52 488\n53 488\n54 488\n55 488\n56 488\n57 488\n58 488\n59 488\n60 488\n61 488\n62 488\n63 488\n64 488\n65 488\n..."
},
{
"input": "10000 57971 8854",
"output": "1 8854\n2 8854\n3 8854\n4 8854\n5 8854\n6 8854\n7 8854\n8 8854\n9 8854\n10 8854\n11 8854\n12 8854\n13 8854\n14 8854\n15 8854\n16 8854\n17 8854\n18 8854\n19 8854\n20 8854\n21 8854\n22 8854\n23 8854\n24 8854\n25 8854\n26 8854\n27 8854\n28 8854\n29 8854\n30 8854\n31 8854\n32 8854\n33 8854\n34 8854\n35 8854\n36 8854\n37 8854\n38 8854\n39 8854\n40 8854\n41 8854\n42 8854\n43 8854\n44 8854\n45 8854\n46 8854\n47 8854\n48 8854\n49 8854\n50 8854\n51 8854\n52 8854\n53 8854\n54 8854\n55 8854\n56 8854\n57 8854\n58 8854..."
},
{
"input": "100000 99999 41895",
"output": "1 41895\n2 41895\n3 41895\n4 41895\n5 41895\n6 41895\n7 41895\n8 41895\n9 41895\n10 41895\n11 41895\n12 41895\n13 41895\n14 41895\n15 41895\n16 41895\n17 41895\n18 41895\n19 41895\n20 41895\n21 41895\n22 41895\n23 41895\n24 41895\n25 41895\n26 41895\n27 41895\n28 41895\n29 41895\n30 41895\n31 41895\n32 41895\n33 41895\n34 41895\n35 41895\n36 41895\n37 41895\n38 41895\n39 41895\n40 41895\n41 41895\n42 41895\n43 41895\n44 41895\n45 41895\n46 41895\n47 41895\n48 41895\n49 41895\n50 41895\n51 41895\n52 41895\n..."
},
{
"input": "99999 100000 66180",
"output": "1 66180\n2 66180\n3 66180\n4 66180\n5 66180\n6 66180\n7 66180\n8 66180\n9 66180\n10 66180\n11 66180\n12 66180\n13 66180\n14 66180\n15 66180\n16 66180\n17 66180\n18 66180\n19 66180\n20 66180\n21 66180\n22 66180\n23 66180\n24 66180\n25 66180\n26 66180\n27 66180\n28 66180\n29 66180\n30 66180\n31 66180\n32 66180\n33 66180\n34 66180\n35 66180\n36 66180\n37 66180\n38 66180\n39 66180\n40 66180\n41 66180\n42 66180\n43 66180\n44 66180\n45 66180\n46 66180\n47 66180\n48 66180\n49 66180\n50 66180\n51 66180\n52 66180\n..."
},
{
"input": "99997 99997 72727",
"output": "1 72727\n2 72727\n3 72727\n4 72727\n5 72727\n6 72727\n7 72727\n8 72727\n9 72727\n10 72727\n11 72727\n12 72727\n13 72727\n14 72727\n15 72727\n16 72727\n17 72727\n18 72727\n19 72727\n20 72727\n21 72727\n22 72727\n23 72727\n24 72727\n25 72727\n26 72727\n27 72727\n28 72727\n29 72727\n30 72727\n31 72727\n32 72727\n33 72727\n34 72727\n35 72727\n36 72727\n37 72727\n38 72727\n39 72727\n40 72727\n41 72727\n42 72727\n43 72727\n44 72727\n45 72727\n46 72727\n47 72727\n48 72727\n49 72727\n50 72727\n51 72727\n52 72727\n..."
},
{
"input": "100000 100000 100000",
"output": "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ..."
},
{
"input": "100000 100000 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 99999 100000",
"output": "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ..."
},
{
"input": "100000 99999 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "100000 99998 100000",
"output": "-1"
},
{
"input": "100000 99998 1",
"output": "-1"
},
{
"input": "100000 0 100000",
"output": "-1"
},
{
"input": "100000 0 1",
"output": "-1"
},
{
"input": "10000 100000 10000",
"output": "1 10000\n2 10000\n3 10000\n4 10000\n5 10000\n6 10000\n7 10000\n8 10000\n9 10000\n10 10000\n11 10000\n12 10000\n13 10000\n14 10000\n15 10000\n16 10000\n17 10000\n18 10000\n19 10000\n20 10000\n21 10000\n22 10000\n23 10000\n24 10000\n25 10000\n26 10000\n27 10000\n28 10000\n29 10000\n30 10000\n31 10000\n32 10000\n33 10000\n34 10000\n35 10000\n36 10000\n37 10000\n38 10000\n39 10000\n40 10000\n41 10000\n42 10000\n43 10000\n44 10000\n45 10000\n46 10000\n47 10000\n48 10000\n49 10000\n50 10000\n51 10000\n52 10000\n..."
},
{
"input": "10000 100000 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "123 13527 42",
"output": "-1"
},
{
"input": "100 96943 65",
"output": "-1"
},
{
"input": "10 39377 1",
"output": "-1"
},
{
"input": "200 34305 75",
"output": "-1"
},
{
"input": "300 44552 1",
"output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..."
},
{
"input": "300 44552 300",
"output": "1 300\n2 300\n3 300\n4 300\n5 300\n6 300\n7 300\n8 300\n9 300\n10 300\n11 300\n12 300\n13 300\n14 300\n15 300\n16 300\n17 300\n18 300\n19 300\n20 300\n21 300\n22 300\n23 300\n24 300\n25 300\n26 300\n27 300\n28 300\n29 300\n30 300\n31 300\n32 300\n33 300\n34 300\n35 300\n36 300\n37 300\n38 300\n39 300\n40 300\n41 300\n42 300\n43 300\n44 300\n45 300\n46 300\n47 300\n48 300\n49 300\n50 300\n51 300\n52 300\n53 300\n54 300\n55 300\n56 300\n57 300\n58 300\n59 300\n60 300\n61 300\n62 300\n63 300\n64 300\n65 300\n..."
},
{
"input": "300 44553 1",
"output": "-1"
},
{
"input": "300 44553 300",
"output": "-1"
}
] | 109 | 0 | 0 | 3,843 |
180 | Defragmentation | [
"implementation"
] | null | null | In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to *n*. The disk has *m* recorded files, the *i*-th file occupies clusters with numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i*. These clusters are not necessarily located consecutively on the disk, but the order in which they are given corresponds to their sequence in the file (cluster *a**i*,<=1 contains the first fragment of the *i*-th file, cluster *a**i*,<=2 has the second fragment, etc.). Also the disc must have one or several clusters which are free from files.
You are permitted to perform operations of copying the contents of cluster number *i* to cluster number *j* (*i* and *j* must be different). Moreover, if the cluster number *j* used to keep some information, it is lost forever. Clusters are not cleaned, but after the defragmentation is complete, some of them are simply declared unusable (although they may possibly still contain some fragments of files).
Your task is to use a sequence of copy operations to ensure that each file occupies a contiguous area of memory. Each file should occupy a consecutive cluster section, the files must follow one after another from the beginning of the hard disk. After defragmentation all free (unused) clusters should be at the end of the hard disk. After defragmenting files can be placed in an arbitrary order. Clusters of each file should go consecutively from first to last. See explanatory examples in the notes.
Print the sequence of operations leading to the disk defragmentation. Note that you do not have to minimize the number of operations, but it should not exceed 2*n*. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200) — the number of clusters and the number of files, correspondingly. Next *m* lines contain descriptions of the files. The first number in the line is *n**i* (*n**i*<=≥<=1), the number of clusters occupied by the *i*-th file. Then follow *n**i* numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i* (1<=≤<=*a**i*,<=*j*<=≤<=*n*). It is guaranteed that each cluster number occurs not more than once and , that is, there exists at least one unused cluster. Numbers on each line are separated by spaces. | In the first line print a single integer *k* (0<=≤<=*k*<=≤<=2*n*) — the number of operations needed to defragment the disk. Next *k* lines should contain the operations' descriptions as "*i* *j*" (copy the contents of the cluster number *i* to the cluster number *j*). | [
"7 2\n2 1 2\n3 3 4 5\n",
"7 2\n2 1 3\n3 2 4 5\n"
] | [
"0\n",
"3\n2 6\n3 2\n6 3\n"
] | Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.
Example 2: each file must occupy a contiguous area of memory.
Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.
Example 4: violating the order of file fragments to each other is not allowed.
Example 5: unused clusters should be located at the end, and in this example the unused clusters are 3, 7, 8. | [
{
"input": "7 2\n2 1 2\n3 3 4 5",
"output": "0"
},
{
"input": "7 2\n2 1 3\n3 2 4 5",
"output": "3\n2 6\n3 2\n6 3"
},
{
"input": "2 1\n1 2",
"output": "1\n2 1"
},
{
"input": "3 1\n2 3 1",
"output": "2\n1 2\n3 1"
},
{
"input": "3 2\n1 3\n1 2",
"output": "1\n3 1"
},
{
"input": "5 3\n1 2\n1 4\n1 5",
"output": "3\n2 1\n4 2\n5 3"
},
{
"input": "7 3\n1 7\n2 6 5\n3 4 3 2",
"output": "7\n7 1\n2 7\n6 2\n3 6\n5 3\n6 5\n7 6"
},
{
"input": "7 2\n3 1 3 5\n3 2 4 6",
"output": "5\n2 7\n3 2\n5 3\n4 5\n7 4"
},
{
"input": "10 1\n5 7 4 6 9 2",
"output": "7\n7 1\n2 3\n4 2\n3 4\n6 3\n4 5\n9 4"
},
{
"input": "7 2\n2 2 1\n3 3 4 5",
"output": "3\n1 6\n2 1\n6 2"
},
{
"input": "7 2\n2 1 2\n3 4 5 6",
"output": "3\n4 3\n5 4\n6 5"
},
{
"input": "20 5\n7 12 16 14 17 20 4 15\n2 7 8\n1 5\n5 3 6 18 11 2\n4 9 13 19 1",
"output": "36\n1 10\n12 1\n2 12\n16 2\n3 16\n14 3\n4 14\n17 4\n5 17\n20 5\n6 20\n14 6\n7 14\n15 7\n8 15\n14 8\n9 14\n15 9\n10 15\n17 10\n11 17\n16 11\n12 16\n20 12\n13 20\n18 13\n14 18\n17 14\n15 17\n16 15\n18 16\n17 18\n20 17\n18 20\n19 18\n20 19"
},
{
"input": "20 10\n1 2\n2 14 11\n2 9 15\n2 16 8\n2 3 13\n3 17 12 6\n1 5\n1 7\n2 20 19\n1 1",
"output": "25\n1 4\n2 1\n14 2\n3 10\n11 3\n4 11\n9 4\n5 9\n15 5\n6 14\n16 6\n7 15\n8 7\n10 8\n9 10\n13 9\n10 13\n17 10\n11 16\n12 11\n14 12\n15 14\n20 15\n16 17\n19 16"
},
{
"input": "100 30\n8 62 50 93 34 82 24 87 65\n2 64 86\n3 91 42 88\n2 76 7\n2 35 63\n3 78 84 15\n4 90 46 73 9\n4 74 13 95 58\n3 71 59 55\n2 4 31\n1 19\n1 10\n2 45 23\n2 27 69\n4 12 66 44 22\n1 36\n2 67 2\n2 77 54\n4 96 47 25 52\n5 18 29 43 70 56\n2 14 41\n2 100 6\n3 30 94 75\n2 32 28\n1 53\n9 26 39 51 68 33 99 79 89 49\n4 5 17 81 37\n3 57 8 16\n3 21 72 98\n4 83 48 40 61",
"output": "168\n62 1\n2 3\n50 2\n3 11\n93 3\n4 20\n34 4\n5 34\n82 5\n6 38\n24 6\n7 24\n87 7\n8 50\n65 8\n9 60\n64 9\n10 62\n86 10\n11 64\n91 11\n12 65\n42 12\n13 42\n88 13\n14 80\n76 14\n15 76\n24 15\n16 24\n35 16\n17 35\n63 17\n18 63\n78 18\n19 78\n84 19\n20 82\n76 20\n21 76\n90 21\n22 84\n46 22\n23 46\n73 23\n24 73\n60 24\n25 60\n74 25\n26 74\n42 26\n27 42\n95 27\n28 85\n58 28\n29 58\n71 29\n30 71\n59 30\n31 59\n55 31\n32 55\n82 32\n33 82\n59 33\n34 59\n78 34\n35 78\n62 35\n36 62\n45 36\n37 45\n46 37\n38 46\n42 38\n..."
},
{
"input": "200 10\n17 110 31 67 40 144 57 90 186 25 112 3 14 79 193 159 26 165\n4 91 1 30 62\n11 64 94 60 49 176 172 54 106 68 51 22\n4 131 114 2 15\n33 58 83 164 190 5 21 17 19 181 46 7 140 29 82 147 6 28 192 27 39 196 101 10 53 156 23 98 48 195 88 126 170 55\n2 81 4\n10 177 16 32 78 119 69 171 127 117 133\n14 184 34 145 43 9 134 168 97 63 191 102 50 72 120\n2 45 99\n3 169 163 104",
"output": "177\n1 8\n110 1\n2 11\n31 2\n3 12\n67 3\n4 13\n40 4\n5 18\n144 5\n6 20\n57 6\n7 24\n90 7\n8 31\n186 8\n9 33\n25 9\n10 25\n112 10\n11 35\n12 11\n14 12\n13 14\n79 13\n14 36\n193 14\n15 37\n159 15\n16 38\n26 16\n17 26\n165 17\n18 40\n91 18\n19 41\n31 19\n20 31\n30 20\n21 30\n62 21\n22 42\n64 22\n23 44\n94 23\n24 47\n60 24\n25 52\n49 25\n26 49\n176 26\n27 56\n172 27\n28 57\n54 28\n29 54\n106 29\n30 59\n68 30\n31 60\n51 31\n32 51\n42 32\n33 42\n131 33\n34 61\n114 34\n36 62\n37 36\n58 37\n38 58\n83 38\n39 64\n16..."
}
] | 248 | 512,000 | 3 | 3,845 |
|
952 | 2 + 2 != 4 | [] | null | null | One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... | The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. | Reproduce the output of the reference solution, including the bug. | [
"8-7+6-5+4-3+2-1-0\n",
"2+2\n",
"112-37\n"
] | [
"4\n",
"-46\n",
"375\n"
] | none | [
{
"input": "8-7+6-5+4-3+2-1-0",
"output": "4"
},
{
"input": "2+2",
"output": "-46"
},
{
"input": "112-37",
"output": "375"
},
{
"input": "255+255+255+255+255+255+255+255+255+255",
"output": "-42450"
},
{
"input": "0-255-255-255-255-255-255-255-255-255",
"output": "24705"
},
{
"input": "0+0+0+0+0+0+0+0+0+0",
"output": "-450"
},
{
"input": "0-0-0-0-0-0-0-0-0-0",
"output": "270"
},
{
"input": "0+100+100+100+100+100+100+100+100+100",
"output": "-44100"
},
{
"input": "255-100-100-100-100-100-100-100-100-100",
"output": "26355"
},
{
"input": "45+5",
"output": "0"
},
{
"input": "23+6-9",
"output": "0"
},
{
"input": "123+234-56-78-90",
"output": "-3967"
},
{
"input": "97+67+12+9+42+45+13",
"output": "-2265"
},
{
"input": "9-109-22+23-87+27-40+10",
"output": "2211"
},
{
"input": "66-165-34+209+76",
"output": "-2048"
},
{
"input": "150+222-3-90-248-187+198",
"output": "-3628"
},
{
"input": "136+90-200+6-102",
"output": "5380"
},
{
"input": "255-12-34-56-69-78-90",
"output": "1716"
},
{
"input": "243-173+90-56+78-53+53-21",
"output": "2561"
},
{
"input": "131+49+249+71-251-61+159-111+51",
"output": "-4913"
},
{
"input": "5-9-1-3+6+4-7+8-2",
"output": "1"
},
{
"input": "101+200+195+231+107+222+146+254+160+209",
"output": "-43175"
},
{
"input": "240-120-234-156-207-189",
"output": "14334"
},
{
"input": "1-2+3-4+5-6",
"output": "-13"
},
{
"input": "9-8+7-6+5-4+3-2+1-0",
"output": "-45"
}
] | 0 | 0 | -1 | 3,846 |
|
25 | Roads in Berland | [
"graphs",
"shortest paths"
] | C. Roads in Berland | 2 | 256 | There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance between them. Berland Government plans to build *k* new roads. For each of the planned road it is known its length, and what cities it will connect. To control the correctness of the construction of new roads, after the opening of another road Berland government wants to check the sum of the shortest distances between all pairs of cities. Help them — for a given matrix of shortest distances on the old roads and plans of all new roads, find out how the sum of the shortest distances between all pairs of cities changes after construction of each road. | The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0,<=*d**i*,<=*j*<==<=*d**j*,<=*i*, and a given matrix is a matrix of shortest distances for some set of two-way roads with integer lengths from 1 to 1000, such that from each city it is possible to get to any other city using these roads.
Next line contains integer *k* (1<=≤<=*k*<=≤<=300) — amount of planned roads. Following *k* lines contain the description of the planned roads. Each road is described by three space-separated integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=1000) — *a**i* and *b**i* — pair of cities, which the road connects, *c**i* — the length of the road. It can be several roads between a pair of cities, but no road connects the city with itself. | Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactly once, i. e. we count unordered pairs. | [
"2\n0 5\n5 0\n1\n1 2 3\n",
"3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n"
] | [
"3 ",
"17 12 "
] | none | [
{
"input": "2\n0 5\n5 0\n1\n1 2 3",
"output": "3 "
},
{
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1",
"output": "17 12 "
},
{
"input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763",
"output": "1480 1480 1480 "
},
{
"input": "4\n0 537 1064 656\n537 0 527 119\n1064 527 0 408\n656 119 408 0\n4\n1 4 123\n1 4 344\n3 2 982\n3 2 587",
"output": "1950 1950 1950 1950 "
},
{
"input": "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n266 688 989 0 485\n751 1173 504 485 0\n5\n5 2 837\n3 4 692\n3 5 756\n3 1 151\n2 5 262",
"output": "8070 7476 7476 6062 5111 "
}
] | 2,000 | 12,185,600 | 0 | 3,847 |
715 | Create a Maze | [
"constructive algorithms"
] | null | null | ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of *n*<=×<=*m* rooms, and the rooms are arranged in *n* rows (numbered from the top to the bottom starting from 1) and *m* columns (numbered from the left to the right starting from 1). The room in the *i*-th row and *j*-th column is denoted by (*i*,<=*j*). A player starts in the room (1,<=1) and wants to reach the room (*n*,<=*m*).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (*i*,<=*j*) and (*i*,<=*j*<=+<=1) is locked, then we can't go from (*i*,<=*j*) to (*i*,<=*j*<=+<=1). Also, one can only travel between the rooms downwards (from the room (*i*,<=*j*) to the room (*i*<=+<=1,<=*j*)) or rightwards (from the room (*i*,<=*j*) to the room (*i*,<=*j*<=+<=1)) provided the corresponding door is not locked.
ZS the Coder considers a maze to have difficulty *x* if there is exactly *x* ways of travelling from the room (1,<=1) to the room (*n*,<=*m*). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to *T*. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right? | The first and only line of the input contains a single integer *T* (1<=≤<=*T*<=≤<=1018), the difficulty of the required maze. | The first line should contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the maze respectively.
The next line should contain a single integer *k* (0<=≤<=*k*<=≤<=300) — the number of locked doors in the maze.
Then, *k* lines describing locked doors should follow. Each of them should contain four integers, *x*1,<=*y*1,<=*x*2,<=*y*2. This means that the door connecting room (*x*1,<=*y*1) and room (*x*2,<=*y*2) is locked. Note that room (*x*2,<=*y*2) should be adjacent either to the right or to the bottom of (*x*1,<=*y*1), i.e. *x*2<=+<=*y*2 should be equal to *x*1<=+<=*y*1<=+<=1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them. | [
"3\n",
"4\n"
] | [
"3 2\n0\n",
"4 3\n3\n1 2 2 2\n3 2 3 3\n1 3 2 3"
] | Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
In the second sample case: | [
{
"input": "3",
"output": "4 4\n5\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n4 1 4 2"
},
{
"input": "4",
"output": "4 4\n4\n1 2 2 2\n1 3 2 3\n2 1 2 2\n4 1 4 2"
},
{
"input": "576460752303423488",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..."
},
{
"input": "576460752303423487",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..."
},
{
"input": "99999988898898889",
"output": "46 46\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "989466010702279111",
"output": "50 50\n251\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 1..."
},
{
"input": "1000000000000000000",
"output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..."
},
{
"input": "1",
"output": "4 4\n5\n1 2 2 2\n1 3 2 3\n2 1 2 2\n3 1 3 2\n4 1 4 2"
},
{
"input": "2",
"output": "4 4\n4\n1 2 2 2\n1 3 2 3\n2 1 2 2\n3 1 3 2"
},
{
"input": "201620162016201600",
"output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "138944482508455329",
"output": "48 48\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11..."
},
{
"input": "327543848458922240",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12..."
},
{
"input": "516143210114421854",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..."
},
{
"input": "481370539210112956",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 ..."
},
{
"input": "639733286738742273",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12 11..."
},
{
"input": "604960615834433375",
"output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n1..."
},
{
"input": "793559981784900286",
"output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n..."
},
{
"input": "982159343440399900",
"output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "170758705095899514",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "513930638418673772",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 ..."
},
{
"input": "702530000074173386",
"output": "48 48\n242\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "891129366024640296",
"output": "50 50\n247\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12..."
},
{
"input": "79728727680139911",
"output": "46 46\n224\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9..."
},
{
"input": "268328089335639525",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 ..."
},
{
"input": "297819469440675531",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n1..."
},
{
"input": "486418831096175146",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..."
},
{
"input": "675018197046642056",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..."
},
{
"input": "863617562997108966",
"output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 1..."
},
{
"input": "632172093115904261",
"output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12..."
},
{
"input": "395388853680415542",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n1..."
},
{
"input": "583988219630882453",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13..."
},
{
"input": "772587581286382067",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 ..."
},
{
"input": "737814910382073169",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13..."
},
{
"input": "926414272037572783",
"output": "50 50\n251\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 ..."
},
{
"input": "179277684702417302",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..."
},
{
"input": "367877050652884212",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 ..."
},
{
"input": "333104375453608019",
"output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..."
},
{
"input": "325030946722146418",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12..."
},
{
"input": "513630312672613328",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14..."
},
{
"input": "53475036382348801",
"output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 ..."
},
{
"input": "242074398037848415",
"output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..."
},
{
"input": "430673763988315325",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n..."
},
{
"input": "619273125643814940",
"output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 ..."
},
{
"input": "807872491594281850",
"output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12..."
},
{
"input": "837363867404350560",
"output": "50 50\n254\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 ..."
},
{
"input": "25963229059850175",
"output": "46 46\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 1..."
},
{
"input": "281442720373954210",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..."
},
{
"input": "983117125129112380",
"output": "50 50\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10..."
},
{
"input": "171716491079579290",
"output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..."
},
{
"input": "934933251644090571",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "123532617594557481",
"output": "46 46\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 1..."
},
{
"input": "312131979250057096",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10..."
},
{
"input": "500731345200524006",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 ..."
},
{
"input": "465958670001247812",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12..."
},
{
"input": "718822086961059627",
"output": "48 48\n226\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 ..."
},
{
"input": "487376621374822218",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12..."
},
{
"input": "675975978735354536",
"output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 1..."
},
{
"input": "864575344685821446",
"output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 1..."
},
{
"input": "53174706341321061",
"output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "880549474766385254",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "69148836421884868",
"output": "46 46\n219\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..."
},
{
"input": "257748198077384482",
"output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14..."
},
{
"input": "446347564027851393",
"output": "48 48\n241\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "634946925683351007",
"output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n1..."
},
{
"input": "467765511106458502",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n1..."
},
{
"input": "656364872761958116",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n..."
},
{
"input": "621592201857649219",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 ..."
},
{
"input": "810191567808116129",
"output": "50 50\n247\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 1..."
},
{
"input": "998790929463615743",
"output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..."
},
{
"input": "762007690028127024",
"output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 9 12 10\n12 ..."
},
{
"input": "950607055978593934",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 1..."
},
{
"input": "139206417634093549",
"output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..."
},
{
"input": "104433742434817355",
"output": "46 46\n220\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10..."
},
{
"input": "96360313703355754",
"output": "46 46\n215\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..."
},
{
"input": "125851689513424465",
"output": "46 46\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12..."
},
{
"input": "314451055463891375",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 ..."
},
{
"input": "503050417119390989",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 1..."
},
{
"input": "691649783069857899",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..."
},
{
"input": "880249149020324810",
"output": "50 50\n255\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "420093872730060283",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 ..."
},
{
"input": "608693234385559897",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..."
},
{
"input": "797292600336026807",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n..."
},
{
"input": "789219171604565206",
"output": "48 48\n229\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n12 14..."
},
{
"input": "754446496405289013",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 ..."
},
{
"input": "7309909070133531",
"output": "44 44\n210\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 1..."
},
{
"input": "195909270725633145",
"output": "48 48\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8..."
},
{
"input": "384508636676100056",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..."
},
{
"input": "349735961476823862",
"output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10..."
},
{
"input": "538335327427290772",
"output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..."
},
{
"input": "301552087991802053",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..."
},
{
"input": "490151453942268963",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "258705984061064258",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10..."
},
{
"input": "447305350011531169",
"output": "48 48\n230\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9..."
},
{
"input": "635904715961998079",
"output": "48 48\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n..."
},
{
"input": "665396091772066789",
"output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..."
},
{
"input": "853995453427566404",
"output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n1..."
},
{
"input": "42594815083066018",
"output": "46 46\n216\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 ..."
},
{
"input": "231194181033532928",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..."
},
{
"input": "419793542689032543",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..."
},
{
"input": "183010307548511120",
"output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "977109881915691245",
"output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "165709243571190859",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 1..."
},
{
"input": "354308605226690473",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 ..."
},
{
"input": "542907971177157383",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..."
},
{
"input": "572399346987226094",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "760998712937693004",
"output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10..."
},
{
"input": "949598074593192619",
"output": "50 50\n249\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..."
},
{
"input": "138197440543659529",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..."
},
{
"input": "326796802199159143",
"output": "48 48\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 ..."
},
{
"input": "446665360611696202",
"output": "48 48\n239\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..."
},
{
"input": "635264726562163113",
"output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 9 12 10\n1..."
},
{
"input": "823864088217662727",
"output": "50 50\n250\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..."
},
{
"input": "789091417313353829",
"output": "48 48\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 15\n12 16 13 16\n12 1..."
},
{
"input": "977690778968853444",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "230554191633697962",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..."
},
{
"input": "419153557584164872",
"output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "384380882384888679",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..."
},
{
"input": "572980248335355589",
"output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "761579609990855203",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 1..."
},
{
"input": "104751543313629461",
"output": "46 46\n213\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 ..."
},
{
"input": "293350904969129075",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "481950270919595985",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 1..."
},
{
"input": "670549632575095600",
"output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n..."
},
{
"input": "859148998525562510",
"output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 1..."
},
{
"input": "888640378630598516",
"output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 1..."
},
{
"input": "77239735991130835",
"output": "46 46\n226\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13..."
},
{
"input": "265839101941597745",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..."
},
{
"input": "454438463597097359",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9..."
},
{
"input": "222992998010859950",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..."
},
{
"input": "986209758575371231",
"output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..."
},
{
"input": "174809124525838142",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 1..."
},
{
"input": "363408486181337756",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 1..."
},
{
"input": "552007852131804666",
"output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..."
},
{
"input": "517235176932528472",
"output": "48 48\n226\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..."
},
{
"input": "770098593892340287",
"output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 ..."
},
{
"input": "958697959842807197",
"output": "50 50\n245\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..."
},
{
"input": "147297317203339516",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..."
},
{
"input": "915851851617102107",
"output": "50 50\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "104451213272601721",
"output": "46 46\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 1..."
},
{
"input": "867667978132080298",
"output": "50 50\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..."
},
{
"input": "832895302932804104",
"output": "50 50\n245\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9..."
},
{
"input": "21494668883271014",
"output": "44 44\n214\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n1..."
},
{
"input": "210094030538770629",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9..."
},
{
"input": "398693396489237539",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10..."
},
{
"input": "428184772299306249",
"output": "48 48\n236\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..."
},
{
"input": "616784138249773160",
"output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..."
},
{
"input": "608710709518311559",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 ..."
},
{
"input": "797310071173811173",
"output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n..."
},
{
"input": "762537395974534979",
"output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12..."
},
{
"input": "525754160834013556",
"output": "48 48\n227\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n..."
},
{
"input": "789730223053602816",
"output": "50 50\n279\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n..."
},
{
"input": "789730223053602815",
"output": "48 48\n199\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 15\n12 16 13 16\n12 17 13 17\n13..."
},
{
"input": "947676267664323379",
"output": "50 50\n256\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..."
},
{
"input": "315892089221441126",
"output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 ..."
},
{
"input": "473838133832161689",
"output": "48 48\n245\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..."
},
{
"input": "631784178442882252",
"output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 1..."
},
{
"input": "999999999999999999",
"output": "50 50\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..."
},
{
"input": "12345678987654321",
"output": "44 44\n219\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..."
},
{
"input": "100055128505716009",
"output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..."
},
{
"input": "981168724994134051",
"output": "50 50\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..."
},
{
"input": "213025900602118694",
"output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n1..."
},
{
"input": "163428781826190151",
"output": "48 48\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..."
},
{
"input": "149046408559208370",
"output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n1..."
},
{
"input": "718882536615471983",
"output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12..."
}
] | 93 | 2,457,600 | 3 | 3,848 |
|
294 | Shaass and Bookshelf | [
"dp",
"greedy"
] | null | null | Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights.
Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure.
Help Shaass to find the minimum total thickness of the vertical books that we can achieve. | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains two integers *t**i* and *w**i* denoting the thickness and width of the *i*-th book correspondingly, (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*w**i*<=≤<=100). | On the only line of the output print the minimum total thickness of the vertical books that we can achieve. | [
"5\n1 12\n1 3\n2 15\n2 5\n2 1\n",
"3\n1 10\n2 1\n2 4\n"
] | [
"5\n",
"3\n"
] | none | [
{
"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1",
"output": "5"
},
{
"input": "3\n1 10\n2 1\n2 4",
"output": "3"
},
{
"input": "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5",
"output": "12"
},
{
"input": "1\n2 7",
"output": "2"
},
{
"input": "50\n1 24\n1 16\n1 33\n2 34\n1 26\n2 35\n1 39\n2 44\n2 29\n2 28\n1 44\n2 48\n2 50\n2 41\n2 9\n1 22\n2 11\n2 27\n1 12\n1 50\n2 49\n1 17\n2 43\n2 6\n1 39\n2 28\n1 47\n1 45\n2 32\n1 43\n2 40\n1 10\n1 44\n2 31\n2 26\n2 15\n2 20\n1 49\n1 36\n2 43\n2 8\n1 46\n2 43\n2 26\n1 30\n1 23\n2 26\n1 32\n2 25\n2 42",
"output": "67"
},
{
"input": "20\n2 4\n1 2\n2 2\n1 2\n2 1\n1 3\n2 5\n1 3\n1 1\n2 3\n1 4\n2 3\n1 5\n1 4\n1 4\n1 2\n2 5\n1 5\n2 2\n2 2",
"output": "16"
},
{
"input": "30\n1 48\n1 3\n2 20\n2 41\n1 33\n2 46\n2 22\n2 21\n1 6\n2 44\n1 23\n2 28\n1 39\n1 19\n2 15\n2 49\n1 26\n1 22\n2 42\n2 27\n2 31\n1 49\n1 11\n1 33\n1 1\n2 31\n2 9\n1 18\n2 27\n1 18",
"output": "38"
},
{
"input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29",
"output": "53"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "1\n1 2",
"output": "1"
},
{
"input": "2\n1 2\n2 2",
"output": "2"
},
{
"input": "100\n2 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n2 1\n1 1\n1 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n1 1\n1 1\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n1 2\n1 1\n2 1\n2 1\n2 2\n1 2\n2 1\n1 1\n2 1\n1 2\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 1\n1 2\n2 1\n1 1\n1 1\n2 2\n2 2\n1 1\n2 1\n1 2\n2 2\n2 1\n1 2\n1 2\n1 2\n1 1\n2 1",
"output": "60"
},
{
"input": "100\n2 2\n1 2\n1 5\n1 5\n1 2\n1 4\n2 3\n1 2\n1 5\n2 1\n2 2\n2 4\n1 2\n2 3\n1 1\n1 1\n2 5\n2 3\n2 2\n1 2\n2 1\n2 2\n1 5\n2 1\n2 4\n1 4\n1 4\n2 2\n1 1\n2 4\n1 4\n2 4\n1 2\n2 3\n2 3\n1 5\n1 5\n2 3\n1 4\n1 5\n2 2\n1 3\n2 2\n2 2\n1 1\n2 1\n2 5\n1 1\n2 3\n2 5\n1 5\n1 3\n1 5\n2 4\n1 5\n2 3\n2 5\n1 4\n2 3\n2 2\n2 5\n2 4\n1 1\n1 1\n1 3\n2 3\n2 1\n2 1\n1 2\n1 1\n2 5\n2 2\n2 1\n2 3\n2 2\n1 5\n1 2\n1 2\n1 1\n1 2\n1 4\n1 5\n1 4\n1 3\n1 1\n1 2\n2 2\n2 4\n1 2\n1 1\n2 3\n2 3\n2 5\n2 1\n1 5\n1 5\n1 4\n2 2\n1 4\n2 4",
"output": "76"
},
{
"input": "50\n1 69\n2 39\n1 32\n2 35\n1 25\n2 24\n1 59\n2 99\n2 48\n2 54\n1 87\n1 81\n2 42\n2 8\n2 92\n1 78\n2 70\n2 91\n1 86\n1 87\n2 15\n1 93\n1 82\n2 36\n1 12\n1 56\n2 84\n1 98\n1 89\n2 79\n1 22\n1 65\n1 40\n2 13\n2 95\n2 93\n1 9\n2 99\n2 100\n1 76\n2 56\n1 10\n1 2\n2 93\n2 21\n2 33\n1 21\n1 81\n2 10\n2 93",
"output": "66"
},
{
"input": "10\n1 61\n1 92\n2 97\n1 70\n2 37\n2 44\n2 29\n1 94\n2 65\n1 48",
"output": "15"
},
{
"input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29",
"output": "53"
},
{
"input": "2\n1 100\n1 100",
"output": "2"
},
{
"input": "3\n2 5\n2 5\n2 5",
"output": "6"
}
] | 93 | 10,956,800 | 0 | 3,858 |
|
896 | Nephren gives a riddle | [
"binary search",
"dfs and similar"
] | null | null |
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, *f*0... ∞.
*f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1.
For example, *f*1 is
"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1.
It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces.
Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes).
Can you answer her queries? | The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions.
Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). | One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. | [
"3\n1 1\n1 2\n1 111111111111\n",
"5\n0 69\n1 194\n1 139\n0 47\n1 66\n",
"10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n"
] | [
"Wh.",
"abdef",
"Areyoubusy"
] | For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend. | [
{
"input": "3\n1 1\n1 2\n1 111111111111",
"output": "Wh."
},
{
"input": "5\n0 69\n1 194\n1 139\n0 47\n1 66",
"output": "abdef"
},
{
"input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474",
"output": "Areyoubusy"
},
{
"input": "1\n0 1",
"output": "W"
},
{
"input": "1\n999 1000000000000000000",
"output": "?"
},
{
"input": "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4",
"output": "ee WWah at"
},
{
"input": "10\n5 235941360876088213\n10 65160787148797531\n0 531970131175601601\n2 938108094014908387\n3 340499457696664259\n5 56614532774539063\n5 719524142056884004\n10 370927072502555372\n2 555965798821270052\n10 492559401050725258",
"output": ".........."
},
{
"input": "10\n72939 670999605706502447\n67498 428341803949410086\n62539 938370976591475035\n58889 657471364021290792\n11809 145226347556228466\n77111 294430864855433173\n29099 912050147755964704\n27793 196249143894732547\n118 154392540400153863\n62843 63234003203996349",
"output": "?usaglrnyh"
},
{
"input": "10\n74 752400948436334811\n22 75900251524550494\n48 106700456127359025\n20 623493261724933249\n90 642991963097110817\n42 47750435275360941\n24 297055789449373682\n65 514620361483452045\n99 833434466044716497\n0 928523848526511085",
"output": "h... .. d."
},
{
"input": "10\n26302 2898997\n2168 31686909\n56241 27404733\n9550 44513376\n70116 90169838\n14419 95334944\n61553 16593205\n85883 42147334\n55209 74676056\n57866 68603505",
"output": "donts ly o"
},
{
"input": "9\n50 161003686678495163\n50 161003686678495164\n50 161003686678495165\n51 322007373356990395\n51 322007373356990396\n51 322007373356990397\n52 644014746713980859\n52 644014746713980860\n52 644014746713980861",
"output": "\"?.\"?.\"?."
},
{
"input": "10\n100000 1000000000000000000\n99999 999999999999998683\n99998 999999999999997366\n99997 999999999999996049\n99996 999999999999994732\n99995 999999999999993415\n99994 999999999999992098\n99993 999999999999990781\n99992 999999999999989464\n99991 999999999999988147",
"output": "o u lugW? "
},
{
"input": "10\n94455 839022536766957828\n98640 878267599238035211\n90388 54356607570140506\n93536 261222577013066170\n91362 421089574363407592\n95907 561235487589345620\n91888 938806156011561508\n90820 141726323964466814\n97856 461989202234320135\n92518 602709074380260370",
"output": "youni iiee"
},
{
"input": "10\n100000 873326525630182716\n100000 620513733919162415\n100000 482953375281256917\n100000 485328193417229962\n100000 353549227094721271\n100000 367447590857326107\n100000 627193846053528323\n100000 243833127760837417\n100000 287297493528203749\n100000 70867563577617188",
"output": "o W rlot"
},
{
"input": "10\n1 1\n1 34\n1 35\n1 109\n1 110\n1 141\n1 142\n1 216\n1 217\n1 218",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n5 1\n5 34\n5 35\n5 2254\n5 2255\n5 2286\n5 2287\n5 4506\n5 4507\n5 4508",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n10 1\n10 34\n10 35\n10 73182\n10 73183\n10 73214\n10 73215\n10 146362\n10 146363\n10 146364",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n15 1\n15 34\n15 35\n15 2342878\n15 2342879\n15 2342910\n15 2342911\n15 4685754\n15 4685755\n15 4685756",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n35 1\n35 34\n35 35\n35 2456721293278\n35 2456721293279\n35 2456721293310\n35 2456721293311\n35 4913442586554\n35 4913442586555\n35 4913442586556",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n47 1\n47 34\n47 35\n47 10062730417405918\n47 10062730417405919\n47 10062730417405950\n47 10062730417405951\n47 20125460834811834\n47 20125460834811835\n47 20125460834811836",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n50 1\n50 34\n50 35\n50 80501843339247582\n50 80501843339247583\n50 80501843339247614\n50 80501843339247615\n50 161003686678495162\n50 161003686678495163\n50 161003686678495164",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n52 1\n52 34\n52 35\n52 322007373356990430\n52 322007373356990431\n52 322007373356990462\n52 322007373356990463\n52 644014746713980858\n52 644014746713980859\n52 644014746713980860",
"output": "W\"W?\"\"W?\"?"
},
{
"input": "10\n54986 859285936548585889\n49540 198101079999865795\n96121 658386311981208488\n27027 787731514451843966\n60674 736617460878411577\n57761 569094390437687993\n93877 230086639196124716\n75612 765187050118682698\n75690 960915623784157529\n1788 121643460920471434",
"output": "oru A\" de\""
},
{
"input": "10\n13599 295514896417102030\n70868 206213281730527977\n99964 675362501525687265\n8545 202563221795027954\n62885 775051601455683055\n44196 552672589494215033\n38017 996305706075726957\n82157 778541544539864990\n13148 755735956771594947\n66133 739544460375378867",
"output": "t?W y wnr"
},
{
"input": "10\n23519 731743847695683578\n67849 214325487756157455\n39048 468966654215390234\n30476 617394929138211942\n40748 813485737737987237\n30632 759622821110550585\n30851 539152740395520686\n23942 567423516617312907\n93605 75958684925842506\n24977 610678262374451619",
"output": "WonreeuhAn"
},
{
"input": "10\n66613 890998077399614704\n59059 389024292752123693\n10265 813853582068134597\n71434 128404685079108014\n76180 582880920044162144\n1123 411409570241705915\n9032 611954441092300071\n78951 57503725302368508\n32102 824738435154619172\n44951 53991552354407935",
"output": "i oio u? "
},
{
"input": "10\n96988 938722606709261427\n97034 794402579184858837\n96440 476737696947281053\n96913 651380108479508367\n99570 535723325634376015\n97425 180427887538234591\n97817 142113098762476646\n96432 446510004868669235\n98788 476529766139390976\n96231 263034481360542586",
"output": "eunWwdtnA "
},
{
"input": "10\n99440 374951566577777567\n98662 802514785210488315\n97117 493713886491759829\n97252 66211820117659651\n98298 574157457621712902\n99067 164006086594761631\n99577 684960128787303079\n96999 12019940091341344\n97772 796752494293638534\n96958 134168283359615339",
"output": "idrd? o nl"
},
{
"input": "10\n95365 811180517856359115\n97710 810626986941150496\n98426 510690080331205902\n99117 481043523165876343\n95501 612591593904017084\n96340 370956318211097183\n96335 451179199961872617\n95409 800901907873821965\n97650 893603181298142989\n96159 781930052798879580",
"output": "oisv\"sb ta"
},
{
"input": "10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 642382931526919655\n96374 448615375338644407",
"output": " e\"atdW? e"
},
{
"input": "10\n5 929947814902665291\n0 270929202623248779\n10 917958578362357217\n3 674632947904782968\n7 19875145653630834\n8 744882317760093379\n4 471398991908637021\n7 253934163977433229\n7 125334789085610404\n10 841267552326270425",
"output": ".........."
},
{
"input": "10\n3 366176770476214135\n10 55669371794102449\n1 934934767906835993\n0 384681214954881520\n4 684989729845321867\n8 231000356557573162\n1 336780423782602481\n2 300230185318227609\n7 23423148068105278\n1 733131408103947638",
"output": ".........."
},
{
"input": "10\n6 25777762904538788\n1 63781573524764630\n5 951910961746282066\n9 280924325736375136\n6 96743418218239198\n1 712038707283212867\n4 780465093108032992\n4 608326071277553255\n8 542408204244362417\n3 360163123764607419",
"output": ".........."
},
{
"input": "10\n1 185031988313502617\n8 461852423965441269\n2 296797889599026429\n3 15306118532047016\n6 866138600524414105\n10 587197493269144005\n2 853266793804812376\n2 98406279962608857\n3 291187954473139083\n0 26848446304372246",
"output": ".........."
},
{
"input": "10\n27314 39\n71465 12\n29327 53\n33250 85\n52608 41\n19454 55\n72760 12\n83873 90\n67859 78\n91505 73",
"output": " u nrhuiy "
},
{
"input": "10\n76311 57\n79978 83\n34607 89\n62441 98\n28700 35\n54426 67\n66596 15\n30889 21\n68793 7\n29916 71",
"output": "lohiW ohra"
}
] | 31 | 102,400 | -1 | 3,859 |
|
626 | Simple Skewness | [
"binary search",
"math",
"ternary search"
] | null | null | Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of *n* (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.
The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200 000) — the number of elements in the list.
The second line contains *n* integers *x**i* (0<=≤<=*x**i*<=≤<=1<=000<=000) — the *i*th element of the list. | In the first line, print a single integer *k* — the size of the subset.
In the second line, print *k* integers — the elements of the subset in any order.
If there are multiple optimal subsets, print any. | [
"4\n1 2 3 12\n",
"4\n1 1 2 2\n",
"2\n1 2\n"
] | [
"3\n1 2 12 \n",
"3\n1 1 2 \n",
"2\n1 2\n"
] | In the first case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/04cdbd07a0375de9c557422eca077386392a9349.png" style="max-width: 100.0%;max-height: 100.0%;"/>, which has mean 5, median 2, and simple skewness of 5 - 2 = 3.
In the second case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/af49670de7c27def20edf0ec421d9bb17d904c94.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that repetition is allowed.
In the last case, any subset has the same median and mean, so all have simple skewness of 0. | [
{
"input": "4\n1 2 3 12",
"output": "3\n1 2 12 "
},
{
"input": "4\n1 1 2 2",
"output": "3\n1 1 2 "
},
{
"input": "2\n1 2",
"output": "2\n1 2"
},
{
"input": "1\n1000000",
"output": "1\n1000000 "
},
{
"input": "20\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712",
"output": "1\n475712 "
},
{
"input": "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712 1000000",
"output": "1\n475712 "
},
{
"input": "40\n999999 999999 999998 999998 999996 999996 999992 999992 999984 999984 999968 999968 999936 999936 999872 999872 999744 999744 999488 999488 998976 998976 997952 997952 995904 995904 991808 991808 983616 983616 967232 967232 934464 934464 868928 868928 737856 737856 475712 0",
"output": "3\n737856 737856 999999 "
},
{
"input": "1\n534166",
"output": "1\n534166 "
},
{
"input": "1\n412237",
"output": "1\n412237 "
},
{
"input": "1\n253309",
"output": "1\n253309 "
},
{
"input": "1\n94381",
"output": "1\n94381 "
},
{
"input": "1\n935454",
"output": "1\n935454 "
},
{
"input": "2\n847420 569122",
"output": "2\n847420 569122"
},
{
"input": "2\n725491 635622",
"output": "2\n725491 635622"
},
{
"input": "2\n566563 590441",
"output": "2\n566563 590441"
},
{
"input": "2\n407635 619942",
"output": "2\n407635 619942"
},
{
"input": "2\n248707 649443",
"output": "2\n248707 649443"
},
{
"input": "3\n198356 154895 894059",
"output": "3\n154895 198356 894059 "
},
{
"input": "3\n76427 184396 963319",
"output": "3\n76427 184396 963319 "
},
{
"input": "3\n880502 176898 958582",
"output": "1\n176898 "
},
{
"input": "3\n758573 206400 991528",
"output": "1\n206400 "
},
{
"input": "3\n599645 198217 986791",
"output": "1\n198217 "
},
{
"input": "4\n549294 703669 96824 126683",
"output": "3\n96824 126683 703669 "
},
{
"input": "4\n390366 733171 92086 595244",
"output": "3\n92086 390366 733171 "
},
{
"input": "4\n231438 762672 125033 26806",
"output": "3\n26806 125033 762672 "
},
{
"input": "4\n109509 792173 120296 495368",
"output": "3\n109509 120296 792173 "
},
{
"input": "4\n950582 784676 190241 964614",
"output": "1\n190241 "
},
{
"input": "5\n900232 289442 225592 622868 113587",
"output": "3\n113587 225592 900232 "
},
{
"input": "5\n741304 281944 258539 54430 284591",
"output": "3\n281944 284591 741304 "
},
{
"input": "5\n582376 311446 253801 560676 530279",
"output": "3\n253801 311446 582376 "
},
{
"input": "5\n460447 303948 286063 992238 738282",
"output": "3\n286063 303948 992238 "
},
{
"input": "5\n301519 370449 319010 460799 983970",
"output": "3\n301519 319010 983970 "
},
{
"input": "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712 999998",
"output": "3\n999998 999998 999999 "
}
] | 30 | 0 | -1 | 3,874 |
|
10 | LCIS | [
"dp"
] | D. LCIS | 1 | 256 | This problem differs from one which was on the online contest.
The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=<<=*a**i*<=+<=1 for *i*<=<<=*n*.
The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of indexes 1<=≤<=*i*1<=<<=*i*2<=<<=...<=<<=*i**k*<=≤<=*n* that *a**i**j*<==<=*s**j*. In other words, the sequence *s* can be derived from the sequence *a* by crossing out some elements.
You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line contains *m* space-separated integers from the range [0,<=109] — elements of the second sequence. | In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | [
"7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n",
"5\n1 2 0 2 1\n3\n1 0 1\n"
] | [
"3\n3 5 6 \n",
"2\n0 1 \n"
] | none | [
{
"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6",
"output": "3\n3 5 6 "
},
{
"input": "5\n1 2 0 2 1\n3\n1 0 1",
"output": "2\n0 1 "
},
{
"input": "2\n6 10\n3\n6 3 3",
"output": "1\n6 "
},
{
"input": "1\n7\n2\n7 9",
"output": "1\n7 "
},
{
"input": "3\n37 49 24\n3\n33 5 70",
"output": "0"
},
{
"input": "10\n7 10 1 2 1 7 1 5 9 9\n9\n6 2 5 6 7 7 5 5 2",
"output": "2\n2 7 "
},
{
"input": "9\n7 0 1 2 6 0 10 3 5\n4\n8 4 0 3",
"output": "2\n0 3 "
},
{
"input": "9\n7 4 4 5 0 6 5 4 10\n4\n5 2 10 9",
"output": "2\n5 10 "
},
{
"input": "8\n7 8 6 6 8 10 3 3\n5\n7 4 10 8 7",
"output": "2\n7 8 "
},
{
"input": "7\n4 2 4 3 10 3 6\n9\n7 5 2 3 0 1 6 1 4",
"output": "3\n2 3 6 "
},
{
"input": "1\n7\n10\n1 8 8 10 9 10 4 6 0 5",
"output": "0"
},
{
"input": "2\n5 2\n4\n8 8 0 4",
"output": "0"
},
{
"input": "3\n1 3 9\n10\n8 0 10 5 7 0 3 1 2 4",
"output": "1\n1 "
},
{
"input": "15\n10 4 7 7 10 1 4 9 1 10 9 6 8 8 2\n2\n0 4",
"output": "1\n4 "
},
{
"input": "16\n8 8 6 7 10 0 10 1 7 6 6 0 4 2 6 7\n12\n9 3 8 4 10 3 9 8 3 7 10 4",
"output": "2\n8 10 "
},
{
"input": "23\n174 172 196 135 91 174 208 92 132 53 202 118 5 244 161 140 71 21 185 56 60 195 217\n17\n38 218 120 77 22 214 164 194 79 195 36 167 42 89 201 80 11",
"output": "1\n195 "
},
{
"input": "53\n135 168 160 123 6 250 251 158 245 184 206 35 189 64 138 12 69 21 112 198 165 211 109 40 192 98 236 216 255 98 136 38 67 79 25 196 216 64 134 124 102 232 229 102 179 138 111 123 2 93 25 162 57\n57\n64 143 41 144 73 26 11 17 224 209 167 162 129 39 102 224 254 45 120 2 138 213 139 133 169 54 7 143 242 118 155 189 100 185 145 168 248 131 83 216 142 180 225 35 226 202 8 15 200 192 75 140 191 189 75 116 202",
"output": "3\n64 138 192 "
},
{
"input": "83\n95 164 123 111 177 71 38 225 103 59 210 209 117 139 115 140 66 21 39 84 14 227 0 43 90 233 96 98 232 237 108 139 55 220 14 225 134 39 68 167 193 125 86 216 87 14 94 75 255 24 165 98 177 191 239 123 98 90 29 52 155 231 187 90 180 1 31 237 167 145 242 115 61 190 47 41 61 206 191 248 126 196 26\n49\n234 134 9 207 37 95 116 239 105 197 191 15 151 249 156 235 17 161 197 199 87 78 191 188 44 151 179 238 72 29 228 157 174 99 190 114 95 185 160 168 58 216 131 151 233 204 213 87 76",
"output": "2\n95 233 "
},
{
"input": "13\n55 160 86 99 92 148 81 36 216 191 214 127 44\n85\n92 12 64 21 221 225 119 243 147 47 244 112 212 237 209 121 81 239 43 104 3 254 52 13 1 210 28 18 199 75 251 146 77 28 253 211 50 35 42 160 157 104 155 37 241 78 42 190 150 228 193 96 190 178 232 65 231 186 1 123 212 126 239 22 214 186 245 249 66 234 57 78 173 229 185 23 240 91 127 177 240 105 77 208 86",
"output": "2\n160 214 "
},
{
"input": "94\n100 161 99 102 209 51 5 188 217 53 121 5 233 55 25 156 136 195 243 157 110 202 136 151 86 171 253 38 126 40 27 76 60 119 222 52 134 104 184 146 133 220 88 108 246 61 215 184 181 134 223 164 41 193 232 217 38 192 226 91 81 99 204 232 178 4 187 61 160 255 121 142 191 114 114 181 226 49 86 55 252 169 59 190 246 93 21 22 17 18 120 88 93 144\n30\n61 51 176 38 119 33 100 185 103 84 161 166 103 227 43 200 127 53 52 89 19 215 76 254 110 30 239 247 11 182",
"output": "3\n51 53 110 "
},
{
"input": "6\n3 5 4 6 8 1\n10\n3 3 0 5 4 0 10 5 6 8",
"output": "4\n3 5 6 8 "
},
{
"input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "8\n2 3 4 5 6 8 9 5\n9\n2 2 3 4 5 6 6 8 9",
"output": "7\n2 3 4 5 6 8 9 "
},
{
"input": "8\n0 4 10 6 7 2 8 5\n7\n0 4 6 7 7 0 8",
"output": "5\n0 4 6 7 8 "
},
{
"input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "17\n12 17 39 156 100 177 188 129 14 142 45 144 243 151 158 194 245\n16\n125 12 17 199 65 39 100 185 129 194 142 144 62 92 158 194",
"output": "9\n12 17 39 100 129 142 144 158 194 "
},
{
"input": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207\n20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207",
"output": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207 "
},
{
"input": "13\n0 46 104 116 63 118 158 16 221 222 136 245 223\n9\n0 46 104 116 118 158 221 222 245",
"output": "9\n0 46 104 116 118 158 221 222 245 "
},
{
"input": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235\n15\n34 38 51 57 73 125 147 158 160 178 255 67 188 198 235",
"output": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235 "
},
{
"input": "17\n25 29 37 207 122 189 118 42 54 95 154 160 162 225 228 237 248\n19\n25 29 248 37 147 209 42 54 255 95 154 160 162 225 228 237 73 248 10",
"output": "13\n25 29 37 42 54 95 154 160 162 225 228 237 248 "
},
{
"input": "10\n62914292 123971042 784965687 324817892 379711365 394545872 813282270 822333477 865397146 437913515\n9\n297835672 62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146",
"output": "8\n62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146 "
},
{
"input": "10\n130077811 57466561 335978192 71385678 434259735 454136111 482887469 530031703 688581885 809880630\n8\n373627898 57466561 71385678 434259735 454136111 482887469 530031703 809880630",
"output": "7\n57466561 71385678 434259735 454136111 482887469 530031703 809880630 "
},
{
"input": "17\n364396044 90653796 82853043 311258337 326557522 362475139 415783272 428510002 840021181 469284863 541444887 650535473 649258258 750028895 791368777 808443140 959785237\n13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237",
"output": "13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237 "
},
{
"input": "3\n6379263 55134355 76061584\n3\n6379263 55134355 76061584",
"output": "3\n6379263 55134355 76061584 "
},
{
"input": "3\n48875076 71023491 76538219\n3\n48875076 71023491 76538219",
"output": "3\n48875076 71023491 76538219 "
},
{
"input": "5\n6621317 78540394 52064998 89150480 53659440\n3\n78540394 46008538 839195",
"output": "1\n78540394 "
},
{
"input": "2\n34665180 51128665\n5\n71074966 34665180 47089728 44119345 51128665",
"output": "2\n34665180 51128665 "
},
{
"input": "4\n3 4 9 1\n7\n5 3 8 9 10 2 1",
"output": "2\n3 9 "
}
] | 77 | 204,800 | 0 | 3,880 |
569 | Music | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start. | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12326 6163 2",
"output": "1"
},
{
"input": "10000 2500 4",
"output": "1"
},
{
"input": "100000 99999 4",
"output": "1"
},
{
"input": "12351 1223 6",
"output": "2"
},
{
"input": "100000 1 10000",
"output": "2"
},
{
"input": "10028 13 10000",
"output": "1"
},
{
"input": "100000 99999 2",
"output": "1"
},
{
"input": "100000 99999 3",
"output": "1"
},
{
"input": "100000 1 2",
"output": "17"
},
{
"input": "100000 1 3",
"output": "11"
},
{
"input": "100000 1 4",
"output": "9"
},
{
"input": "100000 1 5",
"output": "8"
},
{
"input": "100000 3125 2",
"output": "5"
},
{
"input": "12628 1804 7",
"output": "1"
},
{
"input": "100000 45 13",
"output": "4"
},
{
"input": "100000 500 3",
"output": "5"
},
{
"input": "356 2 3",
"output": "5"
},
{
"input": "50 2 2",
"output": "5"
},
{
"input": "65465 12 3",
"output": "8"
},
{
"input": "10033 3 8",
"output": "4"
},
{
"input": "100000 3 2",
"output": "16"
},
{
"input": "64 1 8",
"output": "2"
},
{
"input": "10000 9 2",
"output": "11"
},
{
"input": "25 2 2",
"output": "4"
},
{
"input": "129 2 2",
"output": "7"
},
{
"input": "6562 1 3",
"output": "9"
},
{
"input": "100000 1 10",
"output": "5"
}
] | 46 | 0 | 0 | 3,885 |
|
39 | Company Income Growth | [
"greedy"
] | B. Company Income Growth | 2 | 64 | Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. | Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. | [
"10\n-2 1 1 3 2 3 4 -10 -2 5\n",
"3\n-1 -2 -3\n"
] | [
"5\n2002 2005 2006 2007 2010\n",
"0\n"
] | none | [
{
"input": "10\n-2 1 1 3 2 3 4 -10 -2 5",
"output": "5\n2002 2005 2006 2007 2010 "
},
{
"input": "3\n-1 -2 -3",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1\n2002 "
},
{
"input": "2\n-1 1",
"output": "1\n2002 "
},
{
"input": "2\n-2 0",
"output": "0"
},
{
"input": "2\n3 -3",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "1\n2001 "
},
{
"input": "3\n-2 -2 1",
"output": "1\n2003 "
},
{
"input": "4\n-4 2 3 -1",
"output": "0"
},
{
"input": "5\n-3 -3 -4 2 -2",
"output": "0"
},
{
"input": "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9",
"output": "5\n2020 2036 2044 2077 2083 "
},
{
"input": "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6",
"output": "6\n2021 2042 2060 2062 2068 2089 "
},
{
"input": "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3",
"output": "6\n2006 2048 2053 2057 2064 2083 "
},
{
"input": "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2",
"output": "7\n2005 2047 2052 2067 2075 2083 2089 "
},
{
"input": "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5",
"output": "0"
},
{
"input": "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4",
"output": "4\n2032 2047 2062 2076 "
},
{
"input": "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31",
"output": "0"
},
{
"input": "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87",
"output": "0"
},
{
"input": "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58",
"output": "0"
},
{
"input": "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30",
"output": "1\n2051 "
},
{
"input": "1\n1",
"output": "1\n2001 "
},
{
"input": "2\n1 2",
"output": "2\n2001 2002 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 "
},
{
"input": "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99",
"output": "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 "
},
{
"input": "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50",
"output": "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 "
},
{
"input": "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50",
"output": "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 "
},
{
"input": "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86",
"output": "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 "
},
{
"input": "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21",
"output": "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 "
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10\n2 3 1 3 3 2 1 2 1 2",
"output": "2\n2003 2006 "
},
{
"input": "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1",
"output": "4\n2002 2006 2009 2011 "
},
{
"input": "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4",
"output": "2\n2007 2010 "
},
{
"input": "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4",
"output": "2\n2006 2008 "
}
] | 156 | 7,065,600 | 3.908357 | 3,889 |
337 | Book of Evil | [
"dfs and similar",
"divide and conquer",
"dp",
"trees"
] | null | null | Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains *n* settlements numbered from 1 to *n*. Moving through the swamp is very difficult, so people tramped exactly *n*<=-<=1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to reach any settlement from any other one by traversing one or several paths.
The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range *d*. This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance *d* or less from the settlement where the Book resides.
Manao has heard of *m* settlements affected by the Book of Evil. Their numbers are *p*1,<=*p*2,<=...,<=*p**m*. Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task. | The first line contains three space-separated integers *n*, *m* and *d* (1<=≤<=*m*<=≤<=*n*<=≤<=100000; 0<=≤<=*d*<=≤<=*n*<=-<=1). The second line contains *m* distinct space-separated integers *p*1,<=*p*2,<=...,<=*p**m* (1<=≤<=*p**i*<=≤<=*n*). Then *n*<=-<=1 lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integers *a**i* and *b**i* representing the ends of this path. | Print a single number — the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0. | [
"6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n"
] | [
"3\n"
] | Sample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5. | [
{
"input": "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6",
"output": "3"
},
{
"input": "2 2 1\n2 1\n1 2",
"output": "2"
},
{
"input": "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 34\n29 16\n7 46\n19 28\n27 33\n30 9\n33 16\n36 45\n47 1\n41 39\n23 13\n3 39\n5 34\n12 43",
"output": "9"
},
{
"input": "10 1 0\n3\n10 1\n9 4\n4 5\n6 4\n2 4\n7 5\n8 3\n5 3\n1 3",
"output": "1"
},
{
"input": "5 2 1\n1 5\n1 2\n2 3\n3 4\n4 5",
"output": "0"
},
{
"input": "5 2 0\n1 2\n1 2\n2 3\n3 4\n4 5",
"output": "0"
}
] | 122 | 268,390,400 | 0 | 3,891 |
|
592 | The Big Race | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977",
"output": "23437499999999999/23437500000000000"
},
{
"input": "9 6 1",
"output": "1/9"
},
{
"input": "32 9 2",
"output": "3/32"
},
{
"input": "976 5 6",
"output": "41/244"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 714 345",
"output": "689/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 1173508 8918834",
"output": "1173507/329245015"
},
{
"input": "321076647734423976 7 7",
"output": "1/1"
},
{
"input": "455227494055672047 92 28",
"output": "19792499741550983/455227494055672047"
},
{
"input": "595779167455745259 6954 8697",
"output": "205511958419723/595779167455745259"
},
{
"input": "1000000000000000000 1000000000 2000000000",
"output": "1/2"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701",
"output": "33045955908448679/33045955908448702"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999",
"output": "2499999999999999/1000000000000000000"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999",
"output": "4999999549999999/2001500050002000000"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999",
"output": "29498980479974999/2451500050002000000"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "232 17 83",
"output": "2/29"
},
{
"input": "5496272 63 200",
"output": "13765/2748136"
},
{
"input": "180 174 53",
"output": "13/45"
},
{
"input": "1954 190 537",
"output": "189/1954"
},
{
"input": "146752429 510 514",
"output": "571199/146752429"
},
{
"input": "579312860 55 70",
"output": "10344881/144828215"
},
{
"input": "1 9 9",
"output": "1/1"
},
{
"input": "95 19 19",
"output": "1/1"
},
{
"input": "404 63 441",
"output": "31/202"
},
{
"input": "5566 4798 4798",
"output": "1/1"
},
{
"input": "118289676 570846883 570846883",
"output": "1/1"
},
{
"input": "763 358 358",
"output": "1/1"
},
{
"input": "85356138 7223 482120804",
"output": "3611/42678069"
},
{
"input": "674664088 435395270 5",
"output": "9/674664088"
},
{
"input": "762200126044291557 370330636048898430 6",
"output": "17/762200126044291557"
},
{
"input": "917148533938841535 47 344459175789842163",
"output": "28/183429706787768307"
},
{
"input": "360212127113008697 877228952036215545 5259",
"output": "5258/360212127113008697"
},
{
"input": "683705963104411677 89876390 116741460012229240",
"output": "539258339/683705963104411677"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339",
"output": "3959660298385016/573003994959686829"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955",
"output": "1/1"
},
{
"input": "19 1 19",
"output": "1/19"
},
{
"input": "576 18 32",
"output": "1/16"
},
{
"input": "9540 10 954",
"output": "1/477"
},
{
"input": "101997840 6 16999640",
"output": "1/8499820"
},
{
"input": "955944 1278 748",
"output": "1/639"
},
{
"input": "482120804 66748 7223",
"output": "1/66748"
},
{
"input": "370330636048898430 61721772674816405 6",
"output": "1/61721772674816405"
},
{
"input": "344459175789842163 7328918633826429 47",
"output": "1/7328918633826429"
},
{
"input": "877228952036215545 166805277055755 5259",
"output": "1/55601759018585"
},
{
"input": "116741460012229240 1298911316 89876390",
"output": "1/649455658"
},
{
"input": "275856334120822851 209 1319886766128339",
"output": "1/1319886766128339"
},
{
"input": "413850294331656955 1 413850294331656955",
"output": "1/413850294331656955"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 3931027 6443236",
"output": "357366/29931365"
},
{
"input": "321076647734423976 7 8",
"output": "1672274206950125/13378193655600999"
},
{
"input": "455227494055672047 71 60",
"output": "6411654845854559/455227494055672047"
},
{
"input": "595779167455745259 9741 9331",
"output": "61162012885196/595779167455745259"
},
{
"input": "6470 80 160",
"output": "327/647"
},
{
"input": "686325 828 1656",
"output": "114511/228775"
},
{
"input": "4535304 2129 4258",
"output": "755973/1511768"
},
{
"input": "40525189 6365 12730",
"output": "20265394/40525189"
},
{
"input": "675297075 25986 51972",
"output": "112553659/225099025"
},
{
"input": "5681598412 75376 226128",
"output": "1893897375/5681598412"
},
{
"input": "384118571739435733 619773000 1859319000",
"output": "128039524053435733/384118571739435733"
},
{
"input": "391554751752251913 625743359 1877230077",
"output": "130518250652782079/391554751752251913"
},
{
"input": "390728504279201198 625082797 1250165594",
"output": "195364252413988195/390728504279201198"
},
{
"input": "389902265396085075 624421544 1248843088",
"output": "64983710976697837/129967421798695025"
},
{
"input": "734812071040507372 857211800 2571635400",
"output": "61234339274051543/183703017760126843"
},
{
"input": "1 1 2",
"output": "0/1"
},
{
"input": "3 1 4",
"output": "0/1"
},
{
"input": "8 2 3",
"output": "3/8"
},
{
"input": "64 32 16",
"output": "1/2"
},
{
"input": "1 1 1000000000",
"output": "0/1"
},
{
"input": "1000000000 1 1",
"output": "1/1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1/1"
},
{
"input": "1000000000 2 4",
"output": "1/2"
},
{
"input": "1000000000 123 456",
"output": "6579023/1000000000"
},
{
"input": "1000000000 123123 654",
"output": "24851/1000000000"
},
{
"input": "123456 123 456",
"output": "215/30864"
},
{
"input": "123456 1234567 123",
"output": "61/61728"
},
{
"input": "314159265 271 8281",
"output": "37939/314159265"
},
{
"input": "11071994 4231 1324",
"output": "2647/11071994"
},
{
"input": "961748927 961748941 982451653",
"output": "1/1"
},
{
"input": "15485221 1259 90863",
"output": "1258/15485221"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963",
"output": "1249999999999999959/1250000000000000000"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887",
"output": "399999999999999969/400000000000000000"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737",
"output": "333333333333333236/333333333333333333"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991",
"output": "799999999999999968/799999999999999999"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029",
"output": "406156156156155948/406156156156156111"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931",
"output": "249999999999999963/250000000000000000"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229",
"output": "50505050505050462/50505050505050505"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391",
"output": "66473313998066456/66473313998066473"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573",
"output": "72842742705619241/72842742705619294"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213",
"output": "314159265358979166/314159265358979323"
},
{
"input": "10 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "5 100000000000000000 99999999999999999",
"output": "1/1"
},
{
"input": "5 1000000000000 1000000000001",
"output": "1/1"
},
{
"input": "5 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 10 11",
"output": "1/1"
},
{
"input": "10 123456789123456789 723456789123456781",
"output": "1/1"
},
{
"input": "12345678910 123456789101112131 123456789101112132",
"output": "1/1"
},
{
"input": "5 499999999999999999 499999999999999998",
"output": "1/1"
}
] | 46 | 0 | 0 | 3,899 |
|
931 | World Cup | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
},
{
"input": "2 1 2",
"output": "Final!"
},
{
"input": "2 2 1",
"output": "Final!"
},
{
"input": "4 1 3",
"output": "Final!"
},
{
"input": "4 1 4",
"output": "Final!"
},
{
"input": "4 2 1",
"output": "1"
},
{
"input": "4 2 3",
"output": "Final!"
},
{
"input": "4 2 4",
"output": "Final!"
},
{
"input": "4 3 1",
"output": "Final!"
},
{
"input": "4 3 2",
"output": "Final!"
},
{
"input": "4 3 4",
"output": "1"
},
{
"input": "4 4 1",
"output": "Final!"
},
{
"input": "4 4 2",
"output": "Final!"
},
{
"input": "4 4 3",
"output": "1"
},
{
"input": "8 8 7",
"output": "1"
},
{
"input": "8 8 5",
"output": "2"
},
{
"input": "8 8 1",
"output": "Final!"
},
{
"input": "16 4 3",
"output": "1"
},
{
"input": "16 2 4",
"output": "2"
},
{
"input": "16 14 11",
"output": "3"
},
{
"input": "16 3 11",
"output": "Final!"
},
{
"input": "32 10 9",
"output": "1"
},
{
"input": "32 25 28",
"output": "2"
},
{
"input": "32 22 18",
"output": "3"
},
{
"input": "32 17 25",
"output": "4"
},
{
"input": "32 18 3",
"output": "Final!"
},
{
"input": "64 40 39",
"output": "1"
},
{
"input": "64 60 58",
"output": "2"
},
{
"input": "64 34 37",
"output": "3"
},
{
"input": "64 26 24",
"output": "4"
},
{
"input": "64 50 43",
"output": "5"
},
{
"input": "64 17 42",
"output": "Final!"
},
{
"input": "128 116 115",
"output": "1"
},
{
"input": "128 35 33",
"output": "2"
},
{
"input": "128 61 59",
"output": "3"
},
{
"input": "128 116 123",
"output": "4"
},
{
"input": "128 17 15",
"output": "5"
},
{
"input": "128 124 77",
"output": "6"
},
{
"input": "128 4 80",
"output": "Final!"
},
{
"input": "256 224 223",
"output": "1"
},
{
"input": "256 24 22",
"output": "2"
},
{
"input": "256 199 196",
"output": "3"
},
{
"input": "256 148 159",
"output": "4"
},
{
"input": "256 178 166",
"output": "5"
},
{
"input": "256 75 97",
"output": "6"
},
{
"input": "256 185 200",
"output": "7"
},
{
"input": "256 3 238",
"output": "Final!"
},
{
"input": "256 128 129",
"output": "Final!"
},
{
"input": "256 255 129",
"output": "7"
},
{
"input": "256 255 128",
"output": "Final!"
},
{
"input": "256 129 256",
"output": "7"
},
{
"input": "128 98 69",
"output": "6"
},
{
"input": "128 47 83",
"output": "Final!"
},
{
"input": "16 2 3",
"output": "2"
},
{
"input": "64 32 30",
"output": "2"
},
{
"input": "8 4 5",
"output": "Final!"
},
{
"input": "8 7 8",
"output": "1"
},
{
"input": "8 2 3",
"output": "2"
},
{
"input": "8 2 5",
"output": "Final!"
}
] | 61 | 5,632,000 | 0 | 3,904 |
|
51 | bHTML Tables Analisys | [
"expression parsing"
] | B. bHTML Tables Analisys | 2 | 256 | In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML table is very similar to a simple regular HTML table in which meet only the following tags : "table", "tr", "td", all the tags are paired and the table contains at least one row and at least one cell in each row. Have a look at the sample tests as examples of tables.
As can be seen, the tables may be nested. You are given a table (which may contain other(s)). You need to write a program that analyzes all the tables and finds the number of cells in each of them. The tables are not required to be rectangular. | For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation *s* of the specified table. String *s* corresponds to the given grammar (the root element of grammar is TABLE), its length does not exceed 5000. Only lower case letters are used to write tags. There are no spaces in the given string *s*. | Print the sizes of all the tables in the non-decreasing order. | [
"<table><tr><td></td></tr></table>\n",
"<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>\n",
"<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></table>\n</td></tr></table>\n</td></tr></table>\n"
] | [
"1 ",
"1 4 ",
"1 1 1 3 "
] | none | [
{
"input": "<table><tr><td></td></tr></table>",
"output": "1 "
},
{
"input": "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>",
"output": "1 4 "
},
{
"input": "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></table>\n</td></tr></table>\n</td></tr></table>",
"output": "1 1 1 3 "
},
{
"input": "<\nt\na\nble><tr><td></td>\n</\ntr>\n</\nt\nab\nle>",
"output": "1 "
},
{
"input": "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>",
"output": "1 1 "
},
{
"input": "<table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>",
"output": "1 1 1 "
},
{
"input": "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>",
"output": "1 1 "
},
{
"input": "<table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>",
"output": "1 1 1 "
},
{
"input": "<table><tr><td><table><tr><td></td><td></td></tr></table></td><td><table><tr><td></td></tr></table></td></tr></table>",
"output": "1 2 2 "
},
{
"input": "<table><tr><td><table><tr><td></td><td></td></tr></table></td><td><table><tr><td></td></tr></table></td></tr></table>",
"output": "1 2 2 "
},
{
"input": "<table><tr><td><table><tr><td></td></tr></table></td></tr><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>",
"output": "1 1 1 2 "
},
{
"input": "<table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table>",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
}
] | 62 | 0 | -1 | 3,907 |
845 | Luba And The Ticket | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits. | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "899889",
"output": "1"
},
{
"input": "899888",
"output": "1"
},
{
"input": "505777",
"output": "2"
},
{
"input": "999000",
"output": "3"
},
{
"input": "989010",
"output": "3"
},
{
"input": "651894",
"output": "1"
},
{
"input": "858022",
"output": "2"
},
{
"input": "103452",
"output": "1"
},
{
"input": "999801",
"output": "2"
},
{
"input": "999990",
"output": "1"
},
{
"input": "697742",
"output": "1"
},
{
"input": "242367",
"output": "2"
},
{
"input": "099999",
"output": "1"
},
{
"input": "198999",
"output": "1"
},
{
"input": "023680",
"output": "1"
},
{
"input": "999911",
"output": "2"
},
{
"input": "000990",
"output": "2"
},
{
"input": "117099",
"output": "1"
},
{
"input": "990999",
"output": "1"
},
{
"input": "000111",
"output": "1"
},
{
"input": "000444",
"output": "2"
},
{
"input": "202597",
"output": "2"
},
{
"input": "000333",
"output": "1"
},
{
"input": "030039",
"output": "1"
},
{
"input": "000009",
"output": "1"
},
{
"input": "006456",
"output": "1"
},
{
"input": "022995",
"output": "3"
},
{
"input": "999198",
"output": "1"
},
{
"input": "223456",
"output": "2"
},
{
"input": "333665",
"output": "2"
},
{
"input": "123986",
"output": "2"
},
{
"input": "599257",
"output": "1"
},
{
"input": "101488",
"output": "3"
},
{
"input": "111399",
"output": "2"
},
{
"input": "369009",
"output": "1"
},
{
"input": "024887",
"output": "2"
},
{
"input": "314347",
"output": "1"
},
{
"input": "145892",
"output": "1"
},
{
"input": "321933",
"output": "1"
},
{
"input": "100172",
"output": "1"
},
{
"input": "222455",
"output": "2"
},
{
"input": "317596",
"output": "1"
},
{
"input": "979245",
"output": "2"
},
{
"input": "000018",
"output": "1"
},
{
"input": "101389",
"output": "2"
},
{
"input": "123985",
"output": "2"
},
{
"input": "900000",
"output": "1"
},
{
"input": "132069",
"output": "1"
},
{
"input": "949256",
"output": "1"
},
{
"input": "123996",
"output": "2"
},
{
"input": "034988",
"output": "2"
},
{
"input": "320869",
"output": "2"
},
{
"input": "089753",
"output": "1"
},
{
"input": "335667",
"output": "2"
},
{
"input": "868580",
"output": "1"
},
{
"input": "958031",
"output": "2"
},
{
"input": "117999",
"output": "2"
},
{
"input": "000001",
"output": "1"
},
{
"input": "213986",
"output": "2"
},
{
"input": "123987",
"output": "3"
},
{
"input": "111993",
"output": "2"
},
{
"input": "642479",
"output": "1"
},
{
"input": "033788",
"output": "2"
},
{
"input": "766100",
"output": "2"
},
{
"input": "012561",
"output": "1"
},
{
"input": "111695",
"output": "2"
},
{
"input": "123689",
"output": "2"
},
{
"input": "944234",
"output": "1"
},
{
"input": "154999",
"output": "2"
},
{
"input": "333945",
"output": "1"
},
{
"input": "371130",
"output": "1"
},
{
"input": "977330",
"output": "2"
},
{
"input": "777544",
"output": "2"
},
{
"input": "111965",
"output": "2"
},
{
"input": "988430",
"output": "2"
},
{
"input": "123789",
"output": "3"
},
{
"input": "111956",
"output": "2"
},
{
"input": "444776",
"output": "2"
},
{
"input": "001019",
"output": "1"
},
{
"input": "011299",
"output": "2"
},
{
"input": "011389",
"output": "2"
},
{
"input": "999333",
"output": "2"
},
{
"input": "126999",
"output": "2"
},
{
"input": "744438",
"output": "0"
},
{
"input": "588121",
"output": "3"
},
{
"input": "698213",
"output": "2"
},
{
"input": "652858",
"output": "1"
},
{
"input": "989304",
"output": "3"
},
{
"input": "888213",
"output": "3"
},
{
"input": "969503",
"output": "2"
},
{
"input": "988034",
"output": "2"
},
{
"input": "889444",
"output": "2"
},
{
"input": "990900",
"output": "1"
},
{
"input": "301679",
"output": "2"
},
{
"input": "434946",
"output": "1"
},
{
"input": "191578",
"output": "2"
},
{
"input": "118000",
"output": "2"
},
{
"input": "636915",
"output": "0"
},
{
"input": "811010",
"output": "1"
},
{
"input": "822569",
"output": "1"
},
{
"input": "122669",
"output": "2"
},
{
"input": "010339",
"output": "2"
},
{
"input": "213698",
"output": "2"
},
{
"input": "895130",
"output": "2"
},
{
"input": "000900",
"output": "1"
},
{
"input": "191000",
"output": "2"
},
{
"input": "001000",
"output": "1"
},
{
"input": "080189",
"output": "2"
},
{
"input": "990000",
"output": "2"
},
{
"input": "201984",
"output": "2"
},
{
"input": "002667",
"output": "2"
},
{
"input": "877542",
"output": "2"
},
{
"input": "301697",
"output": "2"
},
{
"input": "211597",
"output": "2"
},
{
"input": "420337",
"output": "1"
},
{
"input": "024768",
"output": "2"
},
{
"input": "878033",
"output": "2"
},
{
"input": "788024",
"output": "2"
},
{
"input": "023869",
"output": "2"
},
{
"input": "466341",
"output": "1"
},
{
"input": "696327",
"output": "1"
},
{
"input": "779114",
"output": "2"
},
{
"input": "858643",
"output": "1"
},
{
"input": "011488",
"output": "3"
},
{
"input": "003669",
"output": "2"
},
{
"input": "202877",
"output": "3"
},
{
"input": "738000",
"output": "2"
},
{
"input": "567235",
"output": "2"
},
{
"input": "887321",
"output": "3"
},
{
"input": "401779",
"output": "2"
},
{
"input": "989473",
"output": "2"
},
{
"input": "004977",
"output": "3"
},
{
"input": "023778",
"output": "2"
},
{
"input": "809116",
"output": "1"
},
{
"input": "042762",
"output": "1"
},
{
"input": "777445",
"output": "2"
},
{
"input": "769302",
"output": "2"
},
{
"input": "023977",
"output": "2"
},
{
"input": "990131",
"output": "2"
}
] | 93 | 307,200 | 0 | 3,915 |
|
111 | Petya and Rectangle | [] | E. Petya and Rectangle | 5 | 256 | Little Petya loves playing with rectangles. Mom bought Petya a rectangle divided into cells *n*<=×<=*m* in size (containing *n* rows, *m* columns). Petya marked two different cells of the rectangle and now he is solving the following task:
Let's define a simple path between those two cells as a sequence of distinct cells *a*1,<=*a*2,<=...,<=*a**k*, where *a*1 and *a**k* are the two marked cells. Besides, *a**i* and *a**i*<=+<=1 are side-neighboring cells of the path (1<=≤<=*i*<=<<=*k*). Let's denote the path length as number *k* (the sequence length).
Petya's task is to find the longest simple path's length and to print the path. Help him. | The first line contains space-separated integers *n* and *m* (4<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the rectangle, correspondingly. The second line contains space-separated integers *x*1 and *y*1 — the coordinates of the first marked cell. The third line contains space-separated integers *x*2 *y*2 — the coordinates of the second marked cell (1<=<<=*x*1,<=*x*2<=<<=*n*,<=1<=<<=*y*1,<=*y*2<=<<=*m*,<=*x*1<=≠<=*x*2,<=*y*1<=≠<=*y*2).
The coordinates of a marked cell are a pair of integers *x* *y*, where *x* represents the row's number and *y* represents the column's number. The rows are numbered from top to bottom with consecutive integers from 1 to *n*. The columns are numbered from the left to the right by consecutive integers from 1 to *m*.
It is guaranteed that the marked cells are not positioned in one row or column. | In the first line print the length of the found path — *k*. In the next lines print *k* pairs of integers, one per line — coordinates of the cells that constitute the found path in the order, in which they follow in the path (the path must go from cell (*x*1,<=*y*1) to cell (*x*2,<=*y*2)). If there are several solutions, print any of them. | [
"4 4\n2 2\n3 3\n"
] | [
"15\n2 2\n1 2\n1 1\n2 1\n3 1\n4 1\n4 2\n4 3\n4 4\n3 4\n2 4\n1 4\n1 3\n2 3\n3 3\n"
] | The statement test is described in the picture: | [] | 92 | 0 | 0 | 3,919 |
208 | Police Station | [
"dp",
"graphs",
"shortest paths"
] | null | null | The Berland road network consists of *n* cities and of *m* bidirectional roads. The cities are numbered from 1 to *n*, where the main capital city has number *n*, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any direction takes the same time.
All residents of Berland are very lazy people, and so when they want to get from city *v* to city *u*, they always choose one of the shortest paths (no matter which one).
The Berland government wants to make this country's road network safer. For that, it is going to put a police station in one city. The police station has a rather strange property: when a citizen of Berland is driving along the road with a police station at one end of it, the citizen drives more carefully, so all such roads are considered safe. The roads, both ends of which differ from the city with the police station, are dangerous.
Now the government wonders where to put the police station so that the average number of safe roads for all the shortest paths from the cultural capital to the main capital would take the maximum value. | The first input line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, ) — the number of cities and the number of roads in Berland, correspondingly. Next *m* lines contain pairs of integers *v**i*, *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, *v**i*<=≠<=*u**i*) — the numbers of cities that are connected by the *i*-th road. The numbers on a line are separated by a space.
It is guaranteed that each pair of cities is connected with no more than one road and that it is possible to get from any city to any other one along Berland roads. | Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10<=-<=6. | [
"4 4\n1 2\n2 4\n1 3\n3 4\n",
"11 14\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 11\n6 11\n1 8\n8 9\n9 7\n11 7\n1 10\n10 4\n"
] | [
"1.000000000000\n",
"1.714285714286\n"
] | In the first sample you can put a police station in one of the capitals, then each path will have exactly one safe road. If we place the station not in the capital, then the average number of safe roads will also make <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8f23cc2cd3bef67bde56e16911c7af627da25d4d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample we can obtain the maximum sought value if we put the station in city 4, then 6 paths will have 2 safe roads each, and one path will have 0 safe roads, so the answer will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d7723df54e28c93b1c3b9d4c68b039b5071092af.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [] | 60 | 0 | 0 | 3,942 |
|
1,004 | Sonya and Exhibition | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily.
She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$.
The total beauty is equal to $2+2+4=8$.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
- in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$.
The total beauty is equal to $1+4+2=7$. | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307",
"output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..."
},
{
"input": "6 2\n1 6\n1 4",
"output": "010101"
},
{
"input": "2 1\n1 2",
"output": "01"
}
] | 108 | 0 | 0 | 3,947 |
|
27 | Unordered Subsequence | [
"constructive algorithms",
"greedy"
] | C. Unordered Subsequence | 2 | 256 | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. | If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length *k* of the shortest such subsequence. Then output *k* integers from the range [1..*n*] — indexes of the elements of this subsequence. If there are several solutions, output any of them. | [
"5\n67 499 600 42 23\n",
"3\n1 2 3\n",
"3\n2 3 1\n"
] | [
"3\n1 3 5\n",
"0\n",
"3\n1 2 3\n"
] | none | [
{
"input": "3\n3 1 2",
"output": "3\n1 2 3"
},
{
"input": "1\n-895376",
"output": "0"
},
{
"input": "2\n166442 61629",
"output": "0"
},
{
"input": "3\n-771740 -255752 -300809",
"output": "3\n1 2 3"
},
{
"input": "4\n-227347 -573134 -671045 11011",
"output": "3\n2 3 4"
},
{
"input": "5\n834472 -373089 441294 -633071 -957672",
"output": "3\n1 2 3"
},
{
"input": "2\n7 8",
"output": "0"
}
] | 218 | 0 | -1 | 3,949 |
877 | Ann and Books | [
"data structures",
"flows",
"hashing"
] | null | null | In Ann's favorite book shop are as many as *n* books on math and economics. Books are numbered from 1 to *n*. Each of them contains non-negative number of problems.
Today there is a sale: any subsegment of a segment from *l* to *r* can be bought at a fixed price.
Ann decided that she wants to buy such non-empty subsegment that the sale operates on it and the number of math problems is greater than the number of economics problems exactly by *k*. Note that *k* may be positive, negative or zero.
Unfortunately, Ann is not sure on which segment the sale operates, but she has *q* assumptions. For each of them she wants to know the number of options to buy a subsegment satisfying the condition (because the time she spends on choosing depends on that).
Currently Ann is too busy solving other problems, she asks you for help. For each her assumption determine the number of subsegments of the given segment such that the number of math problems is greaten than the number of economics problems on that subsegment exactly by *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, <=-<=109<=≤<=*k*<=≤<=109) — the number of books and the needed difference between the number of math problems and the number of economics problems.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2), where *t**i* is 1 if the *i*-th book is on math or 2 if the *i*-th is on economics.
The third line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109), where *a**i* is the number of problems in the *i*-th book.
The fourth line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of assumptions.
Each of the next *q* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) describing the *i*-th Ann's assumption. | Print *q* lines, in the *i*-th of them print the number of subsegments for the *i*-th Ann's assumption. | [
"4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4\n",
"4 0\n1 2 1 2\n0 0 0 0\n1\n1 4\n"
] | [
"2\n3\n4\n1\n",
"10\n"
] | In the first sample Ann can buy subsegments [1;1], [2;2], [3;3], [2;4] if they fall into the sales segment, because the number of math problems is greater by 1 on them that the number of economics problems. So we should count for each assumption the number of these subsegments that are subsegments of the given segment.
Segments [1;1] and [2;2] are subsegments of [1;2].
Segments [1;1], [2;2] and [3;3] are subsegments of [1;3].
Segments [1;1], [2;2], [3;3], [2;4] are subsegments of [1;4].
Segment [3;3] is subsegment of [3;4]. | [
{
"input": "4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4",
"output": "2\n3\n4\n1"
},
{
"input": "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4",
"output": "10"
},
{
"input": "10 10\n2 1 1 1 1 1 1 1 1 2\n0 10 10 0 0 10 10 10 10 0\n10\n4 10\n3 7\n9 9\n2 9\n10 10\n5 5\n2 2\n6 8\n3 4\n1 3",
"output": "7\n7\n1\n10\n0\n0\n1\n3\n2\n3"
},
{
"input": "10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0"
},
{
"input": "10 10\n1 1 1 1 1 2 1 2 1 2\n7 10 2 5 0 1 8 10 1 8\n10\n4 5\n1 3\n6 7\n8 10\n5 10\n1 8\n5 6\n1 5\n2 8\n9 10",
"output": "0\n1\n0\n0\n0\n1\n0\n1\n1\n0"
},
{
"input": "2 0\n1 2\n43 43\n3\n1 2\n2 2\n1 1",
"output": "1\n0\n0"
}
] | 0 | 0 | -1 | 3,966 |
|
90 | Cableway | [
"greedy",
"math"
] | A. Cableway | 2 | 256 | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: *r* of them like to ascend only in the red cablecars, *g* of them prefer only the green ones and *b* of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top. | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=><=0, it means that the group consists of at least one student. | Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. | [
"1 3 2\n",
"3 2 1\n"
] | [
"34",
"33"
] | Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the *b* group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the *g* group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | [
{
"input": "1 3 2",
"output": "34"
},
{
"input": "3 2 1",
"output": "33"
},
{
"input": "3 5 2",
"output": "37"
},
{
"input": "10 10 10",
"output": "44"
},
{
"input": "29 7 24",
"output": "72"
},
{
"input": "28 94 13",
"output": "169"
},
{
"input": "90 89 73",
"output": "163"
},
{
"input": "0 0 1",
"output": "32"
},
{
"input": "0 0 2",
"output": "32"
},
{
"input": "0 1 0",
"output": "31"
},
{
"input": "0 1 1",
"output": "32"
},
{
"input": "0 1 2",
"output": "32"
},
{
"input": "0 2 0",
"output": "31"
},
{
"input": "0 2 1",
"output": "32"
},
{
"input": "0 2 2",
"output": "32"
},
{
"input": "1 0 0",
"output": "30"
},
{
"input": "1 0 1",
"output": "32"
},
{
"input": "1 0 2",
"output": "32"
},
{
"input": "1 1 0",
"output": "31"
},
{
"input": "1 1 1",
"output": "32"
},
{
"input": "1 1 2",
"output": "32"
},
{
"input": "1 2 0",
"output": "31"
},
{
"input": "1 2 1",
"output": "32"
},
{
"input": "1 2 2",
"output": "32"
},
{
"input": "2 0 0",
"output": "30"
},
{
"input": "2 0 1",
"output": "32"
},
{
"input": "2 0 2",
"output": "32"
},
{
"input": "2 1 0",
"output": "31"
},
{
"input": "2 1 1",
"output": "32"
},
{
"input": "2 1 2",
"output": "32"
},
{
"input": "2 2 0",
"output": "31"
},
{
"input": "2 2 1",
"output": "32"
},
{
"input": "2 2 2",
"output": "32"
},
{
"input": "4 5 2",
"output": "37"
},
{
"input": "5 7 8",
"output": "41"
},
{
"input": "13 25 19",
"output": "67"
},
{
"input": "29 28 30",
"output": "74"
},
{
"input": "45 52 48",
"output": "106"
},
{
"input": "68 72 58",
"output": "136"
},
{
"input": "89 92 90",
"output": "166"
},
{
"input": "99 97 98",
"output": "177"
},
{
"input": "89 97 2",
"output": "175"
},
{
"input": "96 3 92",
"output": "171"
},
{
"input": "1 99 87",
"output": "178"
},
{
"input": "95 2 3",
"output": "171"
},
{
"input": "2 97 3",
"output": "175"
},
{
"input": "2 2 99",
"output": "179"
},
{
"input": "100 100 100",
"output": "179"
},
{
"input": "100 0 100",
"output": "179"
},
{
"input": "0 100 100",
"output": "179"
},
{
"input": "100 100 0",
"output": "178"
},
{
"input": "100 0 0",
"output": "177"
},
{
"input": "0 100 0",
"output": "178"
},
{
"input": "0 0 100",
"output": "179"
},
{
"input": "5 4 5",
"output": "38"
}
] | 218 | 0 | 3.9455 | 3,971 |
85 | Domino | [
"constructive algorithms",
"implementation"
] | A. Domino | 1 | 256 | We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.
You are given a 4<=×<=*n* rectangular field, that is the field that contains four lines and *n* columns. You have to find for it any tiling by 1<=×<=2 dominoes such that each of the *n*<=-<=1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2<=×<=1 as well as 1<=×<=2 dominoes.
Write a program that finds an arbitrary sought tiling. | The input contains one positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of the field's columns. | If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing *n* characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling. | [
"4\n"
] | [
"yyzz\nbccd\nbxxd\nyyaa\n"
] | none | [
{
"input": "4",
"output": "aacc\nbbdd\nzkkz\nzllz"
},
{
"input": "2",
"output": "aa\nbb\naa\nbb"
},
{
"input": "3",
"output": "aab\nccb\nbaa\nbcc"
},
{
"input": "5",
"output": "aaccz\nbbddz\nzkkmm\nzllnn"
},
{
"input": "1",
"output": "a\na\nb\nb"
},
{
"input": "6",
"output": "aaccee\nbbddff\nzkkmmz\nzllnnz"
},
{
"input": "7",
"output": "aacceez\nbbddffz\nzkkmmoo\nzllnnpp"
},
{
"input": "8",
"output": "aacceegg\nbbddffhh\nzkkmmooz\nzllnnppz"
},
{
"input": "9",
"output": "aacceeggz\nbbddffhhz\nzkkmmooqq\nzllnnpprr"
},
{
"input": "10",
"output": "aacceeggii\nbbddffhhjj\nzkkmmooqqz\nzllnnpprrz"
},
{
"input": "11",
"output": "aacceeggiiz\nbbddffhhjjz\nzkkmmooqqss\nzllnnpprrtt"
},
{
"input": "12",
"output": "aacceeggiiaa\nbbddffhhjjbb\nzkkmmooqqssz\nzllnnpprrttz"
},
{
"input": "13",
"output": "aacceeggiiaaz\nbbddffhhjjbbz\nzkkmmooqqsskk\nzllnnpprrttll"
},
{
"input": "14",
"output": "aacceeggiiaacc\nbbddffhhjjbbdd\nzkkmmooqqsskkz\nzllnnpprrttllz"
},
{
"input": "15",
"output": "aacceeggiiaaccz\nbbddffhhjjbbddz\nzkkmmooqqsskkmm\nzllnnpprrttllnn"
},
{
"input": "16",
"output": "aacceeggiiaaccee\nbbddffhhjjbbddff\nzkkmmooqqsskkmmz\nzllnnpprrttllnnz"
},
{
"input": "17",
"output": "aacceeggiiaacceez\nbbddffhhjjbbddffz\nzkkmmooqqsskkmmoo\nzllnnpprrttllnnpp"
},
{
"input": "18",
"output": "aacceeggiiaacceegg\nbbddffhhjjbbddffhh\nzkkmmooqqsskkmmooz\nzllnnpprrttllnnppz"
},
{
"input": "19",
"output": "aacceeggiiaacceeggz\nbbddffhhjjbbddffhhz\nzkkmmooqqsskkmmooqq\nzllnnpprrttllnnpprr"
},
{
"input": "20",
"output": "aacceeggiiaacceeggii\nbbddffhhjjbbddffhhjj\nzkkmmooqqsskkmmooqqz\nzllnnpprrttllnnpprrz"
},
{
"input": "21",
"output": "aacceeggiiaacceeggiiz\nbbddffhhjjbbddffhhjjz\nzkkmmooqqsskkmmooqqss\nzllnnpprrttllnnpprrtt"
},
{
"input": "22",
"output": "aacceeggiiaacceeggiiaa\nbbddffhhjjbbddffhhjjbb\nzkkmmooqqsskkmmooqqssz\nzllnnpprrttllnnpprrttz"
},
{
"input": "23",
"output": "aacceeggiiaacceeggiiaaz\nbbddffhhjjbbddffhhjjbbz\nzkkmmooqqsskkmmooqqsskk\nzllnnpprrttllnnpprrttll"
},
{
"input": "24",
"output": "aacceeggiiaacceeggiiaacc\nbbddffhhjjbbddffhhjjbbdd\nzkkmmooqqsskkmmooqqsskkz\nzllnnpprrttllnnpprrttllz"
},
{
"input": "25",
"output": "aacceeggiiaacceeggiiaaccz\nbbddffhhjjbbddffhhjjbbddz\nzkkmmooqqsskkmmooqqsskkmm\nzllnnpprrttllnnpprrttllnn"
},
{
"input": "26",
"output": "aacceeggiiaacceeggiiaaccee\nbbddffhhjjbbddffhhjjbbddff\nzkkmmooqqsskkmmooqqsskkmmz\nzllnnpprrttllnnpprrttllnnz"
},
{
"input": "27",
"output": "aacceeggiiaacceeggiiaacceez\nbbddffhhjjbbddffhhjjbbddffz\nzkkmmooqqsskkmmooqqsskkmmoo\nzllnnpprrttllnnpprrttllnnpp"
},
{
"input": "28",
"output": "aacceeggiiaacceeggiiaacceegg\nbbddffhhjjbbddffhhjjbbddffhh\nzkkmmooqqsskkmmooqqsskkmmooz\nzllnnpprrttllnnpprrttllnnppz"
},
{
"input": "29",
"output": "aacceeggiiaacceeggiiaacceeggz\nbbddffhhjjbbddffhhjjbbddffhhz\nzkkmmooqqsskkmmooqqsskkmmooqq\nzllnnpprrttllnnpprrttllnnpprr"
},
{
"input": "30",
"output": "aacceeggiiaacceeggiiaacceeggii\nbbddffhhjjbbddffhhjjbbddffhhjj\nzkkmmooqqsskkmmooqqsskkmmooqqz\nzllnnpprrttllnnpprrttllnnpprrz"
},
{
"input": "91",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiz\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjz\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqss\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrtt"
},
{
"input": "92",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaa\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbb\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqssz\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttz"
},
{
"input": "93",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaaz\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbz\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskk\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttll"
},
{
"input": "94",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacc\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbdd\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkz\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllz"
},
{
"input": "95",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaaccz\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddz\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmm\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnn"
},
{
"input": "96",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaaccee\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddff\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmz\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnz"
},
{
"input": "97",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceez\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffz\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmoo\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpp"
},
{
"input": "98",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceegg\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhh\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooz\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnppz"
},
{
"input": "99",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggz\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhz\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqq\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprr"
},
{
"input": "100",
"output": "aacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggiiaacceeggii\nbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjjbbddffhhjj\nzkkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqsskkmmooqqz\nzllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrttllnnpprrz"
}
] | 248 | 512,000 | 0 | 3,979 |
31 | Worms Evolution | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output": "5 2 1"
},
{
"input": "10\n858 972 670 15 662 114 33 273 53 310",
"output": "2 6 1"
},
{
"input": "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 362 585 952 365 92 749 904 525 307 626 883 367 450 755 564 950 728 724 69 106 119 157 96 290",
"output": "1 38 25"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "1 63 61"
},
{
"input": "100\n156 822 179 298 981 82 610 345 373 378 895 734 768 15 78 335 764 608 932 297 717 553 916 367 425 447 361 195 66 70 901 236 905 744 919 564 296 610 963 628 840 52 100 750 345 308 37 687 192 704 101 815 10 990 216 358 823 546 578 821 706 148 182 582 421 482 829 425 121 337 500 301 402 868 66 935 625 527 746 585 308 523 488 914 608 709 875 252 151 781 447 2 756 176 976 302 450 35 680 791",
"output": "1 98 69"
},
{
"input": "100\n54 947 785 838 359 647 92 445 48 465 323 486 101 86 607 31 860 420 709 432 435 372 272 37 903 814 309 197 638 58 259 822 793 564 309 22 522 907 101 853 486 824 614 734 630 452 166 532 256 499 470 9 933 452 256 450 7 26 916 406 257 285 895 117 59 369 424 133 16 417 352 440 806 236 478 34 889 469 540 806 172 296 73 655 261 792 868 380 204 454 330 53 136 629 236 850 134 560 264 291",
"output": "2 29 27"
},
{
"input": "99\n175 269 828 129 499 890 127 263 995 807 508 289 996 226 437 320 365 642 757 22 190 8 345 499 834 713 962 889 336 171 608 492 320 257 472 801 176 325 301 306 198 729 933 4 640 322 226 317 567 586 249 237 202 633 287 128 911 654 719 988 420 855 361 574 716 899 317 356 581 440 284 982 541 111 439 29 37 560 961 224 478 906 319 416 736 603 808 87 762 697 392 713 19 459 262 238 239 599 997",
"output": "1 44 30"
},
{
"input": "98\n443 719 559 672 16 69 529 632 953 999 725 431 54 22 346 968 558 696 48 669 963 129 257 712 39 870 498 595 45 821 344 925 179 388 792 346 755 213 423 365 344 659 824 356 773 637 628 897 841 155 243 536 951 361 192 105 418 431 635 596 150 162 145 548 473 531 750 306 377 354 450 975 79 743 656 733 440 940 19 139 237 346 276 227 64 799 479 633 199 17 796 362 517 234 729 62 995 535",
"output": "2 70 40"
},
{
"input": "97\n359 522 938 862 181 600 283 1000 910 191 590 220 761 818 903 264 751 751 987 316 737 898 168 925 244 674 34 950 754 472 81 6 37 520 112 891 981 454 897 424 489 238 363 709 906 951 677 828 114 373 589 835 52 89 97 435 277 560 551 204 879 469 928 523 231 163 183 609 821 915 615 969 616 23 874 437 844 321 78 53 643 786 585 38 744 347 150 179 988 985 200 11 15 9 547 886 752",
"output": "1 23 10"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "100\n328 397 235 453 188 254 879 225 423 36 384 296 486 592 231 849 856 255 213 898 234 800 701 529 951 693 507 326 15 905 618 348 967 927 28 979 752 850 343 35 84 302 36 390 482 826 249 918 91 289 973 457 557 348 365 239 709 565 320 560 153 130 647 708 483 469 788 473 322 844 830 562 611 961 397 673 69 960 74 703 369 968 382 451 328 160 211 230 566 208 7 545 293 73 806 375 157 410 303 58",
"output": "1 79 6"
},
{
"input": "33\n52 145 137 734 180 847 178 286 716 134 181 630 358 764 593 762 785 28 1 468 189 540 764 485 165 656 114 58 628 108 605 584 257",
"output": "8 30 7"
},
{
"input": "57\n75 291 309 68 444 654 985 158 514 204 116 918 374 806 176 31 49 455 269 66 722 713 164 818 317 295 546 564 134 641 28 13 987 478 146 219 213 940 289 173 157 666 168 391 392 71 870 477 446 988 414 568 964 684 409 671 454",
"output": "2 41 29"
},
{
"input": "88\n327 644 942 738 84 118 981 686 530 404 137 197 434 16 693 183 423 325 410 345 941 329 7 106 79 867 584 358 533 675 192 718 641 329 900 768 404 301 101 538 954 590 401 954 447 14 559 337 756 586 934 367 538 928 945 936 770 641 488 579 206 869 902 139 216 446 723 150 829 205 373 578 357 368 960 40 121 206 503 385 521 161 501 694 138 370 709 308",
"output": "1 77 61"
},
{
"input": "100\n804 510 266 304 788 625 862 888 408 82 414 470 777 991 729 229 933 406 601 1 596 720 608 706 432 361 527 548 59 548 474 515 4 991 263 568 681 24 117 563 576 587 281 643 904 521 891 106 842 884 943 54 605 815 504 757 311 374 335 192 447 652 633 410 455 402 382 150 432 836 413 819 669 875 638 925 217 805 632 520 605 266 728 795 162 222 603 159 284 790 914 443 775 97 789 606 859 13 851 47",
"output": "1 77 42"
},
{
"input": "100\n449 649 615 713 64 385 927 466 138 126 143 886 80 199 208 43 196 694 92 89 264 180 617 970 191 196 910 150 275 89 693 190 191 99 542 342 45 592 114 56 451 170 64 589 176 102 308 92 402 153 414 675 352 157 69 150 91 288 163 121 816 184 20 234 836 12 593 150 793 439 540 93 99 663 186 125 349 247 476 106 77 523 215 7 363 278 441 745 337 25 148 384 15 915 108 211 240 58 23 408",
"output": "1 6 5"
},
{
"input": "90\n881 436 52 308 97 261 153 931 670 538 702 156 114 445 154 685 452 76 966 790 93 42 547 65 736 364 136 489 719 322 239 628 696 735 55 703 622 375 100 188 804 341 546 474 484 446 729 290 974 301 602 225 996 244 488 983 882 460 962 754 395 617 61 640 534 292 158 375 632 902 420 979 379 38 100 67 963 928 190 456 545 571 45 716 153 68 844 2 102 116",
"output": "1 14 2"
},
{
"input": "80\n313 674 262 240 697 146 391 221 793 504 896 818 92 899 86 370 341 339 306 887 937 570 830 683 729 519 240 833 656 847 427 958 435 704 853 230 758 347 660 575 843 293 649 396 437 787 654 599 35 103 779 783 447 379 444 585 902 713 791 150 851 228 306 721 996 471 617 403 102 168 197 741 877 481 968 545 331 715 236 654",
"output": "1 13 8"
},
{
"input": "70\n745 264 471 171 946 32 277 511 269 469 89 831 69 2 369 407 583 602 646 633 429 747 113 302 722 321 344 824 241 372 263 287 822 24 652 758 246 967 219 313 882 597 752 965 389 775 227 556 95 904 308 340 899 514 400 187 275 318 621 546 659 488 199 154 811 1 725 79 925 82",
"output": "1 63 60"
},
{
"input": "60\n176 502 680 102 546 917 516 801 392 435 635 492 398 456 653 444 472 513 634 378 273 276 44 920 68 124 800 167 825 250 452 264 561 344 98 933 381 939 426 51 568 548 206 887 342 763 151 514 156 354 486 546 998 649 356 438 295 570 450 589",
"output": "2 26 20"
},
{
"input": "50\n608 92 889 33 146 803 402 91 868 400 828 505 375 558 584 129 361 776 974 123 765 804 326 186 61 927 904 511 762 775 640 593 300 664 897 461 869 911 986 789 607 500 309 457 294 104 724 471 216 155",
"output": "3 25 11"
},
{
"input": "40\n40 330 98 612 747 336 640 381 991 366 22 167 352 12 868 166 603 40 313 869 609 981 609 804 54 729 8 854 347 300 828 922 39 633 695 988 4 530 545 176",
"output": "5 10 8"
},
{
"input": "30\n471 920 308 544 347 222 878 671 467 332 215 180 681 114 151 203 492 951 653 614 453 510 540 422 399 532 113 198 932 825",
"output": "2 21 9"
},
{
"input": "20\n551 158 517 475 595 108 764 961 590 297 761 841 659 568 82 888 733 214 993 359",
"output": "3 20 2"
},
{
"input": "10\n983 748 726 406 196 993 2 251 66 263",
"output": "-1"
},
{
"input": "9\n933 266 457 863 768 257 594 136 145",
"output": "-1"
},
{
"input": "8\n537 198 48 771 944 868 700 163",
"output": "7 8 1"
},
{
"input": "7\n140 779 639 679 768 479 158",
"output": "2 3 1"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "-1"
},
{
"input": "5\n700 939 173 494 120",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "3\n907 452 355",
"output": "-1"
},
{
"input": "3\n963 630 333",
"output": "1 3 2"
},
{
"input": "3\n2 2 4",
"output": "3 2 1"
},
{
"input": "3\n2 4 100",
"output": "-1"
}
] | 92 | 0 | 3.977 | 3,989 |
400 | Inna and Choose Options | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers *a* and *b* (*a*·*b*<==<=12), after that he makes a table of size *a*<=×<=*b* from the cards he put on the table as follows: the first *b* cards form the first row of the table, the second *b* cards form the second row of the table and so on, the last *b* cards form the last (number *a*) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.
Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers *a* and *b* to choose. Help her win the game: print to her all the possible ways of numbers *a*,<=*b* that she can choose and win. | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The *i*-th character of the string shows the character that is written on the *i*-th card from the start. | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line by whitespaces. | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX",
"output": "6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1"
}
] | 77 | 0 | 3 | 3,992 |
|
181 | Number of Triplets | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C*) and (*C*,<=*B*,<=*A*) are considered the same. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are different. | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 0",
"output": "3"
},
{
"input": "9\n1 1\n1 0\n0 1\n0 0\n-1 0\n-1 1\n-1 -1\n1 -1\n0 -1",
"output": "8"
},
{
"input": "10\n2 1\n-1 0\n-2 -1\n-1 1\n0 2\n2 -2\n0 0\n-2 -2\n0 -2\n-2 1",
"output": "4"
},
{
"input": "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2",
"output": "4"
},
{
"input": "10\n0 1\n-1 -1\n1 1\n-1 0\n1 -1\n-2 -1\n-2 2\n-2 0\n0 -2\n0 -1",
"output": "5"
},
{
"input": "10\n2 1\n-1 1\n0 0\n-3 1\n-2 -3\n-1 -2\n-1 -1\n1 2\n3 -2\n0 -2",
"output": "1"
},
{
"input": "20\n-3 -3\n0 4\n-3 1\n1 1\n-1 2\n-4 4\n3 -1\n-3 0\n0 2\n4 0\n2 3\n2 4\n4 -3\n-4 3\n-1 1\n1 3\n-2 4\n1 -2\n1 -1\n3 0",
"output": "10"
},
{
"input": "20\n-3 -3\n0 4\n-3 1\n1 1\n-1 2\n-4 4\n3 -1\n-3 0\n0 2\n4 0\n2 3\n2 4\n4 -3\n-4 3\n-1 1\n1 3\n-2 4\n1 -2\n1 -1\n3 0",
"output": "10"
},
{
"input": "20\n-1 18\n-2 5\n-5 4\n2 -33\n9 -18\n0 0\n11 -22\n2 0\n-1 2\n-4 41\n1 6\n1 -2\n6 -12\n0 1\n-3 6\n3 -6\n3 -8\n-1 4\n2 -5\n1 0",
"output": "21"
},
{
"input": "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-4 5\n181 -262\n76 -118\n0 0\n-7 18\n-58 104\n-5 6\n-6 12\n-3 4\n1 0\n11 -10\n-86 130\n-3 6\n153 -236\n-183 270\n-33 64",
"output": "57"
},
{
"input": "3\n3 3\n1 2\n1 1",
"output": "0"
},
{
"input": "3\n0 0\n0 -1\n0 1",
"output": "1"
}
] | 466 | 16,998,400 | 0 | 3,997 |
|
959 | Mahmoud and Ehab and the even-odd game | [
"games",
"math"
] | null | null | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd.
If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? | The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. | Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. | [
"1\n",
"2\n"
] | [
"Ehab",
"Mahmoud"
] | In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins. | [
{
"input": "1",
"output": "Ehab"
},
{
"input": "2",
"output": "Mahmoud"
},
{
"input": "10000",
"output": "Mahmoud"
},
{
"input": "33333",
"output": "Ehab"
},
{
"input": "5",
"output": "Ehab"
},
{
"input": "1000000000",
"output": "Mahmoud"
},
{
"input": "999999999",
"output": "Ehab"
},
{
"input": "123123123",
"output": "Ehab"
},
{
"input": "22222221",
"output": "Ehab"
},
{
"input": "22222220",
"output": "Mahmoud"
},
{
"input": "3",
"output": "Ehab"
},
{
"input": "4",
"output": "Mahmoud"
},
{
"input": "6",
"output": "Mahmoud"
},
{
"input": "7",
"output": "Ehab"
},
{
"input": "8",
"output": "Mahmoud"
},
{
"input": "9",
"output": "Ehab"
},
{
"input": "10",
"output": "Mahmoud"
},
{
"input": "536870912",
"output": "Mahmoud"
},
{
"input": "536870913",
"output": "Ehab"
},
{
"input": "536870911",
"output": "Ehab"
}
] | 0 | 0 | -1 | 4,010 |
|
817 | Treasure Hunt | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 109 | 307,200 | 3 | 4,028 |
|
380 | Sereja and Brackets | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries.
You can find the definitions for a subsequence and a correct bracket sequence in the notes. | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query. | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> < *k*<sub class="lower-index">2</sub> < ... < *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|).
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
For the third query required sequence will be «()».
For the fourth query required sequence will be «()(())(())». | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n1 70\n1 19\n10 22\n13 36\n3 10\n34 40\n51 76\n64 71\n36 75\n24 71\n1 63\n5 14\n46 67\n32 56\n39 43\n43 56\n61 82\n2 78\n1 21\n10 72\n49 79\n12 14\n53 79\n15 31\n7 47",
"output": "4\n4\n2\n4\n2\n12\n16\n2\n12\n4\n0\n12\n0\n6\n18\n6\n2\n6\n6\n0\n2\n0\n6\n8\n18\n4\n2\n4\n2\n2\n2\n18\n8\n12\n2\n0\n2\n6\n12"
},
{
"input": "))(()))))())())))))())((()()))))()))))))))))))\n9\n26 42\n21 22\n6 22\n7 26\n43 46\n25 27\n32 39\n22 40\n2 45",
"output": "4\n0\n6\n8\n0\n2\n2\n10\n20"
},
{
"input": "(()((((()(())((((((((()((((((()((((\n71\n15 29\n17 18\n5 26\n7 10\n16 31\n26 35\n2 30\n16 24\n2 24\n7 12\n15 18\n12 13\n25 30\n1 30\n12 13\n16 20\n6 35\n20 28\n18 23\n9 31\n12 35\n14 17\n8 16\n3 10\n12 33\n7 19\n2 33\n7 17\n21 27\n10 30\n29 32\n9 28\n18 32\n28 31\n31 33\n4 26\n15 27\n10 17\n8 14\n11 28\n8 23\n17 33\n4 14\n3 6\n6 34\n19 23\n4 21\n16 27\n14 27\n6 19\n31 32\n29 32\n9 17\n1 21\n2 31\n18 29\n16 26\n15 18\n4 5\n13 20\n9 28\n18 30\n1 32\n2 9\n16 24\n1 20\n4 15\n16 23\n19 34\n5 22\n5 23",
"output": "2\n0\n8\n2\n4\n2\n10\n2\n10\n4\n0\n0\n0\n10\n0\n0\n10\n2\n2\n8\n4\n0\n6\n2\n4\n6\n12\n6\n2\n6\n2\n6\n4\n2\n0\n8\n2\n4\n6\n4\n8\n4\n6\n0\n10\n2\n6\n2\n2\n6\n0\n2\n4\n8\n12\n2\n2\n0\n0\n0\n6\n2\n12\n4\n2\n8\n6\n2\n4\n6\n8"
},
{
"input": "(((())((((()()((((((()((()(((((((((((()((\n6\n20 37\n28 32\n12 18\n7 25\n21 33\n4 5",
"output": "4\n0\n2\n6\n4\n2"
},
{
"input": "(((()((((()()()(()))((((()(((()))()((((()))()((())\n24\n37 41\n13 38\n31 34\n14 16\n29 29\n12 46\n1 26\n15 34\n8 47\n11 23\n6 32\n2 22\n9 27\n17 40\n6 15\n4 49\n12 33\n3 48\n22 47\n19 48\n10 27\n23 25\n4 44\n27 48",
"output": "2\n16\n0\n2\n0\n26\n16\n12\n30\n8\n18\n14\n14\n12\n6\n34\n16\n32\n18\n18\n12\n0\n30\n16"
},
{
"input": ")()((((((((((((((((()(((()()(()((((((()(((((((()()))((((())(((((((((()(((((((((\n51\n29 53\n31 69\n54 59\n3 52\n26 46\n14 62\n6 54\n39 56\n17 27\n46 74\n60 72\n18 26\n38 46\n4 27\n22 52\n44 49\n42 77\n2 20\n39 57\n61 70\n33 54\n10 30\n67 70\n46 66\n17 77\n5 52\n33 77\n26 32\n1 72\n40 78\n38 68\n19 47\n30 53\n19 29\n52 71\n1 11\n22 53\n17 42\n2 51\n4 12\n24 76\n22 34\n21 69\n11 69\n36 52\n17 31\n57 58\n54 62\n23 71\n5 46\n51 53",
"output": "12\n14\n4\n18\n6\n22\n18\n8\n4\n12\n2\n4\n2\n4\n16\n2\n14\n2\n8\n2\n10\n6\n2\n10\n24\n18\n16\n4\n26\n14\n14\n10\n12\n6\n6\n2\n16\n10\n18\n0\n22\n6\n20\n22\n10\n8\n2\n4\n22\n10\n0"
},
{
"input": "(\n1\n1 1",
"output": "0"
},
{
"input": ")\n1\n1 1",
"output": "0"
},
{
"input": "()\n1\n1 2",
"output": "2"
},
{
"input": ")(\n1\n1 2",
"output": "0"
}
] | 1,000 | 139,571,200 | 0 | 4,039 |
|
237 | Primes on Interval | [
"binary search",
"number theory",
"two pointers"
] | null | null | You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a*<=+<=1) such that for any integer *x* (*a*<=≤<=*x*<=≤<=*b*<=-<=*l*<=+<=1) among *l* integers *x*, *x*<=+<=1, ..., *x*<=+<=*l*<=-<=1 there are at least *k* prime numbers.
Find and print the required minimum *l*. If no value *l* meets the described limitations, print -1. | A single line contains three space-separated integers *a*,<=*b*,<=*k* (1<=≤<=*a*,<=*b*,<=*k*<=≤<=106; *a*<=≤<=*b*). | In a single line print a single integer — the required minimum *l*. If there's no solution, print -1. | [
"2 4 2\n",
"6 13 1\n",
"1 4 3\n"
] | [
"3\n",
"4\n",
"-1\n"
] | none | [
{
"input": "2 4 2",
"output": "3"
},
{
"input": "6 13 1",
"output": "4"
},
{
"input": "1 4 3",
"output": "-1"
},
{
"input": "5 8 2",
"output": "4"
},
{
"input": "8 10 3",
"output": "-1"
},
{
"input": "1 5 2",
"output": "3"
},
{
"input": "6 8 3",
"output": "-1"
},
{
"input": "21 29 2",
"output": "9"
},
{
"input": "17 27 3",
"output": "11"
},
{
"input": "1 1000000 10000",
"output": "137970"
},
{
"input": "690059 708971 10000",
"output": "-1"
},
{
"input": "12357 534133 2",
"output": "138"
},
{
"input": "838069 936843 3",
"output": "142"
},
{
"input": "339554 696485 4",
"output": "168"
},
{
"input": "225912 522197 5",
"output": "190"
},
{
"input": "404430 864261 6",
"output": "236"
},
{
"input": "689973 807140 7",
"output": "236"
},
{
"input": "177146 548389 8",
"output": "240"
},
{
"input": "579857 857749 9",
"output": "300"
},
{
"input": "35648 527231 10",
"output": "280"
},
{
"input": "2 1000000 10000",
"output": "137970"
},
{
"input": "1 999999 9999",
"output": "137958"
},
{
"input": "5 5 10",
"output": "-1"
},
{
"input": "11 11 6",
"output": "-1"
},
{
"input": "4 4 95",
"output": "-1"
},
{
"input": "1 1000000 1000000",
"output": "-1"
},
{
"input": "1 1000000 78498",
"output": "999999"
},
{
"input": "1 1000000 78499",
"output": "-1"
},
{
"input": "3459 94738 1",
"output": "72"
},
{
"input": "1 1000000 1",
"output": "114"
},
{
"input": "1 1000000 78498",
"output": "999999"
},
{
"input": "1 1000000 78497",
"output": "999998"
},
{
"input": "1 1000000 78490",
"output": "999978"
},
{
"input": "1000 10000 13",
"output": "168"
},
{
"input": "100000 1000000 7821",
"output": "108426"
},
{
"input": "20 1000000 40000",
"output": "539580"
},
{
"input": "1000 900000 50000",
"output": "659334"
},
{
"input": "10000 1000000 60000",
"output": "793662"
},
{
"input": "9999 99999 8000",
"output": "86572"
},
{
"input": "50 150 20",
"output": "100"
},
{
"input": "999953 999953 1",
"output": "1"
},
{
"input": "999953 999953 2",
"output": "-1"
},
{
"input": "999931 999953 2",
"output": "23"
},
{
"input": "999906 999984 4",
"output": "52"
},
{
"input": "999940 999983 3",
"output": "26"
},
{
"input": "1 1 1",
"output": "-1"
},
{
"input": "1 1 1000000",
"output": "-1"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "1 3 1",
"output": "2"
},
{
"input": "1 3 2",
"output": "3"
},
{
"input": "1 4 2",
"output": "3"
},
{
"input": "1 5 2",
"output": "3"
},
{
"input": "1 5 3",
"output": "5"
},
{
"input": "2 5 2",
"output": "3"
},
{
"input": "3 5 1",
"output": "2"
}
] | 61 | 6,963,200 | 0 | 4,047 |
|
548 | Mike and Fun | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for *q* rounds. In each round, Mike chooses a bear (*i*,<=*j*) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the information about the rounds. Each of them contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*), the row number and the column number of the bear changing his state. | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n1 1\n2 1\n1 1\n2 1",
"output": "2\n2\n1\n2\n1\n2\n1\n2\n2\n2"
},
{
"input": "5 5 30\n0 1 1 1 0\n1 1 0 1 1\n0 1 1 1 1\n0 0 1 1 0\n0 0 0 0 0\n3 2\n2 2\n2 2\n4 3\n1 4\n3 2\n4 1\n2 4\n1 4\n2 1\n5 2\n4 1\n4 1\n5 1\n2 4\n2 4\n4 4\n1 2\n3 1\n4 5\n1 2\n2 3\n1 1\n5 1\n3 4\n1 1\n5 4\n1 5\n5 4\n2 2",
"output": "3\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n5\n5\n5\n5\n5\n5\n4\n3\n3\n4\n4\n4"
},
{
"input": "1 1 10\n0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1\n0\n1\n0\n1\n0\n1\n0\n1\n0"
},
{
"input": "1 1 3\n1\n1 1\n1 1\n1 1",
"output": "0\n1\n0"
},
{
"input": "1 5 5\n0 0 0 0 0\n1 2\n1 1\n1 4\n1 5\n1 3",
"output": "1\n2\n2\n2\n5"
},
{
"input": "5 1 5\n0\n0\n0\n0\n0\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "1 1 1\n0\n1 1",
"output": "1"
},
{
"input": "2 2 1\n1 1\n1 1\n1 1",
"output": "2"
}
] | 46 | 102,400 | 0 | 4,049 |
|
833 | The Meaningless Game | [
"math",
"number theory"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes"
},
{
"input": "1\n2 3",
"output": "No"
},
{
"input": "1\n1062961 1031",
"output": "Yes"
},
{
"input": "1\n6 12",
"output": "No"
},
{
"input": "1\n3 1",
"output": "No"
},
{
"input": "1\n3 10",
"output": "No"
},
{
"input": "1\n31159 970883281",
"output": "Yes"
},
{
"input": "1\n9907 98148649",
"output": "Yes"
},
{
"input": "1\n16 8",
"output": "No"
},
{
"input": "1\n90 72",
"output": "No"
}
] | 1,000 | 0 | 0 | 4,052 |
|
596 | Wilbur and Points | [
"combinatorics",
"greedy",
"sortings"
] | null | null | Wilbur is playing with a set of *n* points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (*x*, *y*) belongs to the set, then all points (*x*', *y*'), such that 0<=≤<=*x*'<=≤<=*x* and 0<=≤<=*y*'<=≤<=*y* also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to *n*. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (*x*, *y*) gets number *i*, then all (*x*',*y*') from the set, such that *x*'<=≥<=*x* and *y*'<=≥<=*y* must be assigned a number not less than *i*. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as *s*(*x*,<=*y*)<==<=*y*<=-<=*x*. Now he gives Wilbur some *w*1, *w*2,..., *w**n*, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number *i* has it's special value equal to *w**i*, that is *s*(*x**i*,<=*y**i*)<==<=*y**i*<=-<=*x**i*<==<=*w**i*.
Now Wilbur asks you to help him with this challenge. | The first line of the input consists of a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of points in the set Wilbur is playing with.
Next follow *n* lines with points descriptions. Each line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=100<=000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (*x*, *y*) is present in the input, then all points (*x*', *y*'), such that 0<=≤<=*x*'<=≤<=*x* and 0<=≤<=*y*'<=≤<=*y*, are also present in the input.
The last line of the input contains *n* integers. The *i*-th of them is *w**i* (<=-<=100<=000<=≤<=*w**i*<=≤<=100<=000) — the required special value of the point that gets number *i* in any aesthetically pleasing numbering. | If there exists an aesthetically pleasant numbering of points in the set, such that *s*(*x**i*,<=*y**i*)<==<=*y**i*<=-<=*x**i*<==<=*w**i*, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with *n* lines. On the *i*-th of these lines print the point of the set that gets number *i*. If there are multiple solutions, print any of them. | [
"5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0\n",
"3\n1 0\n0 0\n2 0\n0 1 2\n"
] | [
"YES\n0 0\n1 0\n2 0\n0 1\n1 1\n",
"NO\n"
] | In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and *y*<sub class="lower-index">*i*</sub> - *x*<sub class="lower-index">*i*</sub> = *w*<sub class="lower-index">*i*</sub>.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist. | [
{
"input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0",
"output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"
},
{
"input": "3\n1 0\n0 0\n2 0\n0 1 2",
"output": "NO"
},
{
"input": "9\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1\n1 2\n2 2\n0 2\n0 0 0 -1 -1 -2 1 1 2",
"output": "NO"
},
{
"input": "18\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n1 0\n0 1 2 3 4 5 6 7 8 9 -1 10 11 12 13 14 15 16",
"output": "YES\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 0\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16"
},
{
"input": "1\n0 0\n0",
"output": "YES\n0 0"
},
{
"input": "37\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n1 0\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 -1 26 27 28 29 30 31 32 33 34 35",
"output": "YES\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n1 0\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35"
},
{
"input": "31\n0 0\n0 1\n0 2\n0 3\n1 0\n1 1\n2 0\n2 1\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n24 0\n25 0\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 1 -15 2 -16 -17 -18 3 -19 -20 0 -21 -22 -23 -24 -25 -1",
"output": "YES\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n0 1\n15 0\n0 2\n16 0\n17 0\n18 0\n0 3\n19 0\n20 0\n1 1\n21 0\n22 0\n23 0\n24 0\n25 0\n2 1"
},
{
"input": "40\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n0 1 2 -1 -2 3 4 -3 5 6 7 8 0 -4 -5 1 -6 -7 -8 -9 -10 -11 9 2 -12 -13 -14 3 10 -15 11 4 -16 -17 -18 -19 5 6 12 -20",
"output": "YES\n0 0\n0 1\n0 2\n1 0\n2 0\n0 3\n0 4\n3 0\n0 5\n0 6\n0 7\n0 8\n1 1\n4 0\n5 0\n1 2\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n0 9\n1 3\n12 0\n13 0\n14 0\n1 4\n0 10\n15 0\n0 11\n1 5\n16 0\n17 0\n18 0\n19 0\n1 6\n1 7\n0 12\n20 0"
},
{
"input": "21\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n1 0\n1 1\n1 2\n1 3\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n86174 -26039 -13726 25840 85990 -62633 -29634 -68400 39255 1313 77388 830 -45558 -90862 97867 46376 58592 17103 32820 27220 94751",
"output": "NO"
},
{
"input": "31\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n2 0\n2 1\n2 2\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n-8 1 4 -11 0 -4 -10 3 4 -5 -9 8 7 6 2 -2 -1 9 -3 -14 2 3 -6 0 -7 -1 5 0 -13 -12 1",
"output": "NO"
},
{
"input": "1\n0 0\n-9876",
"output": "NO"
},
{
"input": "16\n0 0\n0 1\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 1 -11 -12 -13 -14",
"output": "YES\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n0 1\n11 0\n12 0\n13 0\n14 0"
},
{
"input": "5\n1 1\n0 1\n2 0\n1 0\n0 0\n0 -1 -2 1 0",
"output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"
},
{
"input": "2\n0 0\n1 0\n-1 0",
"output": "NO"
}
] | 46 | 0 | 0 | 4,054 |
|
0 | none | [
"none"
] | null | null | На координатной прямой сидит *n* собачек, *i*-я собачка находится в точке *x**i*. Кроме того, на прямой есть *m* мисок с едой, для каждой известна её координата на прямой *u**j* и время *t**j*, через которое еда в миске остынет и станет невкусной. Это значит, что если собачка прибежит к миске в момент времени, строго больший *t**j*, то еда уже остынет, и собачка кушать её не станет.
Считая, что каждая собачка бежит со скоростью 1, найдите максимальное количество собачек, которые смогут покушать. Считайте, что собачки побегут к тем мискам, на которые вы им укажете. Из одной миски не могут кушать две или более собачки.
Собачки могут обгонять друг друга, то есть, если одна из них остановится покушать, другая может пройти мимо неё, чтобы попасть к другой миске. | В первой строке находится пара целых чисел *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — количество собачек и мисок соответственно.
Во второй строке находятся *n* целых чисел *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — координата *i*-й собачки.
В следующих *m* строках находятся пары целых чисел *u**j* и *t**j* (<=-<=109<=≤<=*u**j*<=≤<=109, 1<=≤<=*t**j*<=≤<=109) — координата *j*-й миски и время, когда остынет еда в ней, соответственно.
Гарантируется, что никакие две собачки не находятся в одной точке. Никакие две миски также не могут находиться в одной точке. | Выведите одно целое число *a* — максимальное количество собачек, которые смогут покушать. | [
"5 4\n-2 0 4 8 13\n-1 1\n4 3\n6 3\n11 2\n",
"3 3\n-1 3 7\n1 1\n4 1\n7 1\n",
"4 4\n20 1 10 30\n1 1\n2 5\n22 2\n40 10\n"
] | [
"4\n",
"2\n",
"3\n"
] | В первом примере первая собачка побежит направо к первой миске, третья собачка сразу начнёт есть из второй миски, четвёртая собачка побежит влево к третьей миске, а пятая собачка побежит влево к четвёртой миске. | [] | 2,000 | 25,907,200 | 0 | 4,089 |
|
847 | University Classes | [
"implementation"
] | null | null | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. | Print minimum number of rooms needed to hold all groups classes on Monday. | [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] | [
"1\n",
"3\n"
] | In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | [
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n1000000\n0101000",
"output": "1"
},
{
"input": "3\n0101111\n1101011\n1010011",
"output": "3"
},
{
"input": "5\n0100101\n0000001\n0110000\n0010000\n0011110",
"output": "3"
},
{
"input": "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100",
"output": "6"
},
{
"input": "10\n0000000\n0010000\n0000000\n0000010\n0000000\n0100001\n1000000\n0000000\n0000000\n0000000",
"output": "1"
},
{
"input": "20\n1111111\n1101011\n1111011\n0111111\n1111111\n1110111\n1111111\n1111111\n1111111\n1111111\n1110111\n1111111\n0111111\n1011111\n1111111\n1111111\n1101110\n1111111\n1111111\n1111111",
"output": "20"
}
] | 109 | 3,481,600 | 3 | 4,090 |
|
124 | Permutations | [
"brute force",
"combinatorics",
"implementation"
] | null | null | You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. | The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits. | Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule. | [
"6 4\n5237\n2753\n7523\n5723\n5327\n2537\n",
"3 3\n010\n909\n012\n",
"7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n"
] | [
"2700\n",
"3\n",
"20522\n"
] | In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102. | [
{
"input": "6 4\n5237\n2753\n7523\n5723\n5327\n2537",
"output": "2700"
},
{
"input": "3 3\n010\n909\n012",
"output": "3"
},
{
"input": "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156",
"output": "20522"
},
{
"input": "5 5\n61374\n74304\n41924\n46010\n09118",
"output": "64592"
},
{
"input": "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116",
"output": "52901157"
},
{
"input": "7 1\n1\n0\n8\n5\n4\n9\n8",
"output": "9"
},
{
"input": "3 8\n34848224\n16307102\n25181102",
"output": "8612277"
},
{
"input": "2 8\n13633861\n68468345",
"output": "14445725"
},
{
"input": "4 4\n0950\n0634\n9264\n8684",
"output": "3738"
},
{
"input": "6 5\n65777\n80932\n32260\n49089\n00936\n85557",
"output": "41439"
},
{
"input": "5 6\n687443\n279213\n765651\n611680\n500192",
"output": "258067"
},
{
"input": "8 6\n034753\n917195\n222679\n778596\n980006\n467267\n482763\n807481",
"output": "647026"
},
{
"input": "8 6\n075967\n240855\n352399\n791547\n103244\n982259\n409866\n926586",
"output": "491255"
},
{
"input": "3 1\n7\n2\n9",
"output": "7"
},
{
"input": "6 4\n5407\n4617\n3050\n7647\n8647\n1993",
"output": "6474"
},
{
"input": "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675",
"output": "71123"
},
{
"input": "8 7\n5945843\n9094433\n0750024\n6255984\n1784849\n7275947\n6513944\n0145523",
"output": "5152379"
},
{
"input": "8 7\n8112819\n8982110\n5457941\n4575033\n5203331\n7410823\n0532182\n8151054",
"output": "6194602"
},
{
"input": "8 8\n63315032\n20587190\n05461152\n76872565\n71177578\n53541174\n00451913\n85740357",
"output": "60622457"
},
{
"input": "2 3\n135\n725",
"output": "4"
},
{
"input": "7 1\n9\n5\n8\n9\n7\n6\n9",
"output": "4"
},
{
"input": "5 3\n560\n978\n543\n846\n714",
"output": "435"
},
{
"input": "7 2\n53\n74\n84\n62\n14\n77\n59",
"output": "69"
},
{
"input": "3 4\n0537\n2174\n5299",
"output": "3583"
},
{
"input": "7 5\n13532\n16394\n97663\n73133\n22712\n58185\n65035",
"output": "26455"
},
{
"input": "8 5\n07936\n07927\n46068\n99158\n90958\n41283\n59266\n87841",
"output": "52364"
},
{
"input": "8 6\n867468\n695388\n700723\n444270\n545657\n178053\n315040\n554471",
"output": "559559"
},
{
"input": "7 7\n6575460\n6965366\n1912357\n7080608\n2561692\n5209630\n0439095",
"output": "5917123"
},
{
"input": "1 2\n96",
"output": "0"
},
{
"input": "1 3\n289",
"output": "0"
},
{
"input": "1 8\n78795220",
"output": "0"
},
{
"input": "8 7\n2407792\n7023368\n2609925\n0587109\n3543873\n6602371\n4579875\n9893509",
"output": "6790457"
},
{
"input": "4 6\n065169\n150326\n924608\n490012",
"output": "488134"
},
{
"input": "4 4\n8851\n6190\n0521\n1659",
"output": "6596"
},
{
"input": "4 4\n4381\n3147\n7017\n5593",
"output": "3690"
},
{
"input": "8 4\n0344\n9196\n1379\n5470\n0989\n8316\n7096\n7918",
"output": "7801"
},
{
"input": "1 6\n430254",
"output": "0"
},
{
"input": "8 1\n4\n0\n8\n5\n9\n0\n4\n7",
"output": "9"
},
{
"input": "5 2\n60\n08\n77\n66\n03",
"output": "74"
},
{
"input": "3 1\n9\n8\n2",
"output": "7"
},
{
"input": "7 2\n89\n00\n59\n90\n99\n22\n55",
"output": "99"
},
{
"input": "2 4\n7694\n6577",
"output": "712"
},
{
"input": "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116",
"output": "52901157"
},
{
"input": "2 7\n9183508\n9276377",
"output": "26912"
},
{
"input": "5 4\n7411\n3080\n9578\n5902\n3225",
"output": "6498"
},
{
"input": "3 4\n0136\n4556\n4268",
"output": "2134"
},
{
"input": "6 8\n99358096\n38390629\n71597322\n35940809\n48949759\n66204248",
"output": "53570178"
},
{
"input": "7 2\n23\n11\n88\n25\n22\n45\n10",
"output": "78"
},
{
"input": "2 3\n834\n630",
"output": "24"
},
{
"input": "4 2\n87\n03\n95\n23",
"output": "48"
},
{
"input": "2 8\n10715643\n97664296",
"output": "1244714"
},
{
"input": "6 1\n9\n3\n1\n3\n4\n5",
"output": "8"
},
{
"input": "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675",
"output": "71123"
},
{
"input": "4 4\n7603\n0859\n5241\n7680",
"output": "5518"
},
{
"input": "1 7\n4605461",
"output": "0"
},
{
"input": "3 4\n3061\n3404\n6670",
"output": "2916"
},
{
"input": "8 4\n1847\n0962\n3216\n0772\n6399\n3082\n7997\n0625",
"output": "7246"
},
{
"input": "2 6\n834527\n764560",
"output": "577"
},
{
"input": "5 6\n959808\n303464\n414335\n758650\n828038",
"output": "486245"
},
{
"input": "4 1\n0\n7\n5\n1",
"output": "7"
},
{
"input": "6 7\n4565736\n9842969\n1412800\n6411011\n5744909\n3791659",
"output": "4066781"
},
{
"input": "4 1\n0\n7\n5\n1",
"output": "7"
},
{
"input": "1 3\n250",
"output": "0"
},
{
"input": "2 1\n2\n0",
"output": "2"
},
{
"input": "8 8\n96805230\n73119021\n06552907\n86283347\n88650846\n19155689\n37032451\n19310120",
"output": "53604668"
},
{
"input": "3 2\n64\n94\n65",
"output": "10"
},
{
"input": "8 4\n8008\n4983\n0295\n0353\n5838\n1960\n0270\n7144",
"output": "7475"
},
{
"input": "4 8\n22025344\n54085308\n77633421\n59238322",
"output": "7681556"
},
{
"input": "5 3\n504\n878\n599\n683\n083",
"output": "615"
},
{
"input": "5 4\n7663\n4755\n2941\n4588\n0232",
"output": "5346"
},
{
"input": "6 2\n97\n57\n40\n99\n22\n94",
"output": "77"
},
{
"input": "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404",
"output": "2790148"
},
{
"input": "8 2\n42\n86\n25\n30\n27\n64\n67\n38",
"output": "61"
},
{
"input": "5 2\n52\n22\n05\n37\n74",
"output": "51"
},
{
"input": "2 2\n63\n50",
"output": "13"
},
{
"input": "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404",
"output": "2790148"
},
{
"input": "6 2\n95\n56\n06\n46\n77\n51",
"output": "62"
},
{
"input": "3 5\n97424\n96460\n47766",
"output": "9536"
},
{
"input": "2 3\n596\n246",
"output": "35"
},
{
"input": "3 1\n1\n2\n2",
"output": "1"
},
{
"input": "4 2\n87\n03\n95\n23",
"output": "48"
},
{
"input": "7 5\n41078\n41257\n35324\n70082\n66783\n99954\n85784",
"output": "56901"
},
{
"input": "8 7\n8943041\n2427704\n3775080\n2956111\n1345704\n0937172\n1979973\n7081540",
"output": "3544246"
},
{
"input": "6 6\n505845\n903151\n055779\n733849\n508266\n029177",
"output": "249045"
},
{
"input": "4 4\n1871\n9417\n7444\n4294",
"output": "5368"
},
{
"input": "2 5\n60106\n07866",
"output": "5224"
},
{
"input": "3 3\n195\n860\n567",
"output": "258"
},
{
"input": "8 5\n68186\n57779\n78079\n47451\n69788\n82172\n75373\n50157",
"output": "32237"
},
{
"input": "4 7\n5342341\n5194611\n4032103\n8739798",
"output": "4056779"
},
{
"input": "4 8\n91401735\n53979237\n20857777\n94594293",
"output": "34567247"
},
{
"input": "1 2\n95",
"output": "0"
},
{
"input": "6 4\n0443\n7108\n7211\n4287\n6439\n7711",
"output": "5301"
},
{
"input": "6 7\n5794383\n4078451\n0263676\n7682294\n7436158\n3363189",
"output": "3560125"
},
{
"input": "2 5\n07259\n51985",
"output": "23657"
},
{
"input": "3 3\n624\n125\n097",
"output": "247"
},
{
"input": "8 1\n9\n7\n6\n2\n9\n6\n4\n8",
"output": "7"
},
{
"input": "6 3\n530\n862\n874\n932\n972\n157",
"output": "442"
},
{
"input": "3 2\n51\n39\n97",
"output": "58"
},
{
"input": "8 4\n4650\n1735\n4269\n8023\n0948\n9685\n3675\n6017",
"output": "6836"
},
{
"input": "5 3\n168\n513\n110\n386\n501",
"output": "403"
},
{
"input": "6 2\n01\n81\n60\n27\n23\n67",
"output": "70"
},
{
"input": "4 4\n2759\n7250\n3572\n8067",
"output": "2028"
},
{
"input": "8 5\n12658\n00588\n23491\n09985\n63973\n78517\n98187\n29863",
"output": "68592"
},
{
"input": "3 1\n5\n4\n2",
"output": "3"
},
{
"input": "7 8\n24925537\n07626274\n77060131\n82415056\n70422753\n60455207\n32176884",
"output": "54680138"
},
{
"input": "5 8\n94157433\n85577189\n62547277\n11815893\n35445851",
"output": "15679126"
},
{
"input": "5 5\n31164\n27213\n17981\n48806\n01273",
"output": "33367"
},
{
"input": "3 6\n743197\n172242\n635654",
"output": "261245"
},
{
"input": "4 6\n760130\n653002\n902824\n380915",
"output": "268111"
},
{
"input": "8 8\n83239439\n62184887\n58968944\n39808261\n68740623\n38480328\n81965504\n52600488",
"output": "44481119"
},
{
"input": "8 2\n99\n20\n22\n39\n33\n60\n54\n08",
"output": "91"
},
{
"input": "1 7\n3545113",
"output": "0"
},
{
"input": "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762",
"output": "4126934"
},
{
"input": "6 8\n50157346\n63836375\n03176371\n83637145\n28631038\n18617159",
"output": "24702445"
},
{
"input": "1 5\n84932",
"output": "0"
},
{
"input": "4 3\n204\n515\n280\n840",
"output": "467"
},
{
"input": "8 2\n40\n41\n02\n55\n26\n52\n60\n25",
"output": "58"
},
{
"input": "2 5\n90526\n32565",
"output": "586"
},
{
"input": "4 4\n3058\n2370\n0288\n5983",
"output": "2972"
},
{
"input": "6 7\n9085507\n7716507\n1952887\n6569746\n1900754\n9212439",
"output": "3180457"
},
{
"input": "5 2\n01\n07\n63\n71\n99",
"output": "89"
},
{
"input": "6 4\n4505\n3672\n4248\n2783\n9780\n6579",
"output": "4484"
},
{
"input": "2 3\n281\n498",
"output": "127"
},
{
"input": "8 5\n16966\n36762\n49579\n71703\n66646\n41125\n94022\n26623",
"output": "66868"
},
{
"input": "1 6\n170086",
"output": "0"
},
{
"input": "4 1\n4\n2\n2\n2",
"output": "2"
},
{
"input": "3 8\n12418144\n74773130\n10504811",
"output": "22901234"
},
{
"input": "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762",
"output": "4126934"
}
] | 122 | 2,867,200 | -1 | 4,106 |
|
704 | Ant Man | [
"dp",
"graphs",
"greedy"
] | null | null | Scott Lang is at war with Darren Cross. There are *n* chairs in a hall where they are, numbered with 1,<=2,<=...,<=*n* from left to right. The *i*-th chair is located at coordinate *x**i*. Scott is on chair number *s* and Cross is on chair number *e*. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number *s*), visit each chair exactly once and end up on chair number *e* with Cross.
As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number *i* to chair number *j* takes |*x**i*<=-<=*x**j*| seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.
If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.
Jumping off the *i*-th chair takes:
- *c**i* extra seconds if he's small. - *d**i* extra seconds otherwise (he's large).
Also, landing on *i*-th chair takes:
- *b**i* extra seconds if he's small. - *a**i* extra seconds otherwise (he's large).
In simpler words, jumping from *i*-th chair to *j*-th chair takes exactly:
- |*x**i*<=-<=*x**j*|<=+<=*c**i*<=+<=*b**j* seconds if *j*<=<<=*i*. - |*x**i*<=-<=*x**j*|<=+<=*d**i*<=+<=*a**j* seconds otherwise (*j*<=><=*i*).
Given values of *x*, *a*, *b*, *c*, *d* find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once. | The first line of the input contains three integers *n*,<=*s* and *e* (2<=≤<=*n*<=≤<=5000,<=1<=≤<=*s*,<=*e*<=≤<=*n*,<=*s*<=≠<=*e*) — the total number of chairs, starting and ending positions of Scott.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=109).
The third line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1,<=*a*2,<=...,<=*a**n*<=≤<=109).
The fourth line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b*1,<=*b*2,<=...,<=*b**n*<=≤<=109).
The fifth line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c*1,<=*c*2,<=...,<=*c**n*<=≤<=109).
The sixth line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d*1,<=*d*2,<=...,<=*d**n*<=≤<=109). | Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once. | [
"7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8\n"
] | [
"139\n"
] | In the sample testcase, an optimal solution would be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5bbd3e094ffa5a72e263dfaec7aeaff795bc22a3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139. | [
{
"input": "7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8",
"output": "139"
},
{
"input": "2 1 2\n75475634 804928248\n476927808 284875072\n503158867 627937890\n322595515 786026685\n645468307 669240390",
"output": "1659795993"
},
{
"input": "2 2 1\n396750123 498712414\n41068575 397815498\n975619613 324859334\n264886117 99828622\n52238294 539721972",
"output": "1177410526"
},
{
"input": "3 2 1\n374288891 535590429 751244358\n124321145 232930851 266089174\n543529670 773363571 319728747\n580543238 582720391 468188689\n490702144 598813561 138628383",
"output": "2469230490"
},
{
"input": "5 4 1\n291882089 358502890 412106895 564718673 837699009\n657489855 690430685 632939232 373282330 398630021\n753287868 667584659 79866982 603966291 850348020\n738379364 480642952 593942770 930919906 485781288\n903492853 141752547 984789430 897217447 909607734",
"output": "5175751243"
},
{
"input": "10 8 1\n71550121 96204862 223219513 312183499 402690754 446173607 668171337 796619138 799843967 983359971\n905549873 673542337 566661387 879397647 434495917 631413076 150918417 579868000 224422012 126195703\n525305826 535526356 404334728 653535984 998133227 879226371 59632864 356493387 62611196 827258251\n296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375\n546951131 622980885 937972790 529946158 992070269 723690994 343766215 374461155 343698323 996408310",
"output": "8924243769"
},
{
"input": "8 3 1\n58265855 250839457 317463343 432130709 479851779 538085060 652509537 687041819\n126496650 186774359 331193631 836310042 255380788 756411639 690869710 176576709\n222368048 906033133 8623893 807375696 461796409 362923880 194114590 733391789\n137574156 670510137 237249112 673135534 595041001 875171159 112263159 649035661\n806391318 956639323 312576627 140089445 824235612 590430725 170794245 24820918",
"output": "7373256613"
},
{
"input": "2 1 2\n445124518 897457879\n106020849 17627833\n993819963 891100983\n222379086 338599698\n19224513 39444281",
"output": "489185707"
},
{
"input": "3 1 3\n140847557 466570047 534914399\n93013372 106184897 87868332\n798881865 348785541 412639907\n541420868 474507814 209232335\n35025208 96472847 130874791",
"output": "719618126"
},
{
"input": "2 2 1\n30771656 606524344\n997641489 998433881\n28784768 365665640\n391019116 560756524\n999852227 998301460",
"output": "1165293980"
},
{
"input": "3 3 1\n101399784 425546473 843762421\n567904823 879017062 918453203\n254552488 116158914 179175464\n273461838 396254505 362710994\n886094289 597198515 822610701",
"output": "1872039538"
},
{
"input": "2 1 2\n1 2\n1 1\n1 1\n1 1\n1 1",
"output": "3"
},
{
"input": "2 2 1\n1 2\n1 1\n1 1\n1 1\n1 1",
"output": "3"
},
{
"input": "2 1 2\n1 1000000000\n1000000000 1\n1 1\n1 1\n1 1000000000",
"output": "1000000001"
},
{
"input": "2 2 1\n1 1000000000\n1 1\n1000000000 1\n1 1000000000\n1 1",
"output": "2999999999"
},
{
"input": "3 1 2\n1 2 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "7"
},
{
"input": "3 3 2\n1 2 3\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "7"
},
{
"input": "3 1 3\n1 2 3\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "4000000002"
},
{
"input": "2 1 2\n511643468 985543586\n1000000000 1\n1 1000000000\n1000000000 1\n1 1000000000",
"output": "473900120"
},
{
"input": "2 2 1\n326677749 688620949\n1000000000 1\n1 1000000000\n1000000000 1\n1 1000000000",
"output": "361943202"
}
] | 46 | 512,000 | 0 | 4,107 |
|
523 | Rotate, Flip and Zoom | [
"*special",
"implementation"
] | null | null | Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor. | The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome. | Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. | [
"3 2\n.*.\n.*.\n",
"9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n"
] | [
"....\n....\n****\n****\n....\n....\n",
"********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......******************..**********....\n......******************..**********....\n........****************....**********..\n........****************....**********..\n............************......**********\n............************......**********\n"
] | none | [
{
"input": "3 2\n.*.\n.*.",
"output": "....\n....\n****\n****\n....\n...."
},
{
"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*",
"output": "********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......*..."
},
{
"input": "1 100\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\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": "........................................................................................................................................................................................................\n........................................................................................................................................................................................................"
},
{
"input": "1 100\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\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": "********************************************************************************************************************************************************************************************************\n********************************************************************************************************************************************************************************************************"
},
{
"input": "1 100\n.\n*\n.\n.\n.\n*\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n*\n.\n*\n.\n.\n*\n*\n.\n*\n.\n.\n*\n.\n.\n*\n*\n.\n.\n.\n.\n.\n*\n.\n*\n.\n*\n.\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n*\n.\n.\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n.\n*\n*\n*\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": "..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****..\n..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****.."
},
{
"input": "100 1\n****************************************************************************************************",
"output": "**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n..."
},
{
"input": "100 1\n*...***.....**.*...*.*.**.************.**..**.*..**..**.*.**...***.*...*.*..*.*.*......**..*..*...**",
"output": "**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n..."
},
{
"input": "1 1\n.",
"output": "..\n.."
},
{
"input": "1 1\n*",
"output": "**\n**"
},
{
"input": "2 2\n.*\n*.",
"output": "..**\n..**\n**..\n**.."
},
{
"input": "1 2\n*\n.",
"output": "**..\n**.."
},
{
"input": "2 1\n*.",
"output": "**\n**\n..\n.."
}
] | 62 | 102,400 | 3 | 4,108 |
|
929 | Прокат велосипедов | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},
{
"input": "2 100000\n0 100000",
"output": "1"
},
{
"input": "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 61805 61861 63005 64013 68848 71182 71497 72715 73008 75616 76042 76614 80690 83089 85033 86408 92392 92763 93833 95085 95815 97152 99379",
"output": "8"
},
{
"input": "5 7\n6219 6222 6229 6231 6236",
"output": "3"
},
{
"input": "10 448\n78449 78573 78599 78742 78748 78759 78853 79091 79298 79324",
"output": "3"
},
{
"input": "20 19191\n11272 12386 14108 24663 24932 26547 29656 44677 45436 45654 48562 62367 71049 71238 78182 84042 88736 92026 96836 99343",
"output": "6"
},
{
"input": "2 100000\n1 100000",
"output": "1"
},
{
"input": "2 99999\n0 100000",
"output": "-1"
},
{
"input": "2 2\n1 3",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
}
] | 62 | 5,632,000 | 3 | 4,119 |
|
895 | String Mark | [
"combinatorics",
"math",
"strings"
] | null | null | At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*.
Recently at the BSU was an important test work on which Vasya recived the mark *a*. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark *b*, such that every student recieved mark strictly smaller than *b*.
Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious.
More formally: you are given two strings *a*, *b* of the same length and you need to figure out the number of different strings *c* such that:
1) *c* can be obtained from *a* by swapping some characters, in other words *c* is a permutation of *a*.
2) String *a* is lexicographically smaller than *c*.
3) String *c* is lexicographically smaller than *b*.
For two strings *x* and *y* of the same length it is true that *x* is lexicographically smaller than *y* if there exists such *i*, that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=...,<=*x**i*<=-<=1<==<=*y**i*<=-<=1,<=*x**i*<=<<=*y**i*.
Since the answer can be very large, you need to find answer modulo 109<=+<=7. | First line contains string *a*, second line contains string *b*. Strings *a*,<=*b* consist of lowercase English letters. Their lengths are equal and don't exceed 106.
It is guaranteed that *a* is lexicographically smaller than *b*. | Print one integer — the number of different strings satisfying the condition of the problem modulo 109<=+<=7. | [
"abc\nddd\n",
"abcdef\nabcdeg\n",
"abacaba\nubuduba\n"
] | [
"5\n",
"0\n",
"64\n"
] | In first sample from string *abc* can be obtained strings *acb*, *bac*, *bca*, *cab*, *cba*, all of them are larger than *abc*, but smaller than *ddd*. So the answer is 5.
In second sample any string obtained from *abcdef* is larger than *abcdeg*. So the answer is 0. | [
{
"input": "abc\nddd",
"output": "5"
},
{
"input": "abcdef\nabcdeg",
"output": "0"
},
{
"input": "abacaba\nubuduba",
"output": "64"
},
{
"input": "aac\nbbb",
"output": "1"
},
{
"input": "aaaccc\nbbbbbb",
"output": "9"
},
{
"input": "aaaaaa\nzzzzzz",
"output": "0"
},
{
"input": "abcde\nzzzzz",
"output": "119"
},
{
"input": "a\nc",
"output": "0"
},
{
"input": "aaa\nccc",
"output": "0"
},
{
"input": "abacabadaba\ndabacabaaba",
"output": "5586"
},
{
"input": "ujfawuezgiy\nvuqvvsivvwe",
"output": "1730501"
},
{
"input": "jvmzmvqexcqycjcpuqimvyovcffrdwtexpqhxswzytoaokvnexkzgycpmbgvsnyifkwvfbirtwnprmrlotlnhkogjlmxmgruklcuqstwfwoswux\nvzsmohqcjpzdhfyjbljviodktdsfbmaujgtsryzlcwdvccykofgxibzrxoqrvfarjduntkenwwqwuvzzxamztghkusejmucljoedfrqpcwunkru",
"output": "845854724"
},
{
"input": "izybggxalv\nrbqjamqnyg",
"output": "183497"
},
{
"input": "wdtzolgzsx\nxnlokxihzw",
"output": "229771"
},
{
"input": "hoazcxoypk\njdmafdaqwm",
"output": "116556"
},
{
"input": "qdgvzritpdtoqkq\nvlulirhbfjbcmdp",
"output": "862600433"
},
{
"input": "qszbyqbjgs\nqszbyqbjgt",
"output": "0"
},
{
"input": "ftmhkyguxvbuqaiuxbmj\nftmhkyguxvbuqaiuxbmk",
"output": "0"
},
{
"input": "dkvctjuqhtotnlwkoiaegcbsigoqvfbjtbhsniksnsauinmcoffbyberonxcpsucpacnaopnjfytkbaqpsxvjppjxzcsrlqkufjt\ndkvctjuqhtotnlwkoiaegcbsigoqvfbjtbhsniksnsauinmcoffbyberonxcpsucpacnaopnjfytkbaqpsxvjppjxzcsrlqkufju",
"output": "0"
},
{
"input": "acehlmnssx\nzzzzzzzzzz",
"output": "1814399"
},
{
"input": "acceeffghhijjjklmmoqqqssstuuwwxyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "615090736"
},
{
"input": "aaaabbbcccdeeffffgghhhiiiiijjjjjjjkklllmmnnnnnnooopppqqqqssttuuvvvvwwwxyyzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "56953494"
},
{
"input": "aaaabbbccddddeeeeffffffggggggghhhiijjjjjjjkkkllmmmmmmmmmnnnopppppppqqqqrrrrsssttttuuuuuvvvvvvwwwwwxxxxxyyyyyyyzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "362472550"
}
] | 4,000 | 43,315,200 | 0 | 4,127 |
|
207 | The Beaver's Problem - 3 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set. | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set). | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | [
{
"input": "2000\nJAPAN FEBRUARY MONEY SUPPLY RISES 8.8 PCT\nTOKYO, March 17 - Japan's broadly defined money supply\naverage of M-2 plus certificate of deposits (CDs) rose a\npreliminary 8.8 pct in February from a year earlier, compared\nwith an 8.6 pct rise in January, the Bank of Japan said.\nThe seasonally adjusted February average of M-2 plus CDs\nsupply rose 0.8 pct from January, it said.\nUnadjusted M-2 plus CDs stood at an average 336,000 billion\nyen in February compared with 337,100 billion yen in January.",
"output": "2"
}
] | 31 | 0 | 0 | 4,146 |
|
535 | Tavas and Nafas | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without water again, so right now he's really messed up and can't think.
Your task is to help him by telling him what to type. | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
"input": "40",
"output": "forty"
},
{
"input": "63",
"output": "sixty-three"
},
{
"input": "0",
"output": "zero"
},
{
"input": "1",
"output": "one"
},
{
"input": "2",
"output": "two"
},
{
"input": "8",
"output": "eight"
},
{
"input": "9",
"output": "nine"
},
{
"input": "11",
"output": "eleven"
},
{
"input": "12",
"output": "twelve"
},
{
"input": "13",
"output": "thirteen"
},
{
"input": "14",
"output": "fourteen"
},
{
"input": "16",
"output": "sixteen"
},
{
"input": "17",
"output": "seventeen"
},
{
"input": "18",
"output": "eighteen"
},
{
"input": "19",
"output": "nineteen"
},
{
"input": "21",
"output": "twenty-one"
},
{
"input": "29",
"output": "twenty-nine"
},
{
"input": "30",
"output": "thirty"
},
{
"input": "32",
"output": "thirty-two"
},
{
"input": "38",
"output": "thirty-eight"
},
{
"input": "43",
"output": "forty-three"
},
{
"input": "47",
"output": "forty-seven"
},
{
"input": "50",
"output": "fifty"
},
{
"input": "54",
"output": "fifty-four"
},
{
"input": "56",
"output": "fifty-six"
},
{
"input": "60",
"output": "sixty"
},
{
"input": "66",
"output": "sixty-six"
},
{
"input": "70",
"output": "seventy"
},
{
"input": "76",
"output": "seventy-six"
},
{
"input": "80",
"output": "eighty"
},
{
"input": "82",
"output": "eighty-two"
},
{
"input": "90",
"output": "ninety"
},
{
"input": "91",
"output": "ninety-one"
},
{
"input": "95",
"output": "ninety-five"
},
{
"input": "71",
"output": "seventy-one"
},
{
"input": "46",
"output": "forty-six"
},
{
"input": "84",
"output": "eighty-four"
},
{
"input": "22",
"output": "twenty-two"
},
{
"input": "23",
"output": "twenty-three"
},
{
"input": "24",
"output": "twenty-four"
},
{
"input": "25",
"output": "twenty-five"
},
{
"input": "26",
"output": "twenty-six"
},
{
"input": "28",
"output": "twenty-eight"
},
{
"input": "31",
"output": "thirty-one"
},
{
"input": "33",
"output": "thirty-three"
},
{
"input": "34",
"output": "thirty-four"
},
{
"input": "35",
"output": "thirty-five"
},
{
"input": "36",
"output": "thirty-six"
},
{
"input": "37",
"output": "thirty-seven"
},
{
"input": "39",
"output": "thirty-nine"
},
{
"input": "65",
"output": "sixty-five"
},
{
"input": "68",
"output": "sixty-eight"
},
{
"input": "41",
"output": "forty-one"
},
{
"input": "42",
"output": "forty-two"
},
{
"input": "44",
"output": "forty-four"
},
{
"input": "45",
"output": "forty-five"
},
{
"input": "48",
"output": "forty-eight"
},
{
"input": "49",
"output": "forty-nine"
},
{
"input": "51",
"output": "fifty-one"
},
{
"input": "52",
"output": "fifty-two"
},
{
"input": "53",
"output": "fifty-three"
},
{
"input": "55",
"output": "fifty-five"
},
{
"input": "57",
"output": "fifty-seven"
},
{
"input": "58",
"output": "fifty-eight"
},
{
"input": "59",
"output": "fifty-nine"
},
{
"input": "61",
"output": "sixty-one"
},
{
"input": "62",
"output": "sixty-two"
},
{
"input": "64",
"output": "sixty-four"
},
{
"input": "67",
"output": "sixty-seven"
},
{
"input": "69",
"output": "sixty-nine"
},
{
"input": "72",
"output": "seventy-two"
},
{
"input": "73",
"output": "seventy-three"
},
{
"input": "74",
"output": "seventy-four"
},
{
"input": "75",
"output": "seventy-five"
},
{
"input": "77",
"output": "seventy-seven"
},
{
"input": "78",
"output": "seventy-eight"
},
{
"input": "79",
"output": "seventy-nine"
},
{
"input": "81",
"output": "eighty-one"
},
{
"input": "83",
"output": "eighty-three"
},
{
"input": "85",
"output": "eighty-five"
},
{
"input": "86",
"output": "eighty-six"
},
{
"input": "87",
"output": "eighty-seven"
},
{
"input": "88",
"output": "eighty-eight"
},
{
"input": "89",
"output": "eighty-nine"
},
{
"input": "92",
"output": "ninety-two"
},
{
"input": "93",
"output": "ninety-three"
},
{
"input": "94",
"output": "ninety-four"
},
{
"input": "96",
"output": "ninety-six"
},
{
"input": "7",
"output": "seven"
},
{
"input": "97",
"output": "ninety-seven"
},
{
"input": "98",
"output": "ninety-eight"
},
{
"input": "3",
"output": "three"
},
{
"input": "4",
"output": "four"
},
{
"input": "5",
"output": "five"
}
] | 124 | 307,200 | 3 | 4,167 |
|
464 | The Classic Problem | [
"data structures",
"graphs",
"shortest paths"
] | null | null | You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist. | The first line of the input contains two space-separated integers — *n* and *m* (1<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105).
Next *m* lines contain the description of the graph edges. The *i*-th line contains three space-separated integers — *u**i*, *v**i*, *x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 0<=≤<=*x**i*<=≤<=105). That means that vertices with numbers *u**i* and *v**i* are connected by edge of length 2*x**i* (2 to the power of *x**i*).
The last line contains two space-separated integers — the numbers of vertices *s* and *t*.
The vertices are numbered from 1 to *n*. The graph contains no multiple edges and self-loops. | In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109<=+<=7) if the path exists, and -1 if the path doesn't exist.
If the path exists print in the second line integer *k* — the number of vertices in the shortest path from vertex *s* to vertex *t*; in the third line print *k* space-separated integers — the vertices of the shortest path in the visiting order. The first vertex should be vertex *s*, the last vertex should be vertex *t*. If there are multiple shortest paths, print any of them. | [
"4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n",
"4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n",
"4 2\n1 2 0\n3 4 1\n1 4\n"
] | [
"3\n4\n1 2 3 4 \n",
"112\n4\n1 2 3 4 \n",
"-1\n"
] | A path from vertex *s* to vertex *t* is a sequence *v*<sub class="lower-index">0</sub>, ..., *v*<sub class="lower-index">*k*</sub>, such that *v*<sub class="lower-index">0</sub> = *s*, *v*<sub class="lower-index">*k*</sub> = *t*, and for any *i* from 0 to *k* - 1 vertices *v*<sub class="lower-index">*i*</sub> and *v*<sub class="lower-index">*i* + 1</sub> are connected by an edge.
The length of the path is the sum of weights of edges between *v*<sub class="lower-index">*i*</sub> and *v*<sub class="lower-index">*i* + 1</sub> for all *i* from 0 to *k* - 1.
The shortest path from *s* to *t* is the path which length is minimum among all possible paths from *s* to *t*. | [] | 5,000 | 3,584,000 | 0 | 4,168 |
|
686 | Little Robber Girl's Zoo | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers *l* and *r* such that *r*<=-<=*l*<=+<=1 is even. After that animals that occupy positions between *l* and *r* inclusively are rearranged as follows: the animal at position *l* swaps places with the animal at position *l*<=+<=1, the animal *l*<=+<=2 swaps with the animal *l*<=+<=3, ..., finally, the animal at position *r*<=-<=1 swaps with the animal *r*.
Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20<=000 segments, since otherwise the robber girl will become bored and will start scaring the animals again. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — number of animals in the robber girl's zoo.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the height of the animal occupying the *i*-th place. | Print the sequence of operations that will rearrange the animals by non-decreasing height.
The output should contain several lines, *i*-th of the lines should contain two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed.
The number of operations should not exceed 20<=000.
If the animals are arranged correctly from the start, you are allowed to output nothing. | [
"4\n2 1 4 3\n",
"7\n36 28 57 39 66 69 68\n",
"5\n1 2 1 2 1\n"
] | [
"1 4\n",
"1 4\n6 7\n",
"2 5\n3 4\n1 4\n1 4\n"
] | Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed. | [
{
"input": "4\n2 1 4 3",
"output": "1 2\n3 4"
},
{
"input": "7\n36 28 57 39 66 69 68",
"output": "1 2\n3 4\n6 7"
},
{
"input": "5\n1 2 1 2 1",
"output": "2 3\n4 5\n3 4"
},
{
"input": "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 42 42 48 46 49 49 58 50 60 58 65 61 68 66 69 69 69 69 70 69 71 71 77 73 78 77 80 79 85 83 86 86 86 86 88 87 91 90 96 91 98 97 99 98",
"output": "1 2\n5 6\n7 8\n9 10\n11 12\n19 20\n21 22\n23 24\n33 34\n37 38\n41 42\n43 44\n45 46\n47 48\n53 54\n57 58\n59 60\n61 62\n63 64\n69 70\n71 72\n73 74\n75 76\n77 78"
},
{
"input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 77\n77 78\n78 79\n79 80\n80 81\n81 82\n82 83\n83 84\n84 85\n85 86\n86 87\n87 88\n88 89\n89 90\n90 91\n91 92\n92 93\n..."
},
{
"input": "99\n4577 4577 4576 4576 4576 4576 4576 4576 4576 4576 4576 4576 4576 4575 4575 4575 4575 4575 4575 4574 4574 4574 4574 4574 4574 4574 4574 4574 4574 4573 4573 4573 4573 4573 4573 4573 4573 4573 4573 4573 4573 4572 4572 4572 4572 4572 4572 4572 4572 4572 4572 4572 4571 4571 4571 4571 4571 4571 4571 4571 4571 4570 4570 4570 4570 4570 4570 4570 4569 4569 4569 4569 4569 4569 4569 4569 4569 4569 4569 4568 4568 4568 4568 4568 4568 4568 4568 4568 4568 4568 4567 4567 4567 4567 4567 4567 4567 4567 4567",
"output": "2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 77\n7..."
},
{
"input": "10\n44 23 65 17 48 29 49 88 91 85",
"output": "1 2\n3 4\n4 5\n5 6\n6 7\n9 10\n2 3\n4 5\n8 9\n1 2\n3 4"
},
{
"input": "13\n605297997 425887240 859639341 200428931 888317166 983420497 81642057 628988722 389959969 358920886 646428392 324912711 401437250",
"output": "1 2\n3 4\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n2 3\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n1 2\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n3 4\n5 6\n6 7\n8 9\n9 10\n2 3\n4 5\n5 6\n7 8\n8 9\n1 2\n3 4\n4 5\n6 7\n7 8\n3 4\n5 6\n6 7\n4 5\n3 4"
},
{
"input": "43\n644870843 160471908 227474511 47341477 175939701 563067024 749818136 707986934 201095131 736488829 346428456 342944986 316696712 101551423 672610101 897020945 708299245 587795677 408207112 985104524 278945228 192250326 157154304 301319412 270702270 954096281 649990285 37649442 300182190 382249227 605285302 392816037 419998044 84624133 332174228 996770879 816912092 283973844 498255316 374935144 294452244 529912248 553039417",
"output": "1 2\n2 3\n3 4\n4 5\n5 6\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n16 17\n17 18\n18 19\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n2 3\n3 4\n7 8\n9 10\n10 11\n11 12\n12 13\n13 14\n15 16\n16 17\n17 18\n19 20\n20 21\n21 22\n22 23\n23 24\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n1 2\n6 7\n8 9\n9 10\n10 11\n11 12\n12 13\n1..."
},
{
"input": "97\n1 1 1 2 1 1 1 2 1 1 1 1 1 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 1 1 2 1 1 1 1 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 1 2 1 1 2 2 2 1 2 2 1 1 2 2 2 1 1 2 1 2 1 1 2",
"output": "4 5\n5 6\n6 7\n8 9\n9 10\n10 11\n11 12\n12 13\n20 21\n22 23\n26 27\n28 29\n34 35\n35 36\n37 38\n38 39\n39 40\n40 41\n42 43\n44 45\n48 49\n58 59\n59 60\n60 61\n63 64\n64 65\n66 67\n67 68\n68 69\n69 70\n72 73\n74 75\n76 77\n77 78\n81 82\n84 85\n85 86\n89 90\n90 91\n92 93\n94 95\n95 96\n7 8\n8 9\n9 10\n10 11\n11 12\n19 20\n21 22\n25 26\n27 28\n33 34\n34 35\n36 37\n37 38\n38 39\n39 40\n41 42\n43 44\n47 48\n57 58\n58 59\n59 60\n62 63\n63 64\n65 66\n66 67\n67 68\n68 69\n71 72\n73 74\n75 76\n76 77\n80 81\n83 84\n..."
},
{
"input": "87\n2 2 1 2 3 1 3 2 3 2 3 3 1 3 3 3 2 2 1 1 2 3 2 1 2 2 3 3 1 1 1 3 2 3 1 2 1 3 3 3 3 3 3 2 3 2 3 3 2 1 1 3 1 1 3 3 2 3 1 1 3 3 3 2 3 1 3 2 2 2 1 3 3 3 1 1 2 3 2 3 2 1 3 3 3 1 3",
"output": "2 3\n5 6\n7 8\n9 10\n12 13\n16 17\n17 18\n18 19\n19 20\n20 21\n22 23\n23 24\n24 25\n25 26\n28 29\n29 30\n30 31\n32 33\n34 35\n35 36\n36 37\n43 44\n45 46\n48 49\n49 50\n50 51\n52 53\n53 54\n56 57\n58 59\n59 60\n63 64\n65 66\n67 68\n68 69\n69 70\n70 71\n74 75\n75 76\n76 77\n78 79\n80 81\n81 82\n85 86\n1 2\n4 5\n6 7\n8 9\n11 12\n15 16\n16 17\n17 18\n18 19\n19 20\n21 22\n22 23\n23 24\n24 25\n27 28\n28 29\n29 30\n31 32\n33 34\n34 35\n35 36\n42 43\n44 45\n47 48\n48 49\n49 50\n51 52\n52 53\n55 56\n57 58\n58 59\n6..."
},
{
"input": "100\n3 2 5 4 3 3 3 3 4 3 1 2 3 2 3 1 4 1 5 2 5 3 3 5 2 3 5 4 3 4 1 5 5 2 2 1 3 5 1 3 5 2 2 1 4 3 1 3 5 1 1 3 5 5 5 4 5 5 1 5 3 5 4 3 5 4 1 1 2 1 2 5 1 2 2 2 3 5 5 5 4 2 3 2 1 2 3 5 2 2 2 2 5 3 5 4 2 5 3 4",
"output": "1 2\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n19 20\n21 22\n22 23\n24 25\n25 26\n27 28\n28 29\n29 30\n30 31\n33 34\n34 35\n35 36\n36 37\n38 39\n39 40\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n49 50\n50 51\n51 52\n55 56\n58 59\n60 61\n62 63\n63 64\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n72 73\n73 74\n74 75\n75 76\n76 77\n80 81\n81 82\n82 83\n83 84\n84 85\n85 86\n86 87\n88 89\n89 90\n90 91\n91 92\n93 94\n95 96\n96 97\n98 99\n99 100\n3 4\n4 5\n5 6\n..."
},
{
"input": "100\n245 230 240 248 247 235 240 228 247 243 244 240 246 234 244 247 247 232 247 233 241 247 236 247 230 228 243 237 246 231 246 231 233 235 229 244 247 248 245 248 231 230 238 247 235 248 240 239 233 232 230 229 229 244 247 246 248 247 247 234 243 242 247 228 238 238 236 243 236 228 229 245 232 246 241 243 248 235 242 237 244 239 238 245 231 235 234 237 238 237 234 232 231 236 233 238 228 243 242 246",
"output": "1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n38 39\n40 41\n41 42\n42 43\n43 44\n44 45\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n77 78\n78 79\n79 80\n80 81\n81 82\n8..."
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 77\n77 78\n78 79\n79 80\n80 81\n81 82\n82 83\n83 84\n84 85\n85 86\n86 87\n87 88\n88 89\n89 90\n90 91\n91 92\n92 93\n93 94\n94 95\n95 96\n96 97\n97 98\n98 99\n99 100\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n..."
},
{
"input": "98\n5 5 5 5 5 5 5 6 6 6 6 7 6 7 7 7 7 7 7 8 8 8 8 8 8 9 8 9 9 9 9 10 9 10 9 11 10 11 11 11 11 12 12 12 12 12 12 12 12 13 13 13 13 13 13 14 14 14 14 14 14 14 15 15 15 15 15 15 15 16 16 16 16 17 17 17 17 17 17 18 17 18 18 18 19 19 19 19 19 20 19 20 20 20 20 20 20 20",
"output": "12 13\n26 27\n32 33\n34 35\n36 37\n80 81\n90 91\n33 34"
},
{
"input": "20\n2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2",
"output": "6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11"
}
] | 140 | 4,300,800 | 3 | 4,173 |
|
761 | Dasha and friends | [
"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. | [
{
"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"
}
] | 46 | 4,608,000 | 0 | 4,181 |
|
253 | Text Editor | [
"data structures",
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, but none — in writing a composition.
As Vasya was fishing for a sentence in the dark pond of his imagination, he suddenly wondered: what is the least number of times he should push a key to shift the cursor from one position to another one?
Let's describe his question more formally: to type a text, Vasya is using the text editor. He has already written *n* lines, the *i*-th line contains *a**i* characters (including spaces). If some line contains *k* characters, then this line overall contains (*k*<=+<=1) positions where the cursor can stand: before some character or after all characters (at the end of the line). Thus, the cursor's position is determined by a pair of integers (*r*,<=*c*), where *r* is the number of the line and *c* is the cursor's position in the line (the positions are indexed starting from one from the beginning of the line).
Vasya doesn't use the mouse to move the cursor. He uses keys "Up", "Down", "Right" and "Left". When he pushes each of these keys, the cursor shifts in the needed direction. Let's assume that before the corresponding key is pressed, the cursor was located in the position (*r*,<=*c*), then Vasya pushed key:
- "Up": if the cursor was located in the first line (*r*<==<=1), then it does not move. Otherwise, it moves to the previous line (with number *r*<=-<=1), to the same position. At that, if the previous line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=-<=1;- "Down": if the cursor was located in the last line (*r*<==<=*n*), then it does not move. Otherwise, it moves to the next line (with number *r*<=+<=1), to the same position. At that, if the next line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=+<=1;- "Right": if the cursor can move to the right in this line (*c*<=<<=*a**r*<=+<=1), then it moves to the right (to position *c*<=+<=1). Otherwise, it is located at the end of the line and doesn't move anywhere when Vasya presses the "Right" key;- "Left": if the cursor can move to the left in this line (*c*<=><=1), then it moves to the left (to position *c*<=-<=1). Otherwise, it is located at the beginning of the line and doesn't move anywhere when Vasya presses the "Left" key.
You've got the number of lines in the text file and the number of characters, written in each line of this file. Find the least number of times Vasya should push the keys, described above, to shift the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2). | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the file. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105), separated by single spaces. The third line contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*r*2<=≤<=*n*,<=1<=≤<=*c*1<=≤<=*a**r*1<=+<=1,<=1<=≤<=*c*2<=≤<=*a**r*2<=+<=1). | Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2). | [
"4\n2 1 6 4\n3 4 4 2\n",
"4\n10 5 6 4\n1 11 4 2\n",
"3\n10 1 10\n1 10 1 1\n"
] | [
"3\n",
"6\n",
"3\n"
] | In the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter *s* represents the cursor's initial position, letter *t* represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.
123
12
123s567
1t345
One of the possible answers in the given sample is: "Left", "Down", "Left". | [
{
"input": "4\n2 1 6 4\n3 4 4 2",
"output": "3"
},
{
"input": "4\n10 5 6 4\n1 11 4 2",
"output": "6"
},
{
"input": "3\n10 1 10\n1 10 1 1",
"output": "3"
},
{
"input": "4\n2 1 6 4\n4 2 3 5",
"output": "4"
},
{
"input": "3\n20 3 20\n1 20 1 1",
"output": "5"
},
{
"input": "2\n10 1\n1 3 2 1",
"output": "2"
},
{
"input": "20\n3 1 9 9 6 1 3 4 5 6 7 3 1 9 9 1 9 1 5 7\n17 7 19 5",
"output": "5"
},
{
"input": "20\n81 90 11 68 23 18 78 75 45 86 58 37 21 15 98 40 53 100 10 70\n11 55 8 19",
"output": "7"
},
{
"input": "25\n55 47 5 63 55 11 8 32 0 62 41 7 17 70 33 6 41 68 37 82 33 64 28 33 12\n6 11 14 12",
"output": "19"
},
{
"input": "30\n77 38 82 87 88 1 90 3 79 69 64 36 85 12 1 19 80 89 75 56 49 28 10 31 37 65 27 84 10 72\n26 65 19 3",
"output": "15"
},
{
"input": "100\n119 384 220 357 394 123 371 57 6 221 219 79 305 292 71 113 428 326 166 235 120 404 77 223 2 171 81 1 119 307 200 323 89 294 178 421 125 197 89 154 335 46 210 311 216 182 246 262 195 99 175 153 310 302 417 167 222 349 63 325 175 345 6 78 9 147 126 308 229 295 175 368 230 116 95 254 443 15 299 265 322 171 179 184 435 115 384 324 213 359 414 159 322 49 209 296 376 173 369 302\n8 47 23 65",
"output": "73"
},
{
"input": "100\n120 336 161 474 285 126 321 63 82 303 421 110 143 279 505 231 40 413 20 421 271 30 465 186 495 156 225 445 530 156 516 305 360 261 123 5 50 377 124 8 115 529 395 408 271 166 121 240 336 348 352 359 487 471 171 379 381 182 109 425 252 434 131 430 461 386 33 189 481 461 163 89 374 505 525 526 132 468 80 88 90 538 280 281 552 415 194 41 333 296 297 205 40 79 22 219 108 213 158 410\n58 119 82 196",
"output": "186"
},
{
"input": "100\n9 8 5 2 10 6 10 10 1 9 8 5 0 9 1 6 6 2 3 9 9 3 2 7 2 7 8 10 6 6 2 8 5 0 0 8 7 3 0 4 7 5 9 0 3 6 9 6 5 0 4 9 4 7 7 1 5 8 2 4 10 3 9 8 10 6 10 7 4 9 0 1 3 6 6 2 1 1 5 7 0 9 6 0 4 6 8 4 7 6 1 9 4 3 10 9 7 0 0 7\n72 2 87 2",
"output": "16"
},
{
"input": "100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44\n6 76 89 15",
"output": "97"
},
{
"input": "100\n176 194 157 24 27 153 31 159 196 85 127 114 142 39 133 4 44 36 141 96 80 40 120 16 88 29 157 136 158 98 145 152 19 40 106 116 19 195 184 70 72 95 78 146 199 1 103 3 120 71 52 77 160 148 24 156 108 64 86 124 103 97 108 66 107 126 29 172 23 106 29 69 64 90 9 171 59 85 1 63 79 50 136 21 115 164 30 115 86 26 25 6 128 48 122 14 198 88 182 117\n71 4 85 80",
"output": "92"
},
{
"input": "100\n1622 320 1261 282 1604 57 1427 1382 904 911 1719 1682 984 1727 1301 1799 1110 1057 248 764 1642 1325 1172 1677 182 32 665 397 1146 73 412 554 973 874 774 1948 1676 1959 518 280 1467 568 613 760 594 252 224 1359 876 253 760 1566 929 1614 940 1079 288 245 1432 1647 1534 1768 1947 733 225 495 1239 644 124 522 1859 1856 1464 485 1962 131 1693 1622 242 1119 1290 538 998 1342 791 711 809 1407 1369 414 124 758 1104 1142 355 324 665 1155 551 1611\n36 1383 51 21",
"output": "47"
},
{
"input": "50\n966 151 777 841 507 884 487 813 29 230 966 819 390 482 137 365 391 693 56 756 327 500 895 22 361 619 8 516 21 770 572 53 497 682 162 32 308 309 110 470 699 318 947 658 720 679 435 645 481 42\n45 510 25 48",
"output": "59"
},
{
"input": "50\n4143 2907 2028 539 3037 1198 6597 3658 972 9809 854 4931 642 3170 9777 2992 7121 8094 6634 684 5580 4684 3397 7909 3908 3822 2137 8299 8146 2105 7578 4338 7363 8237 530 301 4566 1153 4795 5342 3257 6953 4401 8311 9977 9260 7019 7705 5416 6754\n21 3413 23 218",
"output": "112"
},
{
"input": "50\n8974 13208 81051 72024 84908 49874 22875 64935 27340 38682 28512 43441 78752 83458 63344 5723 83425 54009 61980 7824 59956 43184 49274 3896 44079 67313 68565 9138 55087 68458 43009 3685 22879 85032 84273 93643 64957 73428 57016 33405 85961 47708 90325 1352 1551 20935 76821 75406 59309 40757\n14 45232 2 6810",
"output": "1102"
},
{
"input": "100\n34 80 42 99 7 49 109 61 20 7 92 2 62 96 65 77 70 5 16 83 99 39 88 66 106 1 80 68 71 74 28 75 19 97 38 100 30 1 55 86 3 13 61 82 72 50 68 18 77 89 96 27 26 35 46 13 83 77 40 31 85 108 15 5 40 80 1 108 44 18 66 26 46 7 36 80 34 76 17 9 23 57 109 90 88 1 54 66 71 94 6 89 50 22 93 82 32 74 41 74\n91 7 56 3",
"output": "36"
},
{
"input": "100\n156 150 75 72 205 133 139 99 212 82 58 104 133 88 46 157 49 179 32 72 159 188 42 47 36 58 127 215 125 115 209 118 109 11 62 159 110 151 92 202 203 25 44 209 153 8 199 168 126 34 21 106 31 40 48 212 106 0 131 166 2 126 13 126 103 44 2 66 33 25 194 41 37 198 199 6 22 1 161 16 95 11 198 198 166 145 214 159 143 2 181 130 159 118 176 165 192 178 42 168\n49 12 66 23",
"output": "39"
},
{
"input": "100\n289 16 321 129 0 121 61 86 93 5 63 276 259 144 275 236 309 257 244 138 107 18 158 14 295 162 7 113 58 101 142 196 181 329 115 109 62 237 110 87 19 205 68 257 252 0 166 45 310 244 140 251 262 315 213 206 290 128 287 230 198 83 135 40 8 273 319 295 288 274 34 260 288 252 172 129 201 110 294 111 95 180 34 98 16 188 170 40 274 153 11 159 245 51 328 290 112 11 105 182\n99 53 21 77",
"output": "154"
},
{
"input": "10\n11284 10942 14160 10062 1858 6457 1336 13842 5498 4236\n1 7123 5 664",
"output": "681"
},
{
"input": "53\n29496 9630 10781 25744 28508 15670 8252 14284 25995 20215 24251 14240 1370 15724 28268 30377 4839 16791 33515 23776 24252 1045 15245 12839 17531 28591 13091 27339 23361 10997 30438 26977 26789 18402 32938 2106 26599 10733 29549 9760 31507 33572 16934 7273 26477 15040 23704 19905 1941 3861 5950 1265 34\n11 6571 1 3145",
"output": "1788"
},
{
"input": "31\n14324 29226 58374 19956 61695 71586 13261 11436 58443 34879 12689 62786 68194 34303 99201 67616 51364 67539 56799 60130 22021 64546 28331 75746 45036 43950 2150 61718 33030 37781 34319\n24 57393 7 6152",
"output": "4024"
},
{
"input": "23\n5397 13279 11741 20182 18311 20961 16720 11864 2486 14081 15637 16216 3736 437 16346 12449 20205 10949 14237 2213 15281 15271 19138\n5 11479 13 68",
"output": "380"
},
{
"input": "40\n41997 20736 34699 73866 45509 41964 36050 16673 10454 21166 28306 69335 6172 65943 78569 16794 10439 68061 40392 52510 78248 63851 45294 49929 22580 5574 40993 18334 73897 59148 47727 76645 4280 23651 58772 64500 13704 60366 37099 20336\n14 29991 16 11904",
"output": "1468"
},
{
"input": "16\n922 7593 4748 4103 7672 6001 1573 3973 8524 8265 4747 3202 4796 2637 889 9359\n12 2165 12 1654",
"output": "90"
},
{
"input": "18\n22746 9084 3942 1120 25391 25307 7409 1189 23473 26175 10964 13584 5541 500 24338 12272 15824 27656\n3 1395 12 90",
"output": "424"
},
{
"input": "45\n2286 4425 14666 34959 10792 3723 30132 34266 18100 22813 28627 23310 33911 27285 1211 993 15526 4751 13611 21400 25712 24437 27435 34808 33950 18373 33685 23487 5444 10249 21415 16368 35398 7889 30918 19940 1552 12164 34292 13922 10011 31377 24102 34539 11992\n20 21252 28 2058",
"output": "531"
},
{
"input": "29\n56328 80183 27682 79083 60680 12286 34299 8015 51808 50756 82133 45930 43695 65863 25178 70825 2288 15111 39667 39637 11453 62821 81484 84216 54524 53749 8396 67712 76146\n13 10739 9 3622",
"output": "1345"
},
{
"input": "46\n67864 68218 3593 30646 66413 65542 65322 26801 28984 61330 15247 16522 39142 14013 49272 41585 56739 6881 44227 7101 57657 21121 51857 39351 13500 71528 8488 66118 14756 43923 21284 20018 49049 60198 6181 62460 44141 55828 42636 14623 59758 68321 12192 29978 24745 16467\n27 5545 4 3766",
"output": "197"
},
{
"input": "70\n53691 15034 17444 13375 23285 29211 24567 21643 45514 10290 70111 24541 25072 5365 12162 34564 27535 48253 39581 13468 33718 35105 30468 50214 53365 74800 16749 33935 36346 54230 73796 26826 27866 41887 67566 40813 32267 58821 56828 26439 23708 32335 69515 33825 6092 20510 50174 11129 4592 74116 21498 77951 48056 28554 43904 21885 5967 40253 4990 70029 34374 41201 25399 6101 10354 61833 43646 20534 371 11111\n21 3911 45 1755",
"output": "1455"
},
{
"input": "10\n8121 10681 10179 10221 9410 5214 19040 17893 7862 4611\n7 7780 7 3369",
"output": "1249"
},
{
"input": "2\n1 2\n1 1 1 1",
"output": "0"
},
{
"input": "3\n1 10 20\n2 10 3 1",
"output": "4"
}
] | 186 | 409,600 | 0 | 4,182 |
|
234 | Lefthanders and Righthanders | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
{
"input": "10\nRLLRLRRRLL",
"output": "1 6\n2 7\n3 8\n9 4\n5 10"
},
{
"input": "12\nLRRRRRLRRRRL",
"output": "1 7\n2 8\n3 9\n4 10\n5 11\n12 6"
},
{
"input": "14\nRLLRLLLLRLLLRL",
"output": "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14"
},
{
"input": "16\nLLLRRRLRRLLRRLLL",
"output": "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8"
},
{
"input": "18\nRRRLLLLRRRLRLRLLRL",
"output": "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9"
},
{
"input": "20\nRLRLLRLRRLLRRRRRRLRL",
"output": "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20"
},
{
"input": "22\nRLLLRLLLRRLRRRLRLLLLLL",
"output": "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22"
},
{
"input": "24\nLRRRLRLLRLRRRRLLLLRRLRLR",
"output": "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24"
},
{
"input": "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR",
"output": "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26"
},
{
"input": "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL",
"output": "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14"
},
{
"input": "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL",
"output": "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30"
},
{
"input": "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR",
"output": "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32"
},
{
"input": "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR",
"output": "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34"
},
{
"input": "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL",
"output": "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18"
},
{
"input": "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL",
"output": "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38"
},
{
"input": "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL",
"output": "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40"
},
{
"input": "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR",
"output": "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42"
},
{
"input": "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR",
"output": "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44"
},
{
"input": "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL",
"output": "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46"
},
{
"input": "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL",
"output": "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50"
},
{
"input": "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52"
},
{
"input": "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54"
},
{
"input": "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56"
},
{
"input": "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL",
"output": "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58"
},
{
"input": "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL",
"output": "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60"
},
{
"input": "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR",
"output": "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62"
},
{
"input": "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL",
"output": "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64"
},
{
"input": "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR",
"output": "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66"
},
{
"input": "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL",
"output": "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34"
},
{
"input": "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70"
},
{
"input": "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72"
},
{
"input": "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74"
},
{
"input": "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76"
},
{
"input": "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78"
},
{
"input": "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL",
"output": "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80"
},
{
"input": "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR",
"output": "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82"
},
{
"input": "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR",
"output": "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84"
},
{
"input": "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR",
"output": "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86"
},
{
"input": "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR",
"output": "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88"
},
{
"input": "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90"
},
{
"input": "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92"
},
{
"input": "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94"
},
{
"input": "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96"
},
{
"input": "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98"
},
{
"input": "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100"
},
{
"input": "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL",
"output": "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100"
},
{
"input": "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50"
},
{
"input": "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR",
"output": "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100"
},
{
"input": "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR",
"output": "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR",
"output": "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100"
},
{
"input": "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50"
}
] | 46 | 6,656,000 | -1 | 4,186 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.