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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
965 | Battleship | [
"implementation"
] | null | null | Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship. | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship). | Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell. | [
"4 3\n#..#\n#.#.\n....\n.###\n",
"10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n",
"19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#\n"
] | [
"3 2\n",
"6 1\n",
"1 8\n"
] | The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | [
{
"input": "4 3\n#..#\n#.#.\n....\n.###",
"output": "3 2"
},
{
"input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#",
"output": "6 1"
},
{
"input": "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#",
"output": "1 8"
},
{
"input": "10 4\n##..######\n#...######\n#...######\n#......###\n#.......##\n.##.######\n.##.######\n.##.######\n.#....####\n....######",
"output": "4 4"
},
{
"input": "1 1\n.",
"output": "1 1"
},
{
"input": "1 1\n#",
"output": "1 1"
},
{
"input": "5 2\n..##.\n.###.\n#####\n#####\n..#..",
"output": "1 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n.####\n..#..",
"output": "5 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n####.\n..#..",
"output": "5 5"
},
{
"input": "5 2\n.##..\n.###.\n#####\n#####\n..#..",
"output": "1 5"
},
{
"input": "2 2\n##\n##",
"output": "1 1"
},
{
"input": "4 1\n####\n####\n####\n###.",
"output": "4 4"
},
{
"input": "2 2\n#.\n.#",
"output": "1 1"
},
{
"input": "3 3\n###\n##.\n###",
"output": "1 1"
},
{
"input": "4 4\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "4 3\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "3 1\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 2\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 3\n.#.\n#.#\n.#.",
"output": "1 1"
}
] | 170 | 0 | 0 | 1,135 |
|
931 | Friends Meeting | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"input": "1000\n999",
"output": "1"
},
{
"input": "1000\n1",
"output": "250000"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n999",
"output": "249001"
},
{
"input": "2\n998",
"output": "248502"
},
{
"input": "999\n2",
"output": "249001"
},
{
"input": "998\n2",
"output": "248502"
},
{
"input": "2\n1000",
"output": "249500"
},
{
"input": "1000\n2",
"output": "249500"
},
{
"input": "1\n999",
"output": "249500"
},
{
"input": "999\n1",
"output": "249500"
},
{
"input": "188\n762",
"output": "82656"
},
{
"input": "596\n777",
"output": "8281"
},
{
"input": "773\n70",
"output": "123904"
},
{
"input": "825\n729",
"output": "2352"
},
{
"input": "944\n348",
"output": "89102"
},
{
"input": "352\n445",
"output": "2209"
},
{
"input": "529\n656",
"output": "4096"
},
{
"input": "19\n315",
"output": "22052"
},
{
"input": "138\n370",
"output": "13572"
},
{
"input": "546\n593",
"output": "576"
},
{
"input": "285\n242",
"output": "484"
},
{
"input": "773\n901",
"output": "4160"
},
{
"input": "892\n520",
"output": "34782"
},
{
"input": "864\n179",
"output": "117649"
},
{
"input": "479\n470",
"output": "25"
},
{
"input": "967\n487",
"output": "57840"
},
{
"input": "648\n106",
"output": "73712"
},
{
"input": "58\n765",
"output": "125316"
},
{
"input": "235\n56",
"output": "8100"
},
{
"input": "285\n153",
"output": "4422"
},
{
"input": "943\n13",
"output": "216690"
},
{
"input": "675\n541",
"output": "4556"
},
{
"input": "4\n912",
"output": "206570"
}
] | 124 | 0 | 3 | 1,136 |
|
475 | Bayan Bus | [
"implementation"
] | null | null | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.
In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by *k* participants. Your task is to draw the figure representing occupied seats. | The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants. | Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters. | [
"9\n",
"20\n"
] | [
"+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+\n"
] | none | [
{
"input": "9",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "20",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "30",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "5",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "0",
"output": "+------------------------+\n|#.#.#.#.#.#.#.#.#.#.#.|D|)\n|#.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "1",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|#.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "2",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|#.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "3",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "4",
"output": "+------------------------+\n|O.#.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "6",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "7",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "8",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "10",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "11",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "12",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.#.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "13",
"output": "+------------------------+\n|O.O.O.O.#.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "14",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "15",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.#.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "16",
"output": "+------------------------+\n|O.O.O.O.O.#.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "17",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "18",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.#.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "19",
"output": "+------------------------+\n|O.O.O.O.O.O.#.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "21",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "22",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "23",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "24",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.#.#.#.#.|.|)\n+------------------------+"
},
{
"input": "25",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.#.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "26",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "27",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.#.#.#.|.|)\n+------------------------+"
},
{
"input": "28",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.#.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "29",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+"
},
{
"input": "31",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "32",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "33",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.O.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.#.|.|)\n+------------------------+"
},
{
"input": "34",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.O.|D|)\n|O.O.O.O.O.O.O.O.O.O.O.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.O.O.|.|)\n+------------------------+"
}
] | 15 | 0 | 0 | 1,138 |
|
91 | Newspaper Headline | [
"greedy",
"strings"
] | A. Newspaper Headline | 2 | 256 | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new word *s*2. It is considered that when Fangy erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.
For example, the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac".
Which least number of newspaper headings *s*1 will Fangy need to glue them, erase several letters and get word *s*2? | The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=≤<=|*s*1|<=≤<=104,<=1<=≤<=|*s*2|<=≤<=106). | If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2. | [
"abc\nxyz\n",
"abcd\ndabc\n"
] | [
"-1\n",
"2\n"
] | none | [
{
"input": "abc\nxyz",
"output": "-1"
},
{
"input": "abcd\ndabc",
"output": "2"
},
{
"input": "ab\nbabaaab",
"output": "5"
},
{
"input": "ab\nbaaabba",
"output": "6"
},
{
"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb",
"output": "-1"
},
{
"input": "ibifgcfdbfdhihbifageaaadegbfbhgeebgdgiafgedchdg\ndedfebcfdigdefdediigcfcafbhhiacgfbeccfchd",
"output": "7"
},
{
"input": "fcagdciidcedeaicgfffgjefaefaachfbfj\naiecchjehdgbjfcdjdefgfhiddjajeddiigidaibejabd",
"output": "11"
},
{
"input": "ehfjaabjfedhddejjfcfijagefhjeahjcddhchahjbagi\nfbfdjbjhibjgjgaaajgdbcfdbhjcajcbbieijhcjgajhgaa",
"output": "10"
},
{
"input": "ifjcedhjhdjhbiaededfefagigggcebfaebf\ngeibbffgeefbaghdbfidbbhabdbdgej",
"output": "9"
},
{
"input": "eidfdfbbgjigghaddbjhcbdechecgghjgfjjcajjhaghdhd\nfcgecaefhgjjegbhjeaffcabifihhcadaibhi",
"output": "11"
}
] | 92 | 0 | 0 | 1,140 |
940 | Phone Numbers | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed that the answer exists.
Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}.
String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=<<=*q**i* and for all *j*<=<<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. | The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters. | Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists. | [
"3 3\nabc\n",
"3 2\nabc\n",
"3 3\nayy\n",
"2 3\nba\n"
] | [
"aca\n",
"ac\n",
"yaa\n",
"baa\n"
] | In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. | [
{
"input": "3 3\nabc",
"output": "aca"
},
{
"input": "3 2\nabc",
"output": "ac"
},
{
"input": "3 3\nayy",
"output": "yaa"
},
{
"input": "2 3\nba",
"output": "baa"
},
{
"input": "1 3\nf",
"output": "fff"
},
{
"input": "3 1\nazz",
"output": "z"
},
{
"input": "3 3\nzbf",
"output": "zbz"
},
{
"input": "2 3\ngi",
"output": "gig"
},
{
"input": "3 2\nyzy",
"output": "zy"
},
{
"input": "5 10\nkekff",
"output": "kekffeeeee"
},
{
"input": "10 5\nhqqqqcdddb",
"output": "qbbbb"
},
{
"input": "10 10\nmrfkcsxcuj",
"output": "mrfkcsxcuk"
},
{
"input": "10 3\nggjnohlepu",
"output": "ggl"
},
{
"input": "8 9\npppppppp",
"output": "ppppppppp"
},
{
"input": "10 7\nffffffffyf",
"output": "ffffffy"
},
{
"input": "10 2\nkmiejhcimj",
"output": "mc"
},
{
"input": "10 1\ngiwekrmngf",
"output": "i"
},
{
"input": "8 8\nlolololo",
"output": "lololool"
},
{
"input": "10 9\nbcegikmyyy",
"output": "bcegikybb"
},
{
"input": "7 5000\nqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq..."
},
{
"input": "3 99948\nttt",
"output": "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt..."
}
] | 139 | 30,208,000 | 3 | 1,142 |
|
49 | Sleuth | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
"output": "NO"
},
{
"input": "sZecYdUvZHrXx?",
"output": "NO"
},
{
"input": "uMtXK?",
"output": "NO"
},
{
"input": "U?",
"output": "YES"
},
{
"input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?",
"output": "NO"
},
{
"input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?",
"output": "NO"
},
{
"input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?",
"output": "NO"
},
{
"input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?",
"output": "NO"
},
{
"input": "YhCuZnrWUBEed?",
"output": "NO"
},
{
"input": "hh?",
"output": "NO"
},
{
"input": "whU?",
"output": "YES"
},
{
"input": "fgwg?",
"output": "NO"
},
{
"input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?",
"output": "NO"
},
{
"input": "n?",
"output": "NO"
},
{
"input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?",
"output": "NO"
},
{
"input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?",
"output": "NO"
},
{
"input": " J ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " o ?",
"output": "YES"
},
{
"input": " T ?",
"output": "NO"
},
{
"input": " q ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " c ?",
"output": "NO"
},
{
"input": " B ?",
"output": "NO"
},
{
"input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?",
"output": "YES"
},
{
"input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?",
"output": "YES"
},
{
"input": "wGsfZCSwN PEUhNUrLfABrxA?",
"output": "YES"
},
{
"input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?",
"output": "YES"
},
{
"input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?",
"output": "YES"
},
{
"input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?",
"output": "YES"
},
{
"input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?",
"output": "YES"
}
] | 186 | 0 | 0 | 1,143 |
1,011 | Planning The Expedition | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above? | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package. | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "4 100\n84 99 66 69 86 94 89 96 98 93 93 82 87 93 91 100 69 99 93 81 99 84 75 100 86 88 98 100 84 96 44 70 94 91 85 78 86 79 45 88 91 78 98 94 81 87 93 72 96 88 96 97 96 62 86 72 94 84 80 98 88 90 93 73 73 98 78 50 91 96 97 82 85 90 87 41 97 82 97 77 100 100 92 83 98 81 70 81 74 78 84 79 98 98 55 99 97 99 79 98",
"output": "5"
},
{
"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": "1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "6 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "15"
},
{
"input": "1 1\n59",
"output": "1"
},
{
"input": "1 50\n39 1 46 21 23 28 100 32 63 63 18 15 40 29 34 49 56 74 47 42 96 97 59 62 76 62 69 61 36 21 66 18 92 58 63 85 5 6 77 75 91 66 38 10 66 43 20 74 37 83",
"output": "3"
},
{
"input": "1 100\n83 72 21 55 49 5 61 60 87 21 89 88 3 75 49 81 36 25 50 61 96 19 36 55 48 8 97 69 50 24 23 39 26 25 41 90 69 20 19 62 38 52 60 6 66 31 9 45 36 12 69 94 22 60 91 65 35 58 13 85 33 87 83 11 95 20 20 85 13 21 57 69 17 94 78 37 59 45 60 7 64 51 60 89 91 22 6 58 95 96 51 53 89 22 28 16 27 56 1 54",
"output": "5"
},
{
"input": "50 1\n75",
"output": "0"
},
{
"input": "50 50\n85 20 12 73 52 78 70 95 88 43 31 88 81 41 80 99 16 11 97 11 21 44 2 34 47 38 87 2 32 47 97 93 52 14 35 37 97 48 58 19 52 55 97 72 17 25 16 85 90 58",
"output": "1"
},
{
"input": "50 100\n2 37 74 32 99 75 73 86 67 33 62 30 15 21 51 41 73 75 67 39 90 10 56 74 72 26 38 65 75 55 46 99 34 49 92 82 11 100 15 71 75 12 22 56 47 74 20 98 59 65 14 76 1 40 89 36 43 93 83 73 75 100 50 95 27 10 72 51 25 69 15 3 57 60 84 99 31 44 12 61 69 95 51 31 28 36 57 35 31 52 44 19 79 12 27 27 7 81 68 1",
"output": "1"
},
{
"input": "100 1\n26",
"output": "0"
},
{
"input": "100 50\n8 82 62 11 85 57 5 32 99 92 77 2 61 86 8 88 10 28 83 4 68 79 8 64 56 98 4 88 22 54 30 60 62 79 72 38 17 28 32 16 62 26 56 44 72 33 22 84 77 45",
"output": "0"
},
{
"input": "100 100\n13 88 64 65 78 10 61 97 16 32 76 9 60 1 40 35 90 61 60 85 26 16 38 36 33 95 24 55 82 88 13 9 47 34 94 2 90 74 11 81 46 70 94 11 55 32 19 36 97 16 17 35 38 82 89 16 74 94 97 79 9 94 88 12 28 2 4 25 72 95 49 31 88 82 6 77 70 98 90 57 57 33 38 61 26 75 2 66 22 44 13 35 16 4 33 16 12 66 32 86",
"output": "1"
},
{
"input": "34 64\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",
"output": "1"
},
{
"input": "53 98\n1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 2 2 2 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 2 1 1",
"output": "1"
},
{
"input": "17 8\n2 5 3 4 3 2 2 2",
"output": "0"
},
{
"input": "24 77\n8 6 10 4 6 6 4 10 9 7 7 5 5 4 6 7 10 6 3 4 6 6 4 9 4 6 2 5 3 4 4 1 4 6 6 8 1 1 6 4 6 2 5 7 7 2 4 4 10 1 10 9 2 3 8 1 10 4 3 9 3 8 3 5 6 3 4 9 5 3 4 1 1 6 1 2 1",
"output": "2"
},
{
"input": "65 74\n7 19 2 38 28 44 34 49 14 13 30 22 11 4 4 12 8 1 40 8 34 31 44 38 21 35 13 7 19 32 37 5 36 26 7 2 15 11 47 45 48 2 49 10 10 42 42 31 50 24 29 34 31 38 39 48 43 47 32 46 10 1 33 21 12 50 13 44 38 11 41 41 10 7",
"output": "1"
},
{
"input": "37 71\n50 93 15 80 82 23 35 90 70 73 55 23 23 6 86 63 38 70 38 52 88 34 25 75 32 19 6 98 31 38 21 8 66 8 59 71 7 80 69 23 17 70 6 40 72 5 48 59 18 1 48 91 17 41 11 27 53 95 87 31 62 94 94 60 38 99 70 50 81 86 44",
"output": "1"
},
{
"input": "35 4\n100 100 100 100",
"output": "0"
},
{
"input": "68 12\n100 100 100 99 99 100 100 100 99 99 99 99",
"output": "0"
},
{
"input": "91 33\n97 100 96 96 97 100 97 97 96 96 99 99 98 97 97 99 99 98 100 96 96 99 100 96 97 100 97 97 99 98 96 98 97",
"output": "0"
},
{
"input": "59 72\n99 96 96 93 94 97 93 96 100 99 93 99 96 92 92 97 93 100 92 100 91 96 99 100 97 98 93 93 96 100 97 99 100 100 91 93 96 91 93 100 95 96 92 97 91 91 99 100 91 95 95 100 92 93 98 93 95 92 95 100 91 95 99 95 92 91 100 93 98 98 96 99",
"output": "1"
},
{
"input": "9 35\n95 54 78 94 56 63 68 73 61 85 73 62 61 94 67 91 66 54 89 69 92 60 91 87 63 62 85 70 62 68 97 88 96 55 62",
"output": "2"
},
{
"input": "99 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
}
] | 109 | 0 | 3 | 1,149 |
|
45 | Codecraft III | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.
All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December. | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1",
"output": "July"
},
{
"input": "July\n2",
"output": "September"
},
{
"input": "September\n3",
"output": "December"
},
{
"input": "July\n4",
"output": "November"
},
{
"input": "August\n24",
"output": "August"
},
{
"input": "May\n48",
"output": "May"
},
{
"input": "November\n47",
"output": "October"
},
{
"input": "December\n49",
"output": "January"
},
{
"input": "June\n99",
"output": "September"
},
{
"input": "March\n100",
"output": "July"
},
{
"input": "December\n1",
"output": "January"
},
{
"input": "January\n11",
"output": "December"
},
{
"input": "December\n0",
"output": "December"
},
{
"input": "January\n0",
"output": "January"
},
{
"input": "July\n77",
"output": "December"
},
{
"input": "February\n11",
"output": "January"
},
{
"input": "February\n22",
"output": "December"
},
{
"input": "July\n33",
"output": "April"
},
{
"input": "May\n44",
"output": "January"
},
{
"input": "June\n97",
"output": "July"
}
] | 92 | 0 | 3.977 | 1,152 |
370 | Rook, Bishop and King | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:
- A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally.
Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "1 0 7"
},
{
"input": "8 1 1 8",
"output": "2 1 7"
},
{
"input": "7 7 6 6",
"output": "2 1 1"
},
{
"input": "8 1 8 8",
"output": "1 0 7"
},
{
"input": "1 8 1 1",
"output": "1 0 7"
},
{
"input": "1 8 8 1",
"output": "2 1 7"
},
{
"input": "1 8 8 8",
"output": "1 0 7"
},
{
"input": "8 8 1 1",
"output": "2 1 7"
},
{
"input": "8 8 1 8",
"output": "1 0 7"
},
{
"input": "8 8 8 1",
"output": "1 0 7"
},
{
"input": "1 3 1 6",
"output": "1 0 3"
},
{
"input": "1 3 1 4",
"output": "1 0 1"
},
{
"input": "1 3 1 5",
"output": "1 2 2"
},
{
"input": "3 3 2 4",
"output": "2 1 1"
},
{
"input": "3 3 1 5",
"output": "2 1 2"
},
{
"input": "1 6 2 1",
"output": "2 2 5"
},
{
"input": "1 5 6 4",
"output": "2 2 5"
},
{
"input": "1 3 3 7",
"output": "2 2 4"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 7 5 4",
"output": "2 0 4"
},
{
"input": "1 5 2 7",
"output": "2 0 2"
},
{
"input": "1 4 6 2",
"output": "2 0 5"
},
{
"input": "1 2 3 5",
"output": "2 0 3"
},
{
"input": "1 8 8 7",
"output": "2 2 7"
},
{
"input": "6 5 6 2",
"output": "1 0 3"
},
{
"input": "6 3 3 5",
"output": "2 0 3"
},
{
"input": "6 1 7 8",
"output": "2 2 7"
},
{
"input": "1 2 3 2",
"output": "1 2 2"
},
{
"input": "3 8 7 2",
"output": "2 2 6"
},
{
"input": "4 2 6 4",
"output": "2 1 2"
},
{
"input": "1 1 1 3",
"output": "1 2 2"
},
{
"input": "6 8 8 6",
"output": "2 1 2"
},
{
"input": "6 7 4 1",
"output": "2 2 6"
},
{
"input": "6 5 1 4",
"output": "2 2 5"
},
{
"input": "3 2 7 6",
"output": "2 1 4"
},
{
"input": "3 8 4 1",
"output": "2 2 7"
},
{
"input": "3 6 1 4",
"output": "2 1 2"
}
] | 46 | 0 | 3 | 1,154 |
|
811 | Vladik and Complicated Book | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 93 | 0 | 0 | 1,155 |
|
35 | Fire Again | [
"brute force",
"dfs and similar",
"shortest paths"
] | C. Fire Again | 2 | 64 | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.
The burning began in *K* points simultaneously, which means that initially *K* trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1.
Find the tree that will be the last to start burning. If there are several such trees, output any. | The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning in the beginning.
The third line contains *K* pairs of integers: *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k* (1<=≤<=*x**i*<=≤<=*N*,<=1<=≤<=*y**i*<=≤<=*M*) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. | Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. | [
"3 3\n1\n2 2\n",
"3 3\n1\n1 1\n",
"3 3\n2\n1 1 3 3\n"
] | [
"1 1\n",
"3 3\n",
"2 2"
] | none | [
{
"input": "3 3\n1\n2 2",
"output": "1 1"
},
{
"input": "3 3\n1\n1 1",
"output": "3 3"
},
{
"input": "3 3\n2\n1 1 3 3",
"output": "1 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1 1"
},
{
"input": "2 2\n1\n2 2",
"output": "1 1"
},
{
"input": "2 2\n2\n1 1 2 1",
"output": "1 2"
},
{
"input": "2 2\n3\n1 2 2 1 1 1",
"output": "2 2"
},
{
"input": "2 2\n4\n2 1 2 2 1 1 1 2",
"output": "1 1"
},
{
"input": "10 10\n1\n5 5",
"output": "10 10"
},
{
"input": "10 10\n2\n7 8 1 9",
"output": "3 1"
},
{
"input": "10 10\n3\n3 9 6 3 3 5",
"output": "10 7"
},
{
"input": "10 10\n4\n5 3 4 7 7 5 8 5",
"output": "10 10"
},
{
"input": "10 10\n5\n2 7 10 6 5 3 9 5 2 9",
"output": "1 1"
},
{
"input": "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2",
"output": "1 3"
},
{
"input": "10 10\n7\n5 8 4 6 4 1 6 2 1 10 3 2 7 10",
"output": "10 5"
},
{
"input": "10 10\n8\n9 4 9 10 5 8 6 5 1 3 2 5 10 6 2 1",
"output": "1 10"
},
{
"input": "10 10\n9\n10 1 10 4 8 4 6 6 1 9 10 10 7 7 6 5 7 10",
"output": "1 1"
},
{
"input": "10 10\n10\n7 2 1 9 5 8 6 10 9 4 10 8 6 8 8 7 4 1 9 5",
"output": "1 3"
},
{
"input": "100 100\n1\n44 3",
"output": "100 100"
},
{
"input": "100 100\n2\n79 84 76 63",
"output": "1 1"
},
{
"input": "100 100\n3\n89 93 99 32 32 82",
"output": "1 1"
},
{
"input": "100 100\n4\n72 12 1 66 57 67 25 67",
"output": "100 100"
},
{
"input": "100 100\n5\n22 41 82 16 6 3 20 6 69 78",
"output": "1 100"
},
{
"input": "100 100\n6\n92 32 90 80 32 40 24 19 36 37 39 13",
"output": "1 100"
},
{
"input": "100 100\n7\n30 32 29 63 86 78 88 2 86 50 41 60 54 28",
"output": "1 100"
},
{
"input": "100 100\n8\n40 43 96 8 17 63 61 59 16 69 4 95 30 62 12 91",
"output": "100 100"
},
{
"input": "100 100\n9\n18 16 41 71 25 1 43 38 78 92 77 70 99 8 33 54 76 78",
"output": "1 100"
},
{
"input": "100 100\n10\n58 98 33 62 75 13 94 86 81 42 14 53 12 66 7 14 3 63 87 37",
"output": "40 1"
},
{
"input": "2000 2000\n1\n407 594",
"output": "2000 2000"
},
{
"input": "2000 2000\n2\n1884 43 1235 1111",
"output": "1 2000"
},
{
"input": "2000 2000\n3\n1740 1797 1279 1552 329 756",
"output": "2000 1"
},
{
"input": "2000 2000\n4\n1844 1342 171 1810 1558 1141 1917 1999",
"output": "530 1"
},
{
"input": "2000 2000\n5\n1846 327 1911 1534 134 1615 1664 682 1982 1112",
"output": "346 1"
},
{
"input": "2000 2000\n6\n1744 1102 852 723 409 179 89 1085 997 1433 1082 1680",
"output": "2000 1"
},
{
"input": "2000 2000\n7\n1890 22 288 1729 383 831 1192 1206 721 1376 969 492 510 1699",
"output": "2000 2000"
},
{
"input": "2000 2000\n8\n286 381 572 1849 1703 1574 622 1047 1507 941 871 663 1930 120 1084 1830",
"output": "1 1423"
},
{
"input": "2000 2000\n9\n226 531 56 138 722 405 1082 608 1355 1426 83 544 275 1268 683 412 1880 1049",
"output": "1701 1"
},
{
"input": "2000 2000\n10\n763 851 1182 571 1758 389 247 1907 730 881 531 1970 1430 667 169 765 1729 120 129 967",
"output": "2000 1793"
},
{
"input": "2000 2000\n10\n655 95 1640 1656 1344 79 666 1677 968 1180 522 1394 1850 1568 336 130 412 920 29 1664",
"output": "2000 570"
},
{
"input": "10 1\n10\n4 1 6 1 10 1 9 1 1 1 7 1 5 1 2 1 8 1 3 1",
"output": "1 1"
},
{
"input": "1 10\n10\n1 10 1 4 1 3 1 7 1 6 1 1 1 8 1 2 1 9 1 5",
"output": "1 1"
},
{
"input": "1 100\n10\n1 68 1 18 1 43 1 12 1 64 1 34 1 23 1 70 1 46 1 33",
"output": "1 100"
},
{
"input": "100 1\n10\n62 1 63 1 57 1 76 1 35 1 69 1 73 1 95 1 96 1 21 1",
"output": "1 1"
},
{
"input": "1 2000\n10\n1 1730 1 1374 1 831 1 1076 1 580 1 914 1 123 1 668 1 1288 1 160",
"output": "1 2000"
},
{
"input": "2000 1\n10\n1058 1 1779 1 1995 1 1398 1 96 1 1599 1 1496 1 1659 1 385 1 1485 1",
"output": "721 1"
},
{
"input": "5 5\n1\n1 1",
"output": "5 5"
},
{
"input": "2 5\n10\n1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5",
"output": "1 1"
},
{
"input": "1 10\n9\n1 1 1 2 1 3 1 4 1 6 1 7 1 8 1 9 1 10",
"output": "1 5"
},
{
"input": "3 3\n5\n1 1 1 3 2 2 3 1 3 3",
"output": "1 2"
},
{
"input": "999 999\n4\n1 499 499 1 499 999 999 499",
"output": "500 500"
}
] | 2,000 | 10,444,800 | 0 | 1,159 |
958 | Hyperspace Jump (easy) | [
"expression parsing",
"math"
] | null | null | The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form .
To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope! | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) – the number of ships. The next *m* lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer *a* of up to two decimal digits, a plus sign +, a positive integer *b* of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer *c* of up to two decimal digits. | Print a single line consisting of *m* space-separated integers. The *i*-th integer should be equal to the number of ships whose coordinate is equal to that of the *i*-th ship (including the *i*-th ship itself). | [
"4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n"
] | [
"1 2 2 1 "
] | In the sample testcase, the second and the third ship will both end up at the coordinate 3.
Note that this problem has only two versions – easy and hard. | [
{
"input": "4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7",
"output": "1 2 2 1 "
},
{
"input": "10\n(44+98)/19\n(36+58)/47\n(62+74)/68\n(69+95)/82\n(26+32)/29\n(32+46)/39\n(32+24)/28\n(47+61)/54\n(39+13)/26\n(98+98)/98",
"output": "1 9 9 9 9 9 9 9 9 9 "
},
{
"input": "30\n(89+76)/87\n(81+78)/18\n(60+97)/32\n(41+14)/48\n(55+65)/27\n(29+15)/95\n(64+13)/96\n(78+30)/75\n(43+6)/60\n(69+34)/48\n(62+2)/97\n(85+42)/3\n(4+97)/42\n(1+18)/39\n(46+55)/76\n(22+59)/24\n(62+81)/98\n(64+8)/51\n(9+59)/48\n(47+2)/80\n(33+74)/76\n(61+83)/44\n(86+4)/51\n(65+41)/49\n(53+36)/45\n(6+19)/15\n(51+21)/68\n(98+36)/86\n(92+65)/86\n(27+58)/78",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
}
] | 2,183 | 27,955,200 | 3 | 1,160 |
|
763 | Timofey and a tree | [
"dfs and similar",
"dp",
"dsu",
"graphs",
"implementation",
"trees"
] | null | null | Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.
Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex.
A subtree of some vertex is a subgraph containing that vertex and all its descendants.
Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree.
Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree.
The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices. | Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him.
Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them. | [
"4\n1 2\n2 3\n3 4\n1 2 1 1\n",
"3\n1 2\n2 3\n1 2 3\n",
"4\n1 2\n2 3\n3 4\n1 2 1 2\n"
] | [
"YES\n2",
"YES\n2",
"NO"
] | none | [
{
"input": "4\n1 2\n2 3\n3 4\n1 2 1 1",
"output": "YES\n2"
},
{
"input": "3\n1 2\n2 3\n1 2 3",
"output": "YES\n2"
},
{
"input": "4\n1 2\n2 3\n3 4\n1 2 1 2",
"output": "NO"
},
{
"input": "3\n2 1\n2 3\n1 2 3",
"output": "YES\n2"
},
{
"input": "4\n1 2\n2 4\n4 3\n1 1 3 2",
"output": "YES\n4"
},
{
"input": "2\n1 2\n1 1",
"output": "YES\n1"
},
{
"input": "10\n5 7\n4 5\n10 2\n3 6\n1 2\n3 4\n8 5\n4 9\n2 3\n15 15 15 15 5 15 26 18 15 15",
"output": "YES\n5"
},
{
"input": "8\n1 2\n1 3\n3 5\n3 6\n1 4\n4 7\n4 8\n1 3 1 1 1 1 1 2",
"output": "NO"
},
{
"input": "3\n2 1\n2 3\n4 4 4",
"output": "YES\n1"
},
{
"input": "3\n1 2\n1 3\n1 2 2",
"output": "YES\n1"
},
{
"input": "4\n1 4\n2 4\n3 4\n1 2 3 1",
"output": "YES\n4"
},
{
"input": "4\n1 2\n1 3\n1 4\n1 2 3 4",
"output": "YES\n1"
},
{
"input": "9\n1 2\n2 3\n3 4\n4 5\n2 7\n7 6\n2 8\n8 9\n1 1 2 2 2 3 3 4 4",
"output": "YES\n2"
},
{
"input": "3\n2 1\n2 3\n4 4 5",
"output": "YES\n2"
},
{
"input": "4\n1 2\n2 3\n3 4\n1 2 2 1",
"output": "NO"
}
] | 124 | 0 | 0 | 1,163 |
|
911 | Two Cakes | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake.
Help Ivan to calculate this number *x*! | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"input": "3 70 58",
"output": "35"
},
{
"input": "5 7 10",
"output": "3"
},
{
"input": "5 30 22",
"output": "10"
},
{
"input": "5 5 6",
"output": "2"
},
{
"input": "2 4 3",
"output": "3"
},
{
"input": "10 10 31",
"output": "3"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "10 98 99",
"output": "19"
},
{
"input": "4 10 16",
"output": "5"
},
{
"input": "11 4 8",
"output": "1"
},
{
"input": "5 10 14",
"output": "4"
},
{
"input": "6 7 35",
"output": "7"
},
{
"input": "5 6 7",
"output": "2"
},
{
"input": "4 15 3",
"output": "3"
},
{
"input": "7 48 77",
"output": "16"
},
{
"input": "4 4 10",
"output": "3"
},
{
"input": "4 7 20",
"output": "6"
},
{
"input": "5 2 8",
"output": "2"
},
{
"input": "3 2 3",
"output": "1"
},
{
"input": "14 95 1",
"output": "1"
},
{
"input": "99 82 53",
"output": "1"
},
{
"input": "10 71 27",
"output": "9"
},
{
"input": "5 7 8",
"output": "2"
},
{
"input": "11 77 77",
"output": "12"
},
{
"input": "10 5 28",
"output": "3"
},
{
"input": "7 3 12",
"output": "2"
},
{
"input": "10 15 17",
"output": "3"
},
{
"input": "7 7 7",
"output": "1"
},
{
"input": "4 11 18",
"output": "6"
},
{
"input": "3 3 4",
"output": "2"
},
{
"input": "9 2 10",
"output": "1"
},
{
"input": "100 90 20",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "12 45 60",
"output": "8"
},
{
"input": "3 94 79",
"output": "47"
},
{
"input": "41 67 34",
"output": "2"
},
{
"input": "9 3 23",
"output": "2"
},
{
"input": "10 20 57",
"output": "7"
},
{
"input": "55 27 30",
"output": "1"
},
{
"input": "100 100 10",
"output": "1"
},
{
"input": "20 8 70",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 9 15",
"output": "5"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "2 94 94",
"output": "94"
},
{
"input": "5 3 11",
"output": "2"
},
{
"input": "4 3 2",
"output": "1"
},
{
"input": "12 12 100",
"output": "9"
},
{
"input": "6 75 91",
"output": "25"
},
{
"input": "3 4 3",
"output": "2"
},
{
"input": "3 2 5",
"output": "2"
},
{
"input": "6 5 15",
"output": "3"
},
{
"input": "4 3 6",
"output": "2"
},
{
"input": "3 9 9",
"output": "4"
},
{
"input": "26 93 76",
"output": "6"
},
{
"input": "41 34 67",
"output": "2"
},
{
"input": "6 12 6",
"output": "3"
},
{
"input": "5 20 8",
"output": "5"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "35 66 99",
"output": "4"
},
{
"input": "30 7 91",
"output": "3"
},
{
"input": "5 22 30",
"output": "10"
},
{
"input": "8 19 71",
"output": "10"
},
{
"input": "3 5 6",
"output": "3"
},
{
"input": "5 3 8",
"output": "2"
},
{
"input": "2 4 2",
"output": "2"
},
{
"input": "4 3 7",
"output": "2"
},
{
"input": "5 20 10",
"output": "5"
},
{
"input": "5 100 50",
"output": "25"
},
{
"input": "6 3 10",
"output": "2"
},
{
"input": "2 90 95",
"output": "90"
},
{
"input": "4 8 6",
"output": "3"
},
{
"input": "6 10 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "2"
},
{
"input": "5 33 33",
"output": "11"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "19 24 34",
"output": "3"
},
{
"input": "5 5 12",
"output": "3"
},
{
"input": "8 7 10",
"output": "2"
},
{
"input": "5 56 35",
"output": "17"
},
{
"input": "4 3 5",
"output": "1"
},
{
"input": "18 100 50",
"output": "8"
},
{
"input": "5 6 8",
"output": "2"
},
{
"input": "5 98 100",
"output": "33"
},
{
"input": "6 5 8",
"output": "2"
},
{
"input": "3 40 80",
"output": "40"
},
{
"input": "4 8 11",
"output": "4"
},
{
"input": "66 100 99",
"output": "3"
},
{
"input": "17 100 79",
"output": "10"
},
{
"input": "3 2 10",
"output": "2"
},
{
"input": "99 100 99",
"output": "2"
},
{
"input": "21 100 5",
"output": "5"
},
{
"input": "3 10 2",
"output": "2"
},
{
"input": "4 100 63",
"output": "33"
},
{
"input": "2 2 10",
"output": "2"
},
{
"input": "5 94 79",
"output": "31"
},
{
"input": "4 12 5",
"output": "4"
},
{
"input": "5 5 40",
"output": "5"
},
{
"input": "99 99 99",
"output": "1"
},
{
"input": "8 97 44",
"output": "16"
},
{
"input": "11 4 10",
"output": "1"
},
{
"input": "6 3 3",
"output": "1"
},
{
"input": "7 3 4",
"output": "1"
},
{
"input": "8 4 4",
"output": "1"
},
{
"input": "9 4 5",
"output": "1"
},
{
"input": "12 6 6",
"output": "1"
},
{
"input": "4 48 89",
"output": "29"
},
{
"input": "8 3 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "2"
},
{
"input": "5 5 1",
"output": "1"
},
{
"input": "11 6 5",
"output": "1"
},
{
"input": "4 5 4",
"output": "2"
},
{
"input": "6 6 4",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "4 1 3",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "9 4 6",
"output": "1"
},
{
"input": "6 5 6",
"output": "1"
},
{
"input": "2 2 3",
"output": "2"
},
{
"input": "4 5 1",
"output": "1"
},
{
"input": "13 6 7",
"output": "1"
},
{
"input": "14 7 7",
"output": "1"
},
{
"input": "12 97 13",
"output": "8"
},
{
"input": "4 2 9",
"output": "2"
},
{
"input": "10 20 59",
"output": "7"
},
{
"input": "12 34 56",
"output": "7"
},
{
"input": "4 5 9",
"output": "3"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "4 66 41",
"output": "22"
}
] | 46 | 0 | 0 | 1,164 |
|
713 | Sonya and Queries | [
"data structures",
"implementation"
] | null | null | Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not. | The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=<<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it. | For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. | [
"12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n",
"4\n+ 200\n+ 200\n- 200\n? 0\n"
] | [
"2\n1\n2\n1\n1\n",
"1\n"
] | Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000. | [
{
"input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0",
"output": "2\n1\n2\n1\n1"
},
{
"input": "4\n+ 200\n+ 200\n- 200\n? 0",
"output": "1"
},
{
"input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00",
"output": "3\n2\n3\n4\n4\n2\n2"
},
{
"input": "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11",
"output": "0\n1\n0\n2\n1\n0\n1\n0\n1\n0"
},
{
"input": "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011",
"output": "0\n0\n0\n0\n0"
},
{
"input": "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396",
"output": "1\n1\n1\n1\n1"
},
{
"input": "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011",
"output": "1\n1"
},
{
"input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29",
"output": "1\n1\n1\n1\n1\n1\n1\n1"
}
] | 1,000 | 9,011,200 | 0 | 1,167 |
|
678 | Joty and Chocolate | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get. | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
},
{
"input": "4 1 5 4 3",
"output": "16"
},
{
"input": "8 8 1 1 1",
"output": "8"
},
{
"input": "15 14 32 65 28",
"output": "65"
},
{
"input": "894 197 325 232 902",
"output": "2732"
},
{
"input": "8581 6058 3019 2151 4140",
"output": "10431"
},
{
"input": "41764 97259 54586 18013 75415",
"output": "0"
},
{
"input": "333625 453145 800800 907251 446081",
"output": "0"
},
{
"input": "4394826 2233224 609367 3364334 898489",
"output": "9653757"
},
{
"input": "13350712 76770926 61331309 8735000 9057368",
"output": "0"
},
{
"input": "142098087 687355301 987788392 75187408 868856364",
"output": "0"
},
{
"input": "1000000000 1 3 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "6 6 2 8 2",
"output": "12"
},
{
"input": "500 8 4 4 5",
"output": "625"
},
{
"input": "20 4 6 2 3",
"output": "17"
},
{
"input": "10 3 9 1 2",
"output": "4"
},
{
"input": "120 18 6 3 5",
"output": "100"
},
{
"input": "30 4 6 2 2",
"output": "20"
},
{
"input": "1000000000 7171 2727 191 272",
"output": "125391842"
},
{
"input": "5 2 2 4 1",
"output": "8"
},
{
"input": "1000000000 2 2 3 3",
"output": "1500000000"
},
{
"input": "24 4 6 5 7",
"output": "48"
},
{
"input": "216 6 36 10 100",
"output": "900"
},
{
"input": "100 12 6 1 10",
"output": "160"
},
{
"input": "1000 4 8 3 5",
"output": "1000"
},
{
"input": "10 2 4 3 6",
"output": "21"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 5 10 2 3",
"output": "5"
},
{
"input": "100000 3 9 1 2",
"output": "44444"
},
{
"input": "10 2 4 1 100",
"output": "203"
},
{
"input": "20 6 4 2 3",
"output": "19"
},
{
"input": "1200 4 16 2 3",
"output": "675"
},
{
"input": "7 2 4 7 9",
"output": "23"
},
{
"input": "24 6 4 15 10",
"output": "100"
},
{
"input": "50 2 8 15 13",
"output": "375"
},
{
"input": "100 4 6 12 15",
"output": "444"
},
{
"input": "56756 9 18 56 78",
"output": "422502"
},
{
"input": "10000 4 6 10 12",
"output": "36662"
},
{
"input": "20 2 4 3 5",
"output": "40"
},
{
"input": "24 4 6 10 100",
"output": "440"
},
{
"input": "12 2 4 5 6",
"output": "33"
},
{
"input": "100 2 4 1 100",
"output": "2525"
},
{
"input": "1000 4 6 50 50",
"output": "16650"
},
{
"input": "60 12 6 12 15",
"output": "150"
},
{
"input": "1000 2 4 5 6",
"output": "2750"
},
{
"input": "1000000000 1 1 9999 5555",
"output": "9999000000000"
},
{
"input": "50 2 2 4 5",
"output": "125"
},
{
"input": "14 4 2 2 3",
"output": "21"
},
{
"input": "100 3 9 1 2",
"output": "44"
},
{
"input": "1000000000 4 6 1 1000000000",
"output": "166666666166666667"
},
{
"input": "12 3 3 45 4",
"output": "180"
},
{
"input": "12 2 4 5 9",
"output": "42"
},
{
"input": "1000000000 2 2 1000000000 1000000000",
"output": "500000000000000000"
},
{
"input": "50 4 8 5 6",
"output": "66"
},
{
"input": "32 4 16 6 3",
"output": "48"
},
{
"input": "10000 2 4 1 1",
"output": "5000"
},
{
"input": "8 2 4 100 1",
"output": "400"
},
{
"input": "20 4 2 10 1",
"output": "55"
},
{
"input": "5 2 2 12 15",
"output": "30"
},
{
"input": "20 2 12 5 6",
"output": "51"
},
{
"input": "10 2 4 1 2",
"output": "7"
},
{
"input": "32 4 16 3 6",
"output": "30"
},
{
"input": "50 2 8 13 15",
"output": "337"
},
{
"input": "12 6 4 10 9",
"output": "38"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999",
"output": "1999999997"
},
{
"input": "20 2 4 10 20",
"output": "150"
},
{
"input": "13 4 6 12 15",
"output": "54"
},
{
"input": "30 3 6 5 7",
"output": "60"
},
{
"input": "7 2 4 2 1",
"output": "6"
},
{
"input": "100000 32 16 2 3",
"output": "18750"
},
{
"input": "6 2 6 1 1",
"output": "3"
},
{
"input": "999999999 180 192 46642017 28801397",
"output": "399129078526502"
},
{
"input": "12 4 6 1 1",
"output": "4"
},
{
"input": "10 2 4 10 5",
"output": "50"
},
{
"input": "1000000 4 6 12 14",
"output": "4333328"
},
{
"input": "2000 20 30 3 5",
"output": "531"
},
{
"input": "1000000000 1 2 1 1",
"output": "1000000000"
},
{
"input": "30 3 15 10 3",
"output": "100"
},
{
"input": "1000 2 4 1 100",
"output": "25250"
},
{
"input": "6 3 3 12 15",
"output": "30"
},
{
"input": "24 4 6 1 1",
"output": "8"
},
{
"input": "20 2 12 4 5",
"output": "41"
},
{
"input": "1000000000 9 15 10 10",
"output": "1555555550"
},
{
"input": "16 2 4 1 2",
"output": "12"
},
{
"input": "100000 4 6 12 14",
"output": "433328"
},
{
"input": "24 6 4 1 1",
"output": "8"
},
{
"input": "1000000 4 6 12 15",
"output": "4499994"
},
{
"input": "100 2 4 5 6",
"output": "275"
},
{
"input": "10 3 9 12 15",
"output": "39"
},
{
"input": "1000000000 1 1 999999999 999999999",
"output": "999999999000000000"
},
{
"input": "6 2 4 2 3",
"output": "7"
},
{
"input": "2 2 2 2 2",
"output": "2"
},
{
"input": "6 6 2 1 1",
"output": "3"
},
{
"input": "100 2 4 3 7",
"output": "250"
},
{
"input": "1000000 32 16 2 5",
"output": "312500"
},
{
"input": "100 20 15 50 25",
"output": "375"
},
{
"input": "1000000000 100000007 100000013 10 3",
"output": "117"
},
{
"input": "1000000000 9999999 99999998 3 3",
"output": "330"
},
{
"input": "10077696 24 36 10 100",
"output": "30792960"
},
{
"input": "392852503 148746166 420198270 517065752 906699795",
"output": "1034131504"
},
{
"input": "536870912 60000 72000 271828 314159",
"output": "4369119072"
},
{
"input": "730114139 21550542 204644733 680083361 11353255",
"output": "22476810678"
},
{
"input": "538228881 766493289 791886544 468896052 600136703",
"output": "0"
},
{
"input": "190 20 50 84 172",
"output": "1188"
},
{
"input": "1000 5 10 80 90",
"output": "17000"
},
{
"input": "99999999 999999998 1 271828 314159",
"output": "31415899685841"
},
{
"input": "22 3 6 1243 1",
"output": "8701"
},
{
"input": "15 10 5 2 2",
"output": "6"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "62 62 42 78 124",
"output": "202"
},
{
"input": "2 2 2 2 1",
"output": "2"
},
{
"input": "864351351 351 313 531 11",
"output": "1337898227"
},
{
"input": "26 3 6 1244 1",
"output": "9952"
},
{
"input": "1000 4 6 7 3",
"output": "1999"
},
{
"input": "134312 3 6 33333 1",
"output": "1492318410"
},
{
"input": "100 4 6 17 18",
"output": "577"
},
{
"input": "6 2 4 5 6",
"output": "16"
},
{
"input": "8 2 4 10 1",
"output": "40"
},
{
"input": "10 2 4 3 3",
"output": "15"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000"
},
{
"input": "123123 3 6 34312 2",
"output": "1408198792"
},
{
"input": "1000000000 25 5 999 999",
"output": "199800000000"
},
{
"input": "100 4 2 5 12",
"output": "600"
},
{
"input": "50 2 4 4 5",
"output": "112"
},
{
"input": "24 4 6 100 333",
"output": "1732"
},
{
"input": "216 24 36 10 100",
"output": "660"
},
{
"input": "50 6 4 3 8",
"output": "108"
},
{
"input": "146 76 2 178 192",
"output": "14016"
},
{
"input": "55 8 6 11 20",
"output": "224"
},
{
"input": "5 2 4 6 16",
"output": "22"
},
{
"input": "54 2 52 50 188",
"output": "1488"
},
{
"input": "536870912 60000000 72000000 271828 314159",
"output": "4101909"
},
{
"input": "1000000000 1000000000 1 1 100",
"output": "100000000000"
},
{
"input": "50 4 2 4 5",
"output": "125"
},
{
"input": "198 56 56 122 118",
"output": "366"
},
{
"input": "5 1000000000 1 12 15",
"output": "75"
},
{
"input": "1000 6 12 5 6",
"output": "913"
},
{
"input": "50 3 6 12 15",
"output": "216"
},
{
"input": "333 300 300 300 300",
"output": "300"
},
{
"input": "1 1000000000 1 1 2",
"output": "2"
},
{
"input": "188 110 110 200 78",
"output": "200"
},
{
"input": "100000 20 10 3 2",
"output": "25000"
},
{
"input": "100 2 4 1 10",
"output": "275"
},
{
"input": "1000000000 2 1000000000 1 1000000",
"output": "500999999"
},
{
"input": "20 3 6 5 7",
"output": "36"
},
{
"input": "50 4 6 4 5",
"output": "72"
},
{
"input": "96 46 4 174 156",
"output": "3936"
},
{
"input": "5 2 4 12 15",
"output": "27"
},
{
"input": "12 3 6 100 1",
"output": "400"
},
{
"input": "100 4 2 10 32",
"output": "1600"
},
{
"input": "1232 3 6 30000 3",
"output": "12300000"
},
{
"input": "20 3 6 5 4",
"output": "30"
},
{
"input": "100 6 15 11 29",
"output": "317"
},
{
"input": "10000000 4 8 100 200",
"output": "375000000"
},
{
"input": "1000000000 12 24 2 4",
"output": "249999998"
},
{
"input": "123 3 6 3000 1",
"output": "123000"
},
{
"input": "401523968 1536 2664 271828 314159",
"output": "117768531682"
},
{
"input": "9 2 4 3 5",
"output": "16"
},
{
"input": "999999999 724362018 772432019 46201854 20017479",
"output": "66219333"
},
{
"input": "100 2 4 1 1000",
"output": "25025"
},
{
"input": "50 2 4 1 1000",
"output": "12013"
},
{
"input": "1000000000 2 1 2 1",
"output": "1500000000"
},
{
"input": "1000000000 2005034 2005046 15 12",
"output": "13446"
},
{
"input": "1000000000 999999999 1000000000 1 1",
"output": "2"
},
{
"input": "999999999 500000000 1 100 1000",
"output": "999999999000"
},
{
"input": "50 8 6 3 4",
"output": "44"
},
{
"input": "1000000000 1 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000 999999862 999999818 15 12",
"output": "27"
},
{
"input": "1000000000 10000019 10000019 21 17",
"output": "2079"
},
{
"input": "20 6 4 8 2",
"output": "32"
},
{
"input": "1000000000 1000000000 1 1 1",
"output": "1000000000"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999",
"output": "88999999992"
},
{
"input": "1000000000 2 999999937 100000000 100000000",
"output": "50000000100000000"
},
{
"input": "1000000000 1 1 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000 50001 100003 10 10",
"output": "299980"
},
{
"input": "1000000000 1000000000 3 1 1",
"output": "333333334"
},
{
"input": "10000 44 49 114 514",
"output": "130278"
},
{
"input": "30 5 15 2 1",
"output": "12"
},
{
"input": "20 2 4 1 1",
"output": "10"
},
{
"input": "100 8 12 5 6",
"output": "88"
}
] | 1,000 | 33,996,800 | 0 | 1,170 |
|
454 | Little Pony and Crystal Mine | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw. | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n***DDDDD***\n****DDD****\n*****D*****"
},
{
"input": "15",
"output": "*******D*******\n******DDD******\n*****DDDDD*****\n****DDDDDDD****\n***DDDDDDDDD***\n**DDDDDDDDDDD**\n*DDDDDDDDDDDDD*\nDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDD*\n**DDDDDDDDDDD**\n***DDDDDDDDD***\n****DDDDDDD****\n*****DDDDD*****\n******DDD******\n*******D*******"
},
{
"input": "21",
"output": "**********D**********\n*********DDD*********\n********DDDDD********\n*******DDDDDDD*******\n******DDDDDDDDD******\n*****DDDDDDDDDDD*****\n****DDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDD****\n*****DDDDDDDDDDD*****\n******DDDDDDDDD******\n*******DDDDDDD*******\n********DDDDD********\n*********DDD*********\n**********D**********"
},
{
"input": "33",
"output": "****************D****************\n***************DDD***************\n**************DDDDD**************\n*************DDDDDDD*************\n************DDDDDDDDD************\n***********DDDDDDDDDDD***********\n**********DDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDD..."
},
{
"input": "57",
"output": "****************************D****************************\n***************************DDD***************************\n**************************DDDDD**************************\n*************************DDDDDDD*************************\n************************DDDDDDDDD************************\n***********************DDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDD**..."
},
{
"input": "69",
"output": "**********************************D**********************************\n*********************************DDD*********************************\n********************************DDDDD********************************\n*******************************DDDDDDD*******************************\n******************************DDDDDDDDD******************************\n*****************************DDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDD****************************\n**************..."
},
{
"input": "81",
"output": "****************************************D****************************************\n***************************************DDD***************************************\n**************************************DDDDD**************************************\n*************************************DDDDDDD*************************************\n************************************DDDDDDDDD************************************\n***********************************DDDDDDDDDDD***********************************\n*************..."
},
{
"input": "91",
"output": "*********************************************D*********************************************\n********************************************DDD********************************************\n*******************************************DDDDD*******************************************\n******************************************DDDDDDD******************************************\n*****************************************DDDDDDDDD*****************************************\n****************************************DDDDDD..."
},
{
"input": "101",
"output": "**************************************************D**************************************************\n*************************************************DDD*************************************************\n************************************************DDDDD************************************************\n***********************************************DDDDDDD***********************************************\n**********************************************DDDDDDDDD********************************************..."
}
] | 61 | 0 | 3 | 1,171 |
|
225 | Dice Tower | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input. | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"input": "4\n3\n5 6\n1 3\n1 5\n4 1",
"output": "NO"
},
{
"input": "2\n2\n3 1\n1 3",
"output": "YES"
},
{
"input": "3\n2\n1 4\n3 1\n4 6",
"output": "YES"
},
{
"input": "4\n3\n5 6\n1 5\n5 1\n1 5",
"output": "YES"
},
{
"input": "5\n1\n2 3\n5 3\n5 4\n5 1\n3 5",
"output": "NO"
},
{
"input": "10\n5\n1 3\n2 3\n6 5\n6 5\n4 5\n1 3\n1 2\n3 2\n4 2\n1 2",
"output": "NO"
},
{
"input": "15\n4\n2 1\n2 4\n6 4\n5 3\n4 1\n4 2\n6 3\n4 5\n3 5\n2 6\n5 6\n1 5\n3 5\n6 4\n3 2",
"output": "NO"
},
{
"input": "20\n6\n3 2\n4 6\n3 6\n6 4\n5 1\n1 5\n2 6\n1 2\n1 4\n5 3\n2 3\n6 2\n5 4\n2 6\n1 3\n4 6\n4 5\n6 3\n3 1\n6 2",
"output": "NO"
},
{
"input": "25\n4\n1 2\n4 1\n3 5\n2 1\n3 5\n6 5\n3 5\n5 6\n1 2\n2 4\n6 2\n2 3\n2 4\n6 5\n2 3\n6 3\n2 3\n1 3\n2 1\n3 1\n5 6\n3 1\n6 4\n3 6\n2 3",
"output": "NO"
},
{
"input": "100\n3\n6 5\n5 1\n3 2\n1 5\n3 6\n5 4\n2 6\n4 1\n6 3\n4 5\n1 5\n1 4\n4 2\n2 6\n5 4\n4 1\n1 3\n6 5\n5 1\n2 1\n2 4\n2 1\n3 6\n4 1\n6 3\n2 3\n5 1\n2 6\n6 4\n3 5\n4 1\n6 5\n1 5\n1 5\n2 3\n4 1\n5 3\n6 4\n1 3\n5 3\n4 1\n1 4\n2 1\n6 2\n1 5\n6 2\n6 2\n4 5\n4 2\n5 6\n6 3\n1 3\n2 3\n5 4\n6 5\n3 1\n1 2\n4 1\n1 3\n1 3\n6 5\n4 6\n3 1\n2 1\n2 3\n3 2\n4 1\n1 5\n4 1\n6 3\n1 5\n4 5\n4 2\n4 5\n2 6\n2 1\n3 5\n4 6\n4 2\n4 5\n2 4\n3 1\n6 4\n5 6\n3 1\n1 4\n4 5\n6 3\n6 3\n2 1\n5 1\n3 6\n3 5\n2 1\n4 6\n4 2\n5 6\n3 1\n3 5\n3 6",
"output": "NO"
},
{
"input": "99\n3\n2 1\n6 2\n3 6\n1 3\n5 1\n2 6\n4 6\n6 4\n6 4\n6 5\n3 6\n2 6\n1 5\n2 3\n4 6\n1 4\n4 1\n2 3\n4 5\n4 1\n5 1\n1 2\n6 5\n4 6\n6 5\n6 2\n3 6\n6 4\n2 1\n3 1\n2 1\n6 2\n3 5\n4 1\n5 3\n3 1\n1 5\n3 6\n6 2\n1 5\n2 1\n5 1\n4 1\n2 6\n5 4\n4 2\n2 1\n1 5\n1 3\n4 6\n4 6\n4 5\n2 3\n6 2\n3 2\n2 1\n4 6\n6 2\n3 5\n3 6\n3 1\n2 3\n2 1\n3 6\n6 5\n6 3\n1 2\n5 1\n1 4\n6 2\n5 3\n1 3\n5 4\n2 3\n6 3\n1 5\n1 2\n2 6\n5 6\n5 6\n3 5\n3 1\n4 6\n3 1\n4 5\n4 2\n3 5\n6 2\n2 4\n4 6\n6 2\n4 2\n2 3\n2 4\n1 5\n1 4\n3 5\n1 2\n4 5",
"output": "NO"
},
{
"input": "98\n6\n4 2\n1 2\n3 2\n2 1\n2 1\n3 2\n2 3\n6 5\n4 6\n1 5\n4 5\n5 1\n6 5\n1 4\n1 2\n2 4\n6 5\n4 5\n4 6\n3 1\n2 3\n4 1\n4 2\n6 5\n3 2\n4 2\n5 1\n2 4\n1 3\n4 5\n3 2\n1 2\n3 1\n3 2\n3 6\n6 4\n3 6\n3 5\n4 6\n6 5\n3 5\n3 2\n4 2\n6 4\n1 3\n2 4\n5 3\n2 3\n1 3\n5 6\n5 3\n5 3\n4 6\n4 6\n3 6\n4 1\n6 5\n6 2\n1 5\n2 1\n6 2\n5 4\n6 3\n1 5\n2 3\n2 6\n5 6\n2 6\n5 1\n3 2\n6 2\n6 2\n1 2\n2 1\n3 5\n2 1\n4 6\n1 4\n4 5\n3 2\n3 2\n5 4\n1 3\n5 1\n2 3\n6 2\n2 6\n1 5\n5 1\n5 4\n5 1\n5 4\n2 1\n6 5\n1 4\n6 5\n1 2\n3 5",
"output": "NO"
},
{
"input": "97\n3\n2 1\n6 5\n4 1\n6 5\n3 2\n1 2\n6 3\n6 4\n6 3\n1 3\n1 3\n3 1\n3 6\n3 2\n5 6\n4 2\n3 6\n1 5\n2 6\n3 2\n6 2\n2 1\n2 4\n1 3\n3 1\n2 6\n3 6\n4 6\n6 2\n5 1\n6 3\n2 6\n3 6\n2 4\n4 5\n6 5\n4 1\n5 6\n6 2\n5 4\n5 1\n6 5\n1 4\n2 1\n4 5\n4 5\n4 1\n5 4\n1 4\n2 6\n2 6\n1 5\n5 6\n3 2\n2 3\n1 4\n4 1\n3 6\n6 2\n5 3\n6 2\n4 5\n6 2\n2 6\n6 5\n1 4\n2 6\n3 5\n2 6\n4 1\n4 5\n1 3\n4 2\n3 2\n1 2\n5 6\n1 5\n3 5\n2 1\n1 2\n1 2\n6 4\n5 1\n1 2\n2 4\n6 3\n4 5\n1 5\n4 2\n5 1\n3 1\n6 4\n4 2\n1 5\n4 6\n2 1\n2 6",
"output": "NO"
},
{
"input": "96\n4\n1 5\n1 5\n4 6\n1 2\n4 2\n3 2\n4 6\n6 4\n6 3\n6 2\n4 1\n6 4\n5 1\n2 4\n5 6\n6 5\n3 2\n6 2\n3 1\n1 4\n3 2\n6 2\n2 4\n1 3\n5 4\n1 3\n6 2\n6 2\n5 6\n1 4\n4 2\n6 2\n3 1\n6 5\n3 1\n4 2\n6 3\n3 2\n3 6\n1 3\n5 6\n6 4\n1 4\n5 4\n2 6\n3 5\n5 4\n5 1\n2 4\n1 5\n1 3\n1 2\n1 3\n6 4\n6 3\n4 5\n4 1\n3 6\n1 2\n6 4\n1 2\n2 3\n2 1\n4 6\n1 3\n5 1\n4 5\n5 4\n6 3\n2 6\n5 1\n6 2\n3 1\n3 1\n5 4\n3 1\n5 6\n2 6\n5 6\n4 2\n6 5\n3 2\n6 5\n2 3\n6 4\n6 2\n1 2\n4 1\n1 2\n6 3\n2 1\n5 1\n6 5\n5 4\n4 5\n1 2",
"output": "NO"
},
{
"input": "5\n1\n2 3\n3 5\n4 5\n5 4\n5 3",
"output": "YES"
},
{
"input": "10\n5\n1 3\n3 1\n6 3\n6 3\n4 6\n3 1\n1 4\n3 1\n4 6\n1 3",
"output": "YES"
},
{
"input": "15\n4\n2 1\n2 6\n6 5\n5 1\n1 5\n2 1\n6 5\n5 1\n5 1\n6 2\n6 5\n5 1\n5 1\n6 5\n2 6",
"output": "YES"
},
{
"input": "20\n6\n3 2\n4 2\n3 5\n4 2\n5 3\n5 4\n2 3\n2 3\n4 5\n3 5\n3 2\n2 4\n4 5\n2 4\n3 2\n4 2\n5 4\n3 2\n3 5\n2 4",
"output": "YES"
},
{
"input": "25\n4\n1 2\n1 5\n5 6\n1 2\n5 1\n5 6\n5 1\n6 5\n2 1\n2 6\n2 6\n2 6\n2 6\n5 6\n2 6\n6 5\n2 1\n1 5\n1 2\n1 2\n6 5\n1 2\n6 5\n6 2\n2 6",
"output": "YES"
},
{
"input": "100\n3\n6 5\n1 5\n2 1\n5 1\n6 5\n5 1\n6 2\n1 2\n6 5\n5 1\n5 1\n1 5\n2 6\n6 2\n5 6\n1 2\n1 5\n5 6\n1 5\n1 2\n2 6\n1 2\n6 2\n1 5\n6 2\n2 6\n1 5\n6 2\n6 5\n5 6\n1 5\n5 6\n5 1\n5 1\n2 1\n1 2\n5 6\n6 5\n1 5\n5 1\n1 2\n1 5\n1 2\n2 6\n5 1\n2 6\n2 6\n5 6\n2 6\n6 5\n6 5\n1 5\n2 1\n5 6\n5 6\n1 2\n2 1\n1 2\n1 2\n1 2\n5 6\n6 2\n1 5\n1 2\n2 1\n2 6\n1 2\n5 1\n1 5\n6 5\n5 1\n5 1\n2 6\n5 6\n6 2\n1 2\n5 1\n6 2\n2 1\n5 6\n2 1\n1 5\n6 5\n6 5\n1 2\n1 2\n5 1\n6 2\n6 2\n1 2\n1 5\n6 5\n5 6\n1 2\n6 5\n2 1\n6 5\n1 5\n5 6\n6 5",
"output": "YES"
},
{
"input": "99\n3\n2 1\n2 6\n6 2\n1 5\n1 5\n6 2\n6 5\n6 5\n6 2\n5 6\n6 5\n6 2\n5 1\n2 6\n6 5\n1 5\n1 5\n2 6\n5 1\n1 5\n1 5\n2 1\n5 6\n6 5\n5 6\n2 6\n6 2\n6 5\n1 2\n1 2\n1 2\n2 6\n5 6\n1 2\n5 6\n1 2\n5 1\n6 5\n2 6\n5 1\n1 2\n1 5\n1 5\n6 2\n5 1\n2 6\n1 2\n5 1\n1 5\n6 5\n6 5\n5 6\n2 1\n2 6\n2 6\n1 2\n6 2\n2 6\n5 6\n6 5\n1 5\n2 1\n1 2\n6 2\n5 6\n6 5\n2 1\n1 5\n1 5\n2 6\n5 1\n1 2\n5 6\n2 1\n6 5\n5 1\n2 1\n6 2\n6 5\n6 5\n5 6\n1 2\n6 5\n1 2\n5 1\n2 1\n5 1\n2 6\n2 1\n6 2\n2 6\n2 6\n2 1\n2 1\n5 1\n1 5\n5 6\n2 1\n5 6",
"output": "YES"
},
{
"input": "98\n6\n4 2\n2 3\n2 3\n2 3\n2 3\n2 3\n3 2\n5 4\n4 2\n5 4\n5 4\n5 4\n5 3\n4 5\n2 3\n4 2\n5 3\n5 4\n4 5\n3 5\n3 2\n4 2\n2 4\n5 4\n2 3\n2 4\n5 4\n4 2\n3 5\n5 4\n2 3\n2 4\n3 5\n2 3\n3 5\n4 2\n3 5\n5 3\n4 2\n5 3\n5 3\n2 3\n2 4\n4 5\n3 2\n4 2\n3 5\n3 2\n3 5\n5 4\n3 5\n3 5\n4 2\n4 2\n3 2\n4 5\n5 4\n2 3\n5 4\n2 4\n2 3\n4 5\n3 5\n5 4\n3 2\n2 3\n5 3\n2 3\n5 3\n2 3\n2 3\n2 4\n2 3\n2 3\n5 3\n2 3\n4 2\n4 2\n5 4\n2 3\n2 3\n4 5\n3 2\n5 3\n3 2\n2 4\n2 4\n5 3\n5 4\n4 5\n5 3\n4 5\n2 4\n5 3\n4 2\n5 4\n2 4\n5 3",
"output": "YES"
},
{
"input": "97\n3\n2 1\n5 6\n1 2\n5 6\n2 6\n2 1\n6 2\n6 5\n6 2\n1 5\n1 2\n1 2\n6 2\n2 6\n6 5\n2 6\n6 5\n5 1\n6 2\n2 6\n2 6\n1 2\n2 6\n1 2\n1 5\n6 2\n6 5\n6 5\n2 6\n1 5\n6 5\n6 2\n6 2\n2 6\n5 6\n5 6\n1 5\n6 5\n2 6\n5 6\n1 5\n5 6\n1 5\n1 2\n5 1\n5 1\n1 5\n5 1\n1 5\n6 2\n6 2\n5 1\n6 5\n2 1\n2 6\n1 5\n1 5\n6 2\n2 6\n5 6\n2 6\n5 6\n2 6\n6 2\n5 6\n1 2\n6 2\n5 6\n6 2\n1 5\n5 6\n1 5\n2 6\n2 6\n2 1\n6 5\n5 1\n5 1\n1 2\n2 1\n2 1\n6 2\n1 5\n2 1\n2 1\n6 2\n5 1\n5 1\n2 6\n1 5\n1 2\n6 2\n2 6\n5 1\n6 5\n1 2\n6 2",
"output": "YES"
},
{
"input": "96\n4\n1 5\n5 1\n6 5\n2 1\n2 1\n2 6\n6 5\n6 5\n6 2\n2 6\n1 5\n6 5\n1 5\n2 6\n6 5\n5 6\n2 1\n2 6\n1 2\n1 5\n2 6\n2 6\n2 1\n1 5\n5 1\n1 2\n2 6\n2 6\n6 5\n1 5\n2 1\n2 6\n1 2\n5 6\n1 5\n2 6\n6 2\n2 6\n6 5\n1 5\n6 5\n6 5\n1 5\n5 1\n6 2\n5 1\n5 1\n1 5\n2 6\n5 1\n1 5\n2 1\n1 2\n6 2\n6 2\n5 6\n1 5\n6 5\n2 1\n6 5\n2 1\n2 1\n1 2\n6 2\n1 2\n1 5\n5 1\n5 6\n6 5\n6 2\n1 5\n2 6\n1 2\n1 2\n5 1\n1 5\n6 5\n6 2\n6 5\n2 6\n5 6\n2 1\n5 6\n2 1\n6 5\n2 6\n2 1\n1 5\n2 1\n6 2\n1 2\n1 5\n5 6\n5 1\n5 6\n2 1",
"output": "YES"
},
{
"input": "3\n6\n3 2\n5 4\n2 6",
"output": "NO"
},
{
"input": "4\n1\n2 3\n2 3\n2 3\n1 3",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 4",
"output": "NO"
},
{
"input": "3\n6\n3 2\n5 6\n2 4",
"output": "NO"
},
{
"input": "2\n5\n6 3\n4 5",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 5",
"output": "NO"
},
{
"input": "2\n1\n3 2\n1 2",
"output": "NO"
},
{
"input": "2\n3\n5 1\n3 5",
"output": "NO"
},
{
"input": "2\n1\n2 3\n1 2",
"output": "NO"
},
{
"input": "2\n1\n2 3\n2 1",
"output": "NO"
},
{
"input": "3\n1\n4 5\n4 1\n4 5",
"output": "NO"
},
{
"input": "2\n4\n2 6\n5 4",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 2",
"output": "NO"
},
{
"input": "2\n3\n2 1\n3 5",
"output": "NO"
},
{
"input": "2\n3\n1 2\n3 1",
"output": "NO"
},
{
"input": "2\n3\n2 6\n5 3",
"output": "NO"
},
{
"input": "3\n3\n1 2\n3 2\n3 1",
"output": "NO"
},
{
"input": "3\n5\n3 1\n1 3\n2 3",
"output": "NO"
},
{
"input": "2\n6\n2 4\n6 5",
"output": "NO"
},
{
"input": "2\n6\n4 5\n6 5",
"output": "NO"
},
{
"input": "2\n6\n3 5\n3 6",
"output": "NO"
},
{
"input": "2\n4\n1 2\n4 5",
"output": "NO"
},
{
"input": "2\n3\n2 6\n3 1",
"output": "NO"
}
] | 374 | 26,112,000 | 3 | 1,172 |
|
832 | Strange Radiation | [
"binary search",
"implementation",
"math"
] | null | null | *n* people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed.
You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all people will start running with their maximum speed in the direction they are facing. Also, two strange rays will start propagating from the bomb with speed *s*: one to the right, and one to the left. Of course, the speed *s* is strictly greater than people's maximum speed.
The rays are strange because if at any moment the position and the direction of movement of some ray and some person coincide, then the speed of the person immediately increases by the speed of the ray.
You need to place the bomb is such a point that the minimum time moment in which there is a person that has run through point 0, and there is a person that has run through point 106, is as small as possible. In other words, find the minimum time moment *t* such that there is a point you can place the bomb to so that at time moment *t* some person has run through 0, and some person has run through point 106. | The first line contains two integers *n* and *s* (2<=≤<=*n*<=≤<=105, 2<=≤<=*s*<=≤<=106) — the number of people and the rays' speed.
The next *n* lines contain the description of people. The *i*-th of these lines contains three integers *x**i*, *v**i* and *t**i* (0<=<<=*x**i*<=<<=106, 1<=≤<=*v**i*<=<<=*s*, 1<=≤<=*t**i*<=≤<=2) — the coordinate of the *i*-th person on the line, his maximum speed and the direction he will run to (1 is to the left, i.e. in the direction of coordinate decrease, 2 is to the right, i.e. in the direction of coordinate increase), respectively.
It is guaranteed that the points 0 and 106 will be reached independently of the bomb's position. | Print the minimum time needed for both points 0 and 106 to be reached.
Your answer is considered correct if its absolute or relative error doesn't exceed 10<=-<=6. Namely, if your answer is *a*, and the jury's answer is *b*, then your answer is accepted, if . | [
"2 999\n400000 1 2\n500000 1 1\n",
"2 1000\n400000 500 1\n600000 500 2\n"
] | [
"500000.000000000000000000000000000000\n",
"400.000000000000000000000000000000\n"
] | In the first example, it is optimal to place the bomb at a point with a coordinate of 400000. Then at time 0, the speed of the first person becomes 1000 and he reaches the point 10<sup class="upper-index">6</sup> at the time 600. The bomb will not affect on the second person, and he will reach the 0 point at the time 500000.
In the second example, it is optimal to place the bomb at the point 500000. The rays will catch up with both people at the time 200. At this time moment, the first is at the point with a coordinate of 300000, and the second is at the point with a coordinate of 700000. Their speed will become 1500 and at the time 400 they will simultaneously run through points 0 and 10<sup class="upper-index">6</sup>. | [
{
"input": "2 999\n400000 1 2\n500000 1 1",
"output": "500000.000000000000000000000000000000"
},
{
"input": "2 1000\n400000 500 1\n600000 500 2",
"output": "400.000000000000000000000000000000"
},
{
"input": "2 99999\n500 1 1\n499 10000 2",
"output": "99.950100000000000000088817841970"
},
{
"input": "26 10\n495492 7 1\n256604 5 2\n511773 3 2\n590712 4 1\n206826 7 2\n817878 4 2\n843915 1 1\n349160 3 1\n351298 4 1\n782251 8 2\n910928 4 1\n662354 4 2\n468621 2 2\n466991 7 2\n787303 6 2\n221623 8 2\n343518 6 1\n141123 7 1\n24725 6 1\n896603 3 2\n918129 8 2\n706071 6 2\n512369 2 2\n600004 4 1\n928608 9 2\n298493 3 1",
"output": "4120.833333333333333481363069950021"
},
{
"input": "13 10000\n78186 325 1\n942344 8592 2\n19328 6409 2\n632454 7747 2\n757264 8938 1\n462681 7708 1\n26489 2214 2\n415801 8912 2\n156832 48 1\n898262 1620 2\n936086 5125 1\n142567 5086 1\n207839 9409 2",
"output": "7.572493946731234866574095088154"
},
{
"input": "22 30\n739680 21 1\n697634 24 1\n267450 27 2\n946750 8 2\n268031 27 1\n418652 11 1\n595005 12 1\n59519 22 2\n332220 1 1\n355395 2 1\n573947 26 1\n864962 4 1\n659836 14 1\n439461 22 1\n694157 11 2\n429431 11 2\n304031 9 2\n282710 4 1\n623799 11 1\n610188 27 2\n596592 20 2\n562391 18 2",
"output": "6656.250000000000000000000000000000"
},
{
"input": "10 100\n945740 58 2\n424642 85 2\n310528 91 2\n688743 93 1\n355046 85 1\n663649 84 2\n720124 56 1\n941616 59 2\n412011 46 2\n891591 30 2",
"output": "1919.167567567567567521358284921007"
},
{
"input": "4 100\n884131 61 1\n927487 23 2\n663318 13 1\n234657 61 1",
"output": "3152.739130434782608647381607624993"
},
{
"input": "20 20\n722369 11 1\n210389 8 2\n743965 2 1\n951723 17 2\n880618 1 2\n101303 8 2\n174013 19 2\n627995 19 1\n541778 5 1\n586095 19 1\n324166 4 1\n125805 12 2\n538606 2 2\n691777 9 2\n127586 7 1\n849701 9 1\n23273 17 1\n250794 4 1\n64709 7 2\n785893 9 1",
"output": "1369.000000000000000000000000000000"
},
{
"input": "5 786551\n352506 2 1\n450985 6 2\n561643 4 2\n5065 8 2\n717868 3 1",
"output": "0.635685124996669956255399003275"
},
{
"input": "3 96475\n187875 5 2\n813727 8 1\n645383 7 2",
"output": "50659.571428571428569398449326399714"
},
{
"input": "2 96475\n813727 8 1\n645383 7 2",
"output": "50659.571428571428569398449326399714"
},
{
"input": "2 2\n1 1 1\n999999 1 2",
"output": "1.000000000000000000000000000000"
},
{
"input": "2 1000000\n1 1 1\n999999 1 2",
"output": "0.499999999999500000001997901400"
},
{
"input": "2 250001\n499999 250000 1\n500000 250000 2",
"output": "1.499997000005989434244513258676"
}
] | 1,154 | 23,347,200 | 3 | 1,173 |
|
742 | Arpa’s hard exam and Mehrdad’s naive cheat | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": "8"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "2"
},
{
"input": "1378",
"output": "4"
},
{
"input": "13781378",
"output": "4"
},
{
"input": "51202278",
"output": "4"
},
{
"input": "999999998",
"output": "4"
},
{
"input": "999999997",
"output": "8"
},
{
"input": "12193721",
"output": "8"
},
{
"input": "0",
"output": "1"
},
{
"input": "989898989",
"output": "8"
},
{
"input": "7",
"output": "2"
},
{
"input": "8",
"output": "6"
},
{
"input": "9",
"output": "8"
},
{
"input": "10",
"output": "4"
},
{
"input": "11",
"output": "2"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "14",
"output": "4"
},
{
"input": "15",
"output": "2"
},
{
"input": "16",
"output": "6"
},
{
"input": "999999996",
"output": "6"
},
{
"input": "999999995",
"output": "2"
},
{
"input": "999999994",
"output": "4"
}
] | 31 | 0 | 0 | 1,176 |
|
745 | Hongcow Learns the Cyclic Shift | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "1"
},
{
"input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy",
"output": "2"
},
{
"input": "y",
"output": "1"
},
{
"input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos",
"output": "49"
},
{
"input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy",
"output": "50"
},
{
"input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde",
"output": "8"
},
{
"input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs",
"output": "49"
},
{
"input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz",
"output": "49"
},
{
"input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw",
"output": "12"
},
{
"input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "25"
},
{
"input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba",
"output": "4"
},
{
"input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq",
"output": "48"
},
{
"input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq",
"output": "49"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx",
"output": "50"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "50"
},
{
"input": "abcddcba",
"output": "8"
},
{
"input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac",
"output": "12"
},
{
"input": "aabaabcaabaabcdaabaabcaabaabcd",
"output": "15"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaaa",
"output": "47"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaa",
"output": "23"
},
{
"input": "aaababaab",
"output": "9"
},
{
"input": "aba",
"output": "3"
}
] | 46 | 0 | 3 | 1,177 |
|
899 | Splitting in Teams | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n2 2 1 1 1",
"output": "2"
},
{
"input": "7\n1 1 2 2 1 2 1",
"output": "3"
},
{
"input": "10\n1 2 2 1 2 2 1 2 1 1",
"output": "5"
},
{
"input": "5\n2 2 2 1 2",
"output": "1"
},
{
"input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2",
"output": "10"
},
{
"input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2",
"output": "34"
},
{
"input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2",
"output": "32"
},
{
"input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2",
"output": "9"
},
{
"input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1",
"output": "11"
},
{
"input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2",
"output": "100"
},
{
"input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2",
"output": "123"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "3\n2 2 1",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "1"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n1 1 1 1 2",
"output": "2"
},
{
"input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "38\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 1",
"output": "1"
},
{
"input": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "26\n2 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",
"output": "1"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "3"
},
{
"input": "5\n2 1 1 1 1",
"output": "2"
},
{
"input": "9\n1 1 1 1 1 1 2 2 2",
"output": "4"
},
{
"input": "10\n2 2 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "2"
}
] | 155 | 8,806,400 | 3 | 1,178 |
|
580 | Kefa and First Steps | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992",
"output": "42"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "6\n5 4 3 2 1 2",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "7\n99 100 1 2 3 4 5",
"output": "5"
},
{
"input": "5\n3 3 1 2 3",
"output": "3"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
}
] | 30 | 0 | 0 | 1,179 |
|
146 | Lucky Mask | [
"brute force",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a mask of a positive integer *n* the number that is obtained after successive writing of all lucky digits of number *n* from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.
Petya has two numbers — an arbitrary integer *a* and a lucky number *b*. Help him find the minimum number *c* (*c*<=><=*a*) such that the mask of number *c* equals *b*. | The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky. | In the only line print a single number — the number *c* that is sought by Petya. | [
"1 7\n",
"100 47\n"
] | [
"7\n",
"147\n"
] | none | [
{
"input": "1 7",
"output": "7"
},
{
"input": "100 47",
"output": "147"
},
{
"input": "458 47",
"output": "467"
},
{
"input": "7 7",
"output": "17"
},
{
"input": "547 47",
"output": "647"
},
{
"input": "77 77",
"output": "177"
},
{
"input": "44 4",
"output": "45"
},
{
"input": "740 4",
"output": "804"
},
{
"input": "100000 77777",
"output": "177777"
},
{
"input": "77777 77777",
"output": "177777"
},
{
"input": "47 74",
"output": "74"
},
{
"input": "74 77",
"output": "77"
},
{
"input": "77 74",
"output": "174"
},
{
"input": "98545 7474",
"output": "107474"
},
{
"input": "99997 4",
"output": "100004"
},
{
"input": "100000 7",
"output": "100007"
},
{
"input": "99997 47",
"output": "100047"
},
{
"input": "47774 774",
"output": "50774"
},
{
"input": "47744 7",
"output": "50007"
},
{
"input": "45896 4",
"output": "45898"
},
{
"input": "45679 77777",
"output": "77777"
},
{
"input": "99979 77",
"output": "100077"
},
{
"input": "10 77777",
"output": "77777"
},
{
"input": "1 47774",
"output": "47774"
},
{
"input": "47774 47774",
"output": "147774"
},
{
"input": "47580 47774",
"output": "47774"
},
{
"input": "55557 74",
"output": "55574"
},
{
"input": "59765 4774",
"output": "64774"
},
{
"input": "76492 447",
"output": "80447"
},
{
"input": "69700 77477",
"output": "77477"
},
{
"input": "31975 74",
"output": "32074"
},
{
"input": "369 47",
"output": "407"
},
{
"input": "39999 4",
"output": "40000"
},
{
"input": "39999 4774",
"output": "40774"
},
{
"input": "474 74",
"output": "574"
},
{
"input": "40007 74444",
"output": "74444"
},
{
"input": "40007 74",
"output": "50074"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "4 4",
"output": "14"
},
{
"input": "700 74",
"output": "704"
},
{
"input": "476 47",
"output": "478"
},
{
"input": "99999 77",
"output": "100077"
},
{
"input": "46 7",
"output": "57"
}
] | 280 | 0 | 0 | 1,180 |
|
22 | Second Order Statistics | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 62 | 0 | 3.9845 | 1,181 |
402 | Strictly Positive Matrix | [
"graphs",
"math"
] | null | null | You have matrix *a* of size *n*<=×<=*n*. Let's number the rows of the matrix from 1 to *n* from top to bottom, let's number the columns from 1 to *n* from left to right. Let's use *a**ij* to represent the element on the intersection of the *i*-th row and the *j*-th column.
Matrix *a* meets the following two conditions:
- for any numbers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) the following inequality holds: *a**ij*<=≥<=0; - .
Matrix *b* is strictly positive, if for any numbers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) the inequality *b**ij*<=><=0 holds. You task is to determine if there is such integer *k*<=≥<=1, that matrix *a**k* is strictly positive. | The first line contains integer *n* (2<=≤<=*n*<=≤<=2000) — the number of rows and columns in matrix *a*.
The next *n* lines contain the description of the rows of matrix *a*. The *i*-th line contains *n* non-negative integers *a**i*1,<=*a**i*2,<=...,<=*a**in* (0<=≤<=*a**ij*<=≤<=50). It is guaranteed that . | If there is a positive integer *k*<=≥<=1, such that matrix *a**k* is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes). | [
"2\n1 0\n0 1\n",
"5\n4 5 6 1 2\n1 2 3 4 5\n6 4 1 2 4\n1 1 1 1 1\n4 4 4 4 4\n"
] | [
"NO\n",
"YES\n"
] | none | [
{
"input": "2\n1 0\n0 1",
"output": "NO"
},
{
"input": "5\n4 5 6 1 2\n1 2 3 4 5\n6 4 1 2 4\n1 1 1 1 1\n4 4 4 4 4",
"output": "YES"
},
{
"input": "5\n1 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 1 1\n0 0 0 0 1",
"output": "NO"
},
{
"input": "5\n1 0 0 0 0\n1 1 0 0 0\n0 1 1 0 0\n0 0 1 1 0\n0 0 0 1 1",
"output": "NO"
},
{
"input": "10\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n1 0 1 1 0 1 1 1 0 1\n0 1 0 0 1 0 0 0 1 0\n1 0 1 1 0 1 1 1 0 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 1 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 1 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0",
"output": "YES"
},
{
"input": "3\n1 1 0\n0 0 1\n1 0 0",
"output": "YES"
},
{
"input": "10\n16 7 11 41 25 6 8 40 38 13\n0 0 37 22 0 34 5 43 38 34\n13 3 0 38 13 7 41 45 2 20\n50 41 12 22 24 43 38 3 0 0\n33 0 5 47 3 48 3 0 48 17\n28 2 43 43 20 6 12 13 47 28\n38 45 47 49 33 2 26 26 43 0\n39 0 11 39 15 31 5 5 39 22\n27 15 0 18 19 47 3 18 14 40\n20 32 33 25 43 10 0 0 15 43",
"output": "YES"
},
{
"input": "9\n22 32 19 16 27 0 8 31 36\n49 2 13 16 7 38 36 45 48\n9 24 19 45 6 18 19 11 2\n3 23 48 7 13 42 16 44 33\n30 8 37 0 4 12 27 29 11\n9 1 7 2 11 15 21 15 40\n41 23 0 38 17 36 15 2 10\n13 37 39 18 26 20 41 48 17\n13 12 43 10 46 8 46 22 46",
"output": "YES"
},
{
"input": "2\n33 50\n20 27",
"output": "YES"
},
{
"input": "5\n0 1 0 0 0\n0 0 0 1 0\n1 0 0 0 0\n0 0 0 1 1\n0 0 1 0 0",
"output": "YES"
},
{
"input": "2\n0 1\n1 1",
"output": "YES"
},
{
"input": "5\n0 1 1 0 1\n1 1 1 0 0\n1 1 0 0 0\n0 0 0 1 1\n0 0 0 1 0",
"output": "NO"
},
{
"input": "5\n0 1 1 0 0\n1 1 1 0 0\n1 1 0 0 0\n0 0 0 1 1\n1 0 0 1 0",
"output": "NO"
},
{
"input": "10\n0 1 1 1 1 1 1 0 0 0\n1 0 1 1 1 1 1 0 0 0\n1 1 0 1 1 1 1 0 0 0\n1 1 1 0 1 1 1 0 0 0\n1 1 1 1 1 1 1 0 0 0\n1 1 1 1 1 0 1 0 0 0\n1 1 1 1 1 1 0 0 0 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 1 0 1\n0 1 0 0 0 0 0 1 1 0",
"output": "NO"
},
{
"input": "5\n0 1 0 0 0\n1 0 0 0 0\n0 0 1 1 0\n0 0 0 1 1\n0 0 1 0 1",
"output": "NO"
},
{
"input": "4\n1 1 0 0\n1 1 0 0\n0 0 1 1\n0 0 1 1",
"output": "NO"
},
{
"input": "5\n0 1 0 0 0\n1 0 1 0 0\n0 0 1 1 0\n0 0 0 1 1\n0 0 1 0 1",
"output": "NO"
},
{
"input": "3\n1 2 0\n0 0 3\n0 0 0",
"output": "NO"
},
{
"input": "2\n1 1\n0 1",
"output": "NO"
},
{
"input": "4\n1 1 0 0\n1 0 1 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 1 1\n0 1 1 0\n0 1 1 0\n1 1 1 1",
"output": "NO"
},
{
"input": "3\n1 1 0\n0 1 1\n0 0 1",
"output": "NO"
},
{
"input": "4\n1 0 0 1\n0 1 1 0\n0 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "4\n1 1 0 0\n1 1 0 0\n1 1 1 1\n1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 0 0 0\n1 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n0 0 1 0 1",
"output": "NO"
},
{
"input": "2\n1 1\n0 0",
"output": "NO"
},
{
"input": "15\n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 0 0 0 0 0 0 0 0 0 0 0\n0 0 1 1 1 0 0 0 0 0 0 0 0 0 0\n0 0 0 1 1 1 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 1 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0 0 0 0 0\n0 0 0 0 0 0 0 1 1 1 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 1 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1",
"output": "YES"
},
{
"input": "4\n1 1 0 0\n1 0 0 0\n0 1 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "6\n1 1 0 0 0 0\n0 1 1 0 0 0\n1 0 1 0 0 0\n0 0 0 1 1 0\n0 0 0 0 1 1\n0 0 0 1 0 1",
"output": "NO"
},
{
"input": "3\n1 1 1\n0 0 0\n0 0 0",
"output": "NO"
}
] | 1,000 | 16,691,200 | 0 | 1,184 |
|
318 | Even Odds | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 62 | 0 | 3 | 1,185 |
|
609 | The Best Gift | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from 1 to *m*. | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed that for each genre there is at least one book of that genre. | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2\n1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "12 3\n1 2 3 1 2 3 1 2 3 1 2 3",
"output": "48"
},
{
"input": "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "3296"
},
{
"input": "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5",
"output": "3953"
},
{
"input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "4428"
}
] | 139 | 8,192,000 | 3 | 1,187 |
|
445 | DZY Loves Chemistry | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours a chemical, if there are already one or more chemicals in the test tube that can react with it, the danger of the test tube will be multiplied by 2. Otherwise the danger remains as it is.
Find the maximum possible danger after pouring all the chemicals one by one in optimal order. | The first line contains two space-separated integers *n* and *m* .
Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=<<=*y**i*<=≤<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once in the input.
Consider all the chemicals numbered from 1 to *n* in some order. | Print a single integer — the maximum possible danger. | [
"1 0\n",
"2 1\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first sample, there's only one way to pour, and the danger won't increase.
In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.
In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that is the numbers of the chemicals in order of pouring). | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "3 2\n1 2\n2 3",
"output": "4"
},
{
"input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7",
"output": "512"
},
{
"input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12\n2 15\n5 17\n5 14\n6 14\n12 20\n7 20\n1 6\n1 7\n2 19\n14 17\n1 10\n11 15\n9 18\n2 12",
"output": "32768"
},
{
"input": "30 30\n7 28\n16 26\n14 24\n16 18\n20 29\n4 28\n19 21\n8 26\n1 25\n14 22\n13 23\n4 15\n15 16\n2 19\n29 30\n12 20\n3 4\n3 26\n3 11\n22 27\n5 16\n2 24\n2 18\n7 16\n17 21\n17 25\n8 15\n23 27\n12 21\n5 30",
"output": "67108864"
},
{
"input": "40 40\n28 33\n15 21\n12 29\n14 31\n2 26\n3 12\n25 34\n6 30\n6 25\n5 28\n9 17\n23 29\n30 36\n3 21\n35 37\n7 25\n29 39\n15 19\n12 35\n24 34\n15 25\n19 33\n26 31\n7 29\n1 40\n11 27\n6 9\n6 27\n36 39\n10 14\n6 16\n23 25\n2 38\n3 24\n30 31\n29 30\n4 12\n11 13\n14 40\n22 39",
"output": "34359738368"
},
{
"input": "50 50\n16 21\n23 47\n23 30\n2 12\n23 41\n3 16\n14 20\n4 49\n2 47\n19 29\n13 42\n5 8\n24 38\n13 32\n34 37\n38 46\n3 20\n27 50\n7 42\n33 45\n2 48\n41 47\n9 48\n15 26\n27 37\n32 34\n17 24\n1 39\n27 30\n10 33\n38 47\n32 33\n14 39\n35 50\n2 19\n3 12\n27 34\n18 25\n12 23\n31 44\n5 35\n28 45\n38 39\n13 44\n34 38\n16 46\n5 15\n26 30\n47 49\n2 10",
"output": "4398046511104"
},
{
"input": "50 0",
"output": "1"
},
{
"input": "50 7\n16 32\n31 34\n4 16\n4 39\n1 50\n43 49\n1 33",
"output": "128"
},
{
"input": "7 20\n2 3\n3 6\n1 6\n1 2\n3 5\n1 7\n4 5\n4 7\n1 3\n2 6\n2 7\n4 6\n3 4\n1 4\n3 7\n1 5\n2 5\n5 6\n5 7\n2 4",
"output": "64"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5",
"output": "16"
},
{
"input": "10 7\n1 2\n2 3\n1 5\n2 7\n7 8\n1 9\n9 10",
"output": "128"
},
{
"input": "20 15\n1 3\n3 4\n3 5\n4 6\n1 7\n1 8\n1 9\n7 11\n8 12\n5 13\n3 16\n1 17\n3 18\n1 19\n17 20",
"output": "32768"
},
{
"input": "30 24\n2 3\n3 4\n1 5\n4 6\n6 7\n1 8\n1 9\n4 10\n9 11\n5 12\n6 13\n10 14\n14 15\n12 16\n14 17\n2 18\n8 19\n3 20\n10 21\n11 24\n3 25\n1 26\n7 27\n4 29",
"output": "16777216"
},
{
"input": "40 28\n1 2\n2 4\n3 5\n1 7\n1 8\n7 9\n6 10\n7 11\n2 12\n9 13\n11 15\n12 16\n1 18\n10 19\n7 21\n7 23\n20 25\n24 27\n14 28\n9 29\n23 30\n27 31\n11 34\n21 35\n32 36\n23 38\n7 39\n20 40",
"output": "268435456"
},
{
"input": "50 41\n1 2\n1 3\n2 4\n1 5\n2 7\n4 8\n7 9\n2 11\n10 13\n11 14\n12 15\n14 16\n4 19\n7 20\n14 21\n8 23\n16 24\n16 25\n16 26\n19 27\n2 28\n3 29\n21 30\n12 31\n20 32\n23 33\n30 34\n6 35\n34 36\n34 37\n33 38\n34 40\n30 41\n3 42\n39 43\n5 44\n8 45\n40 46\n20 47\n31 49\n34 50",
"output": "2199023255552"
},
{
"input": "50 39\n1 2\n1 4\n5 6\n4 7\n5 8\n7 9\n9 10\n10 11\n2 12\n8 14\n11 15\n11 17\n3 18\n13 19\n17 20\n7 21\n6 22\n22 23\n14 24\n22 25\n23 26\n26 27\n27 28\n15 29\n8 30\n26 31\n32 33\n21 35\n14 36\n30 37\n17 38\n12 40\n11 42\n14 43\n12 44\n1 45\n29 46\n22 47\n47 50",
"output": "549755813888"
},
{
"input": "50 38\n1 2\n2 3\n3 4\n3 5\n4 7\n5 10\n9 11\n9 12\n11 13\n12 14\n6 15\n8 16\n2 18\n15 19\n3 20\n10 21\n4 22\n9 24\n2 25\n23 26\n3 28\n20 29\n14 30\n4 32\n24 33\n20 36\n1 38\n19 39\n39 40\n22 41\n18 42\n19 43\n40 45\n45 46\n9 47\n6 48\n9 49\n25 50",
"output": "274877906944"
},
{
"input": "50 41\n1 3\n1 4\n2 5\n2 7\n1 8\n2 10\n4 11\n5 12\n12 13\n4 14\n10 17\n1 18\n1 21\n5 22\n14 23\n19 24\n13 25\n3 26\n11 27\n6 28\n26 29\n21 30\n17 31\n15 32\n1 33\n12 34\n23 36\n6 37\n15 38\n37 39\n31 40\n15 41\n25 42\n19 43\n20 44\n32 45\n44 46\n31 47\n2 48\n32 49\n27 50",
"output": "2199023255552"
},
{
"input": "50 47\n1 2\n1 3\n1 4\n1 5\n5 6\n2 7\n2 8\n2 9\n2 10\n8 11\n5 12\n11 13\n10 14\n6 15\n9 16\n1 17\n1 18\n8 19\n5 20\n5 21\n11 22\n2 23\n22 24\n24 25\n5 26\n21 27\n27 28\n8 29\n2 30\n4 31\n11 32\n17 33\n22 34\n25 35\n28 36\n28 37\n11 38\n17 39\n19 42\n6 43\n11 44\n29 45\n2 46\n24 47\n7 48\n3 49\n44 50",
"output": "140737488355328"
},
{
"input": "11 20\n3 6\n2 6\n2 9\n4 5\n9 11\n6 8\n5 6\n1 6\n4 11\n9 10\n5 10\n4 6\n3 8\n2 3\n1 7\n1 11\n2 7\n1 3\n3 7\n1 8",
"output": "1024"
},
{
"input": "26 17\n1 2\n2 3\n1 6\n6 7\n7 8\n2 9\n4 10\n3 11\n11 12\n9 13\n6 14\n2 16\n5 18\n6 19\n11 22\n15 24\n6 26",
"output": "131072"
},
{
"input": "48 43\n1 2\n1 3\n3 4\n4 5\n2 6\n5 7\n7 9\n4 10\n6 11\n3 12\n6 13\n3 14\n6 15\n13 16\n4 17\n12 18\n18 19\n1 20\n1 21\n16 22\n9 23\n3 24\n22 25\n2 26\n10 27\n18 28\n13 30\n3 31\n24 33\n29 34\n15 35\n16 36\n23 37\n21 38\n34 39\n37 40\n39 41\n19 42\n15 43\n23 44\n22 45\n14 47\n10 48",
"output": "8796093022208"
},
{
"input": "8 5\n1 2\n1 3\n1 4\n5 6\n7 8",
"output": "32"
},
{
"input": "8 7\n1 2\n2 3\n3 4\n1 4\n5 6\n6 7\n7 8",
"output": "64"
}
] | 46 | 0 | -1 | 1,188 |
|
336 | Vasily the Bear and Triangle | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique. | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-2000000000 0 0 -2000000000"
},
{
"input": "1000000000 1000000000",
"output": "0 2000000000 2000000000 0"
},
{
"input": "-123131 3123141",
"output": "-3246272 0 0 3246272"
},
{
"input": "-23423 -243242423",
"output": "-243265846 0 0 -243265846"
},
{
"input": "123112 4560954",
"output": "0 4684066 4684066 0"
},
{
"input": "1321 -23131",
"output": "0 -24452 24452 0"
},
{
"input": "1000000000 999999999",
"output": "0 1999999999 1999999999 0"
},
{
"input": "54543 432423",
"output": "0 486966 486966 0"
},
{
"input": "1 1",
"output": "0 2 2 0"
},
{
"input": "-1 -1",
"output": "-2 0 0 -2"
},
{
"input": "-1 1",
"output": "-2 0 0 2"
},
{
"input": "1 -1",
"output": "0 -2 2 0"
},
{
"input": "42 -2",
"output": "0 -44 44 0"
},
{
"input": "2 -435",
"output": "0 -437 437 0"
},
{
"input": "76 -76",
"output": "0 -152 152 0"
},
{
"input": "1000000000 1",
"output": "0 1000000001 1000000001 0"
},
{
"input": "1000000000 -1",
"output": "0 -1000000001 1000000001 0"
},
{
"input": "-1000000000 1",
"output": "-1000000001 0 0 1000000001"
},
{
"input": "-1000000000 -1",
"output": "-1000000001 0 0 -1000000001"
},
{
"input": "1000000000 -999999999",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-1000000000 999999999",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "-1000000000 -999999999",
"output": "-1999999999 0 0 -1999999999"
},
{
"input": "999999999 1000000000",
"output": "0 1999999999 1999999999 0"
},
{
"input": "-999999999 1000000000",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "999999999 -1000000000",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-999999999 -1000000000",
"output": "-1999999999 0 0 -1999999999"
}
] | 278 | 0 | 0 | 1,197 |
|
295 | Greg and Graph | [
"dp",
"graphs",
"shortest paths"
] | null | null | Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:
- The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex. - Before executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that *d*(*i*,<=*v*,<=*u*) is the shortest path between vertices *v* and *u* in the graph that formed before deleting vertex *x**i*, then Greg wants to know the value of the following sum: .
Help Greg, print the value of the required sum before each step. | The first line contains integer *n* (1<=≤<=*n*<=≤<=500) — the number of vertices in the graph.
Next *n* lines contain *n* integers each — the graph adjacency matrix: the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*a**ij*<=≤<=105,<=*a**ii*<==<=0) represents the weight of the edge that goes from vertex *i* to vertex *j*.
The next line contains *n* distinct integers: *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=*n*) — the vertices that Greg deletes. | Print *n* integers — the *i*-th number equals the required sum before the *i*-th step.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"1\n0\n1\n",
"2\n0 5\n4 0\n1 2\n",
"4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n"
] | [
"0 ",
"9 0 ",
"17 23 404 0 "
] | none | [
{
"input": "1\n0\n1",
"output": "0 "
},
{
"input": "2\n0 5\n4 0\n1 2",
"output": "9 0 "
},
{
"input": "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3",
"output": "17 23 404 0 "
},
{
"input": "4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 97007 0\n2 3 1 4",
"output": "723897 306638 52930 0 "
},
{
"input": "5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 55784\n70744 17563 79061 0 73981\n70529 35681 91073 52031 0\n5 2 3 1 4",
"output": "896203 429762 232508 87178 0 "
},
{
"input": "6\n0 72137 71041 29217 96749 46417\n40199 0 55907 57677 68590 78796\n83463 50721 0 30963 31779 28646\n94529 47831 98222 0 61665 73941\n24397 66286 2971 81613 0 52501\n26285 3381 51438 45360 20160 0\n6 3 2 4 5 1",
"output": "1321441 1030477 698557 345837 121146 0 "
},
{
"input": "7\n0 34385 31901 51111 10191 14089 95685\n11396 0 8701 33277 1481 517 46253\n51313 2255 0 5948 66085 37201 65310\n21105 60985 10748 0 89271 42883 77345\n34686 29401 73565 47795 0 13793 66997\n70279 49576 62900 40002 70943 0 89601\n65045 1681 28239 12023 40414 89585 0\n3 5 7 6 1 2 4",
"output": "1108867 1016339 729930 407114 206764 94262 0 "
},
{
"input": "8\n0 74961 47889 4733 72876 21399 63105 48239\n15623 0 9680 89133 57989 63401 26001 29608\n42369 82390 0 32866 46171 11871 67489 54070\n23425 80027 18270 0 28105 42657 40876 29267\n78793 18701 7655 94798 0 88885 71424 86914\n44835 76636 11553 46031 13617 0 16971 51915\n33037 53719 43116 52806 56897 71241 0 11629\n2119 62373 93265 69513 5770 90751 36619 0\n3 7 6 5 8 1 2 4",
"output": "1450303 1188349 900316 531281 383344 219125 169160 0 "
},
{
"input": "9\n0 85236 27579 82251 69479 24737 87917 15149 52311\n59640 0 74687 34711 3685 30121 4961 7552 83399\n33376 68733 0 81357 18042 74297 15466 29476 5865\n7493 5601 3321 0 20263 55901 45756 55361 87633\n26751 17161 76681 40376 0 39745 50717 56887 90055\n18885 76353 47089 43601 21561 0 60571 33551 53753\n74595 877 71853 93156 97499 70876 0 22713 63961\n67725 25309 56358 92376 40641 35433 39781 0 97482\n81818 12561 85961 81445 3941 76799 31701 43725 0\n6 2 9 3 5 7 1 4 8",
"output": "2106523 1533575 1645151 1255230 946667 618567 287636 147737 0 "
}
] | 216 | 3,174,400 | 0 | 1,198 |
|
501 | Misha and Changing Handles | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description. | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k",
"output": "1\na k"
},
{
"input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha",
"output": "2\n123abc 1A2B3C\n1 Misha"
},
{
"input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e",
"output": "3\nM G\n1 R\nS e"
},
{
"input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV",
"output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV"
},
{
"input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI",
"output": "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9"
},
{
"input": "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6",
"output": "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ"
},
{
"input": "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ",
"output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ"
}
] | 0 | 0 | -1 | 1,199 |
|
867 | Between the Offices | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 93 | 0 | 3 | 1,200 |
|
177 | Good Matrix Elements | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix. | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101 | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
"output": "756"
},
{
"input": "3\n19 7 16\n12 15 5\n15 15 5",
"output": "109"
},
{
"input": "3\n36 4 33\n11 46 32\n20 49 34",
"output": "265"
},
{
"input": "3\n79 91 74\n33 82 22\n18 28 54",
"output": "481"
},
{
"input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6",
"output": "65"
},
{
"input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6",
"output": "225"
},
{
"input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6",
"output": "495"
},
{
"input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6",
"output": "705"
},
{
"input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83",
"output": "708"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "3\n0 0 0\n0 0 0\n0 0 0",
"output": "0"
}
] | 218 | 307,200 | 3 | 1,205 |
|
746 | Decoding | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 62 | 409,600 | 3 | 1,206 |
|
598 | Queries on a String | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa. | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query. | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
{
"input": "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8",
"output": "zctycopttp"
},
{
"input": "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 8 7\n2 7 5",
"output": "bylwlwylbb"
},
{
"input": "thisisahacktest\n1\n1 2 1",
"output": "htisisahacktest"
},
{
"input": "ozozumuhackleyan\n1\n1 4 1",
"output": "zozoumuhackleyan"
},
{
"input": "lacongaithattuyet\n1\n1 1 1",
"output": "lacongaithattuyet"
}
] | 795 | 512,000 | 3 | 1,207 |
|
165 | Another Problem on Strings | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.
You are given a binary string *s*. Your task is to find the number of its substrings, containing exactly *k* characters "1". | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
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. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
},
{
"input": "988205\n000110001001000",
"output": "0"
},
{
"input": "10\n1011110011111001100",
"output": "8"
},
{
"input": "0\n000",
"output": "6"
},
{
"input": "16\n1111011111110110111111111",
"output": "8"
},
{
"input": "0\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0",
"output": "0"
},
{
"input": "2\n1",
"output": "0"
},
{
"input": "1000000\n0",
"output": "0"
},
{
"input": "1000000\n1",
"output": "0"
},
{
"input": "0\n00",
"output": "3"
},
{
"input": "0\n01",
"output": "1"
},
{
"input": "0\n10",
"output": "1"
},
{
"input": "0\n11",
"output": "0"
},
{
"input": "1\n00",
"output": "0"
},
{
"input": "1\n01",
"output": "2"
},
{
"input": "1\n10",
"output": "2"
},
{
"input": "1\n11",
"output": "2"
},
{
"input": "2\n00",
"output": "0"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "94\n111111111111010111100111111111111011011111111011111111111011111111111111101111101111110111011111111110011111111001111101111",
"output": "17"
}
] | 92 | 6,656,000 | -1 | 1,214 |
|
200 | Drinks | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 92 | 0 | 3 | 1,221 |
|
227 | Where do I Turn? | [
"geometry"
] | null | null | Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight road and met point *B* on his way. The hero knows that in this land for every pair of roads it is true that they are either parallel to each other, or lie on a straight line, or are perpendicular to each other. He also knows well that points *B* and *C* are connected by a road. So the hero must either turn 90 degrees to the left or continue riding straight ahead or turn 90 degrees to the right. But he forgot where the point *C* is located.
Fortunately, a Brave Falcon flew right by. It can see all three points from the sky. The hero asked him what way to go to get to the dragon's lair.
If you have not got it, you are the falcon. Help the hero and tell him how to get him to point *C*: turn left, go straight or turn right.
At this moment the hero is believed to stand at point *B*, turning his back to point *A*. | The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≤<=109) — the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*.
It is guaranteed that all points are pairwise different. It is also guaranteed that either point *B* lies on segment *AC*, or angle *ABC* is right. | Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes). | [
"0 0\n0 1\n1 1\n",
"-1 -1\n-3 -3\n-4 -4\n",
"-4 -6\n-3 -7\n-2 -6\n"
] | [
"RIGHT\n",
"TOWARDS\n",
"LEFT\n"
] | The picture to the first sample:
The red color shows points A, B and C. The blue arrow shows the hero's direction. The green color shows the hero's trajectory.
The picture to the second sample: | [
{
"input": "0 0\n0 1\n1 1",
"output": "RIGHT"
},
{
"input": "-1 -1\n-3 -3\n-4 -4",
"output": "TOWARDS"
},
{
"input": "-4 -6\n-3 -7\n-2 -6",
"output": "LEFT"
},
{
"input": "-44 57\n-118 -41\n-216 33",
"output": "RIGHT"
},
{
"input": "39 100\n90 85\n105 136",
"output": "LEFT"
},
{
"input": "71 43\n96 -15\n171 -189",
"output": "TOWARDS"
},
{
"input": "-22 -84\n-117 8\n-25 103",
"output": "RIGHT"
},
{
"input": "28 -81\n49 -85\n45 -106",
"output": "RIGHT"
},
{
"input": "-20 -60\n-39 -45\n-24 -26",
"output": "RIGHT"
},
{
"input": "-61 -24\n-61 35\n-120 35",
"output": "LEFT"
},
{
"input": "-19 27\n-115 -63\n-25 -159",
"output": "LEFT"
},
{
"input": "53 69\n147 114\n102 208",
"output": "LEFT"
},
{
"input": "22 -38\n22 -128\n22 -398",
"output": "TOWARDS"
},
{
"input": "47 16\n-13 -52\n-253 -324",
"output": "TOWARDS"
},
{
"input": "71 -22\n10 -1\n-417 146",
"output": "TOWARDS"
},
{
"input": "-783785 244379\n-827111 1135071\n63581 1178397",
"output": "RIGHT"
},
{
"input": "3609 -639705\n294730 -1024276\n-89841 -1315397",
"output": "RIGHT"
},
{
"input": "47715 -171800\n-228153 -358383\n-414736 -82515",
"output": "RIGHT"
},
{
"input": "-702371 875896\n-1445450 1767452\n-2337006 1024373",
"output": "LEFT"
},
{
"input": "-508160 -332418\n-1151137 415692\n-1899247 -227285",
"output": "LEFT"
},
{
"input": "-756864 833019\n-105276 568688\n159055 1220276",
"output": "LEFT"
},
{
"input": "635167 -889045\n1429362 -1770135\n2223557 -2651225",
"output": "TOWARDS"
},
{
"input": "-897142 527212\n-313890 206605\n2019118 -1075823",
"output": "TOWARDS"
},
{
"input": "8662 -907734\n-73417 -1195869\n-401733 -2348409",
"output": "TOWARDS"
},
{
"input": "-752889181 -922273353\n-495897323 -117405233\n308970797 -374397091",
"output": "RIGHT"
},
{
"input": "-143491154 -462477108\n173292223 111677574\n747446905 -205105803",
"output": "RIGHT"
},
{
"input": "419299232 564945785\n960228923 -229158901\n166124237 -770088592",
"output": "RIGHT"
},
{
"input": "85768877 -347290108\n332919696 -655546541\n641176129 -408395722",
"output": "LEFT"
},
{
"input": "708149426 502573762\n-210552252 335164034\n-43142524 -583537644",
"output": "LEFT"
},
{
"input": "640934661 -321662897\n-332613133 326172546\n-980448576 -647375248",
"output": "LEFT"
},
{
"input": "-951852504 776750379\n-698326409 275687363\n-191274219 -726438669",
"output": "TOWARDS"
},
{
"input": "507851078 -147339692\n440808462 -4699564\n373765846 137940564",
"output": "TOWARDS"
},
{
"input": "579796456 -149651968\n516495557 -133472697\n-369717029 93037097",
"output": "TOWARDS"
},
{
"input": "0 -1800000\n0 0\n10000000 0",
"output": "RIGHT"
},
{
"input": "0 994599799\n0 0\n-999999928 0",
"output": "RIGHT"
},
{
"input": "-1000000000 0\n0 0\n0 1000000000",
"output": "LEFT"
},
{
"input": "1000000000 1000000000\n-1000000000 1000000000\n-1000000000 -1000000000",
"output": "LEFT"
},
{
"input": "0 0\n1 0\n1 1",
"output": "LEFT"
},
{
"input": "0 0\n0 1000000000\n1000000000 1000000000",
"output": "RIGHT"
},
{
"input": "998000000 999000000\n999000000 1000000000\n1000000000 999000000",
"output": "RIGHT"
},
{
"input": "0 0\n1000000000 0\n1000000000 1000000000",
"output": "LEFT"
},
{
"input": "0 0\n1111111 1111111\n2222222 0",
"output": "RIGHT"
},
{
"input": "0 0\n100000007 0\n100000007 -999999999",
"output": "RIGHT"
},
{
"input": "-1000000000 1000000000\n-1000000000 -1000000000\n1000000000 -1000000000",
"output": "LEFT"
},
{
"input": "0 1000000000\n0 -99999999\n-99999999 -99999999",
"output": "RIGHT"
},
{
"input": "1000000000 1000000000\n1000000000 0\n0 0",
"output": "RIGHT"
},
{
"input": "0 0\n100000000 100000000\n1000000000 1000000000",
"output": "TOWARDS"
},
{
"input": "0 -1000000000\n0 0\n1000000000 0",
"output": "RIGHT"
}
] | 124 | 3,379,200 | -1 | 1,222 |
|
719 | Anatoly and Cockroaches | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 46 | 204,800 | 0 | 1,224 |
|
45 | TCMCF+++ | [
"greedy"
] | I. TCMCF+++ | 2 | 256 | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of the suggested problems. The next line contains *n* space-separated integers *c**i* (<=-<=100<=≤<=*c**i*<=≤<=100) — the cost of the *i*-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | [
"5\n1 2 -3 3 3\n",
"13\n100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"4\n-2 -2 -2 -2\n"
] | [
"3 1 2 3 \n",
"100 100 100 100 100 100 100 100 100 100 100 100 100 \n",
"-2 -2 -2 -2 \n"
] | none | [
{
"input": "5\n1 2 -3 3 3",
"output": "3 1 2 3 "
},
{
"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "4\n-2 -2 -2 -2",
"output": "-2 -2 -2 -2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "1\n-1",
"output": "-1 "
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1 1 "
},
{
"input": "2\n1 -1",
"output": "1 "
},
{
"input": "2\n-1 1",
"output": "1 "
},
{
"input": "2\n-1 -1",
"output": "-1 -1 "
},
{
"input": "2\n1 0",
"output": "1 "
},
{
"input": "2\n0 1",
"output": "1 "
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n-1 0",
"output": "0"
},
{
"input": "2\n0 -1",
"output": "0"
},
{
"input": "1\n13",
"output": "13 "
},
{
"input": "1\n-13",
"output": "-13 "
},
{
"input": "1\n100",
"output": "100 "
},
{
"input": "1\n-100",
"output": "-100 "
},
{
"input": "2\n100 100",
"output": "100 100 "
},
{
"input": "2\n100 -100",
"output": "100 "
},
{
"input": "2\n-100 100",
"output": "100 "
},
{
"input": "2\n100 0",
"output": "100 "
},
{
"input": "2\n0 100",
"output": "100 "
},
{
"input": "2\n0 -100",
"output": "0"
},
{
"input": "2\n-100 0",
"output": "0"
},
{
"input": "1\n3",
"output": "3 "
},
{
"input": "2\n0 -1",
"output": "0"
},
{
"input": "2\n-1 2",
"output": "2 "
},
{
"input": "2\n2 2",
"output": "2 2 "
},
{
"input": "2\n-1 -2",
"output": "-1 -2 "
},
{
"input": "2\n-2 -1",
"output": "-1 -2 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "2\n0 -2",
"output": "0"
},
{
"input": "2\n-2 -1",
"output": "-1 -2 "
},
{
"input": "3\n0 -2 -1",
"output": "-1 -2 "
},
{
"input": "3\n2 1 -1",
"output": "2 1 "
},
{
"input": "3\n0 1 2",
"output": "2 1 "
},
{
"input": "3\n-2 2 2",
"output": "2 2 "
},
{
"input": "3\n1 -1 2",
"output": "2 1 "
},
{
"input": "3\n-2 0 2",
"output": "2 "
},
{
"input": "3\n1 0 2",
"output": "2 1 "
},
{
"input": "3\n-1 2 2",
"output": "2 2 "
},
{
"input": "4\n0 0 2 -2",
"output": "2 "
},
{
"input": "4\n1 0 -1 2",
"output": "2 1 "
},
{
"input": "4\n-2 0 -2 0",
"output": "-2 -2 "
},
{
"input": "4\n2 2 1 -1",
"output": "2 1 2 "
},
{
"input": "4\n-1 2 0 -2",
"output": "2 -1 -2 "
},
{
"input": "4\n1 2 -2 1",
"output": "2 1 1 "
},
{
"input": "4\n-2 -1 2 2",
"output": "2 -1 2 -2 "
},
{
"input": "4\n-1 -1 -2 0",
"output": "-1 -2 "
},
{
"input": "10\n-10 5 9 -10 2 -7 10 10 6 -9",
"output": "10 -10 -9 -7 2 5 6 9 10 -10 "
},
{
"input": "10\n9 10 9 10 10 10 1 5 10 5",
"output": "10 5 5 9 9 10 10 10 10 1 "
},
{
"input": "10\n-3 -9 -10 -10 -9 -8 -9 -9 -8 -9",
"output": "-3 -10 -9 -9 -9 -9 -9 -8 -8 -10 "
},
{
"input": "10\n-5 -5 4 1 -8 -3 -9 -2 4 4",
"output": "4 -8 -5 -5 -3 -2 1 4 4 -9 "
},
{
"input": "100\n-74 11 -35 -39 31 -39 43 43 2 -78 -17 -16 -70 41 -96 -70 -89 48 -98 -44 47 -92 49 20 47 -23 -19 -24 7 -79 16 18 0 29 -43 -98 27 50 -65 -50 44 -66 -64 -34 -77 -38 22 18 8 30 -62 -37 -3 -80 -94 15 -50 -61 6 -97 35 24 -19 -79 -47 -4 4 38 -37 -51 -31 -24 -3 -3 -94 -99 -87 -35 48 -57 16 -2 6 -13 -5 -60 -39 -61 -42 7 -14 -4 -99 -32 31 17 -84 13 -72 -37",
"output": "50 -99 -98 -98 -97 -96 -94 -94 -92 -89 -87 -84 -80 -79 -79 -78 -77 -74 -72 -70 -70 -66 -65 -64 -62 -61 -61 -60 -57 -51 -50 -50 -47 -44 -43 -42 -39 -39 -39 -38 -37 -37 -37 -35 -35 -34 -32 -31 -24 -24 -23 -19 -19 -17 -16 -14 -13 -5 -4 -4 -3 -3 -3 -2 2 4 6 6 7 7 8 11 13 15 16 16 17 18 18 20 22 24 27 29 30 31 31 35 38 41 43 43 44 47 47 48 48 49 -99 "
},
{
"input": "100\n8 -63 12 -31 48 1 11 7 -18 -25 -3 11 -23 44 31 33 -10 44 46 -62 29 5 -4 -35 -1 0 -20 34 -18 -46 -9 46 41 42 -69 18 24 48 50 13 -24 -19 37 -21 8 50 30 24 -48 36 -42 -43 31 50 -17 -29 -27 9 50 47 36 -50 6 -51 12 49 -1 -15 37 -44 -19 46 27 5 -37 17 19 39 11 42 44 43 -48 -1 31 -80 -30 -35 -19 50 35 -56 -1 20 50 -13 27 39 -20 -15",
"output": "50 -69 -63 -62 -56 -51 -50 -48 -48 -46 -44 -43 -42 -37 -35 -35 -31 -30 -29 -27 -25 -24 -23 -21 -20 -20 -19 -19 -19 -18 -18 -17 -15 -15 -13 -10 -9 -4 -3 -1 -1 -1 1 5 5 6 7 8 8 9 11 11 11 12 12 13 17 18 19 20 24 24 27 27 29 30 31 31 31 33 34 35 36 36 37 37 39 39 41 42 42 43 44 44 44 46 46 46 47 48 48 49 50 50 50 50 50 -80 "
},
{
"input": "100\n-39 -43 43 18 -21 -24 -8 -29 -32 -12 50 35 5 1 42 -24 44 37 6 25 -39 17 32 -67 49 -19 -19 50 45 17 -48 17 -11 -16 47 44 29 -29 30 1 50 -4 35 -18 0 -9 -14 31 49 34 -25 36 37 9 3 26 43 25 40 24 48 21 -18 50 -10 26 39 29 45 1 48 34 14 -48 17 0 50 33 -4 31 31 -63 10 26 22 8 50 -15 1 -1 -15 13 -47 25 3 45 22 -5 -16 32",
"output": "50 -63 -48 -48 -47 -43 -39 -39 -32 -29 -29 -25 -24 -24 -21 -19 -19 -18 -18 -16 -16 -15 -15 -14 -12 -11 -10 -9 -8 -5 -4 -4 1 1 1 1 3 3 5 6 8 9 10 13 14 17 17 17 17 18 21 22 22 24 25 25 25 26 26 26 29 29 30 31 31 31 32 32 33 34 34 35 35 36 37 37 39 40 42 43 43 44 44 45 45 45 47 48 48 49 49 50 50 50 50 50 -67 "
},
{
"input": "100\n43 17 39 -15 9 24 28 21 42 -56 9 12 -53 -30 -1 26 39 44 50 46 47 22 29 11 30 42 27 34 31 31 46 7 33 47 48 2 44 -19 33 32 22 23 39 34 -8 1 -18 33 43 45 47 39 -15 44 50 32 42 42 46 -13 28 35 31 -31 13 30 -10 0 9 50 24 38 24 -48 20 43 13 46 26 36 43 32 48 5 -5 39 37 41 -4 -6 -9 32 42 -3 31 37 39 48 26 38",
"output": "50 -53 -48 -31 -30 -19 -18 -15 -15 -13 -10 -9 -8 -6 -5 -4 -3 -1 1 2 5 7 9 9 9 11 12 13 13 17 20 21 22 22 23 24 24 24 26 26 26 27 28 28 29 30 30 31 31 31 31 32 32 32 32 33 33 33 34 34 35 36 37 37 38 38 39 39 39 39 39 39 41 42 42 42 42 42 43 43 43 43 44 44 44 45 46 46 46 46 47 47 47 48 48 48 50 50 -56 "
},
{
"input": "100\n35 41 38 39 46 -1 19 42 34 22 0 -23 48 24 41 12 11 4 4 35 35 2 9 33 50 30 15 21 44 47 47 27 31 24 40 14 22 26 45 1 35 31 13 8 48 50 31 36 26 26 48 41 6 -19 17 17 16 3 38 42 41 35 19 31 15 -48 43 6 -32 -18 -2 41 44 29 11 46 43 48 -12 34 30 -10 -7 44 47 24 44 32 36 29 15 25 25 -19 26 46 36 37 -10 45",
"output": "50 -32 -23 -19 -19 -18 -12 -10 -10 -7 -2 -1 1 2 3 4 4 6 6 8 9 11 11 12 13 14 15 15 15 16 17 17 19 19 21 22 22 24 24 24 25 25 26 26 26 26 27 29 29 30 30 31 31 31 31 32 33 34 34 35 35 35 35 35 36 36 36 37 38 38 39 40 41 41 41 41 41 42 42 43 43 44 44 44 44 45 45 46 46 46 47 47 47 48 48 48 48 50 -48 "
},
{
"input": "100\n42 -14 90 5 0 62 14 36 -76 -94 69 25 -2 40 -49 62 -38 0 -96 49 -24 -92 55 18 22 42 -25 72 -52 47 78 98 80 -27 -64 -4 -38 -93 -15 40 -78 -49 -49 21 50 -13 34 0 78 84 55 -95 -52 -3 -46 -49 53 23 -49 -98 -1 47 48 -93 25 37 -71 -23 74 -58 -39 -43 -14 -57 98 -6 9 -56 88 -88 7 71 -60 95 -9 15 55 63 -75 -29 -90 -38 -61 -97 9 -40 89 92 -37 50",
"output": "98 -97 -96 -95 -94 -93 -93 -92 -90 -88 -78 -76 -75 -71 -64 -61 -60 -58 -57 -56 -52 -52 -49 -49 -49 -49 -49 -46 -43 -40 -39 -38 -38 -38 -37 -29 -27 -25 -24 -23 -15 -14 -14 -13 -9 -6 -4 -3 -2 -1 5 7 9 9 14 15 18 21 22 23 25 25 34 36 37 40 40 42 42 47 47 48 49 50 50 53 55 55 55 62 62 63 69 71 72 74 78 78 80 84 88 89 90 92 95 98 -98 "
},
{
"input": "100\n-60 98 -34 30 48 69 -50 70 3 85 67 73 -23 64 31 98 57 84 54 81 24 37 41 -29 73 -6 3 62 -23 86 67 -8 79 38 60 64 -65 78 81 95 98 100 38 -46 -6 -4 14 18 58 95 94 57 21 66 8 26 89 99 74 46 69 75 97 54 29 79 1 -90 67 61 24 62 78 -1 96 82 23 87 9 87 2 -50 -26 30 74 52 -28 39 69 67 6 56 74 93 13 -22 23 97 70 -45",
"output": "100 -65 -60 -50 -50 -46 -45 -34 -29 -28 -26 -23 -23 -22 -8 -6 -6 -4 1 2 3 3 6 8 9 13 14 18 21 23 23 24 24 26 29 30 30 31 37 38 38 39 41 46 48 52 54 54 56 57 57 58 60 61 62 62 64 64 66 67 67 67 67 69 69 69 70 70 73 73 74 74 74 75 78 78 79 79 81 81 82 84 85 86 87 87 89 93 94 95 95 96 97 97 98 98 98 99 -90 "
},
{
"input": "100\n16 -41 -52 -100 -74 -57 -57 -49 63 -71 -26 -96 -50 -49 -57 -66 -27 -32 -99 6 -24 14 -79 -57 -82 -81 17 -54 -47 3 -66 -100 2 -35 -18 -83 12 46 -37 -19 -1 30 -93 -59 57 -69 -43 -83 -91 -28 -67 -17 -18 13 -35 57 -59 -85 33 -77 -74 92 -58 -82 -59 42 29 -54 -50 -89 -39 68 -64 -86 37 -73 -68 -85 -51 -25 -31 -10 -70 32 1 -64 -47 27 -86 -7 24 -55 -73 -88 21 -3 61 -61 -44 -24",
"output": "92 -100 -99 -96 -93 -91 -89 -88 -86 -86 -85 -85 -83 -83 -82 -82 -81 -79 -77 -74 -74 -73 -73 -71 -70 -69 -68 -67 -66 -66 -64 -64 -61 -59 -59 -59 -58 -57 -57 -57 -57 -55 -54 -54 -52 -51 -50 -50 -49 -49 -47 -47 -44 -43 -41 -39 -37 -35 -35 -32 -31 -28 -27 -26 -25 -24 -24 -19 -18 -18 -17 -10 -7 -3 1 2 3 6 12 13 14 16 17 21 24 27 29 30 32 33 37 42 46 57 57 61 63 68 -100 "
},
{
"input": "100\n99 100 100 99 99 96 100 100 100 98 98 99 100 99 98 98 97 99 99 100 94 100 99 98 97 100 98 99 100 99 97 91 99 95 95 97 99 99 100 98 100 99 99 100 99 100 100 93 96 96 93 99 99 99 100 96 100 97 92 100 100 100 97 100 100 99 98 98 95 97 96 92 97 100 100 90 98 100 100 99 100 98 99 99 100 97 94 99 100 100 99 99 99 100 99 100 96 99 98 100",
"output": "100 91 92 92 93 93 94 94 95 95 95 96 96 96 96 96 96 97 97 97 97 97 97 97 97 97 98 98 98 98 98 98 98 98 98 98 98 98 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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 90 "
},
{
"input": "100\n-93 -100 -99 -100 -99 -100 -99 -99 -99 -100 -99 -99 -100 -98 -98 -100 -99 -100 -95 -100 -100 -99 -98 -100 -96 -99 -99 -100 -97 -98 -100 -98 -98 -93 -100 -100 -99 -100 -100 -98 -100 -98 -100 -98 -97 -99 -98 -99 -99 -99 -100 -100 -100 -100 -98 -93 -100 -100 -97 -100 -100 -100 -98 -99 -100 -95 -98 -99 -100 -100 -99 -99 -100 -98 -100 -100 -100 -100 -96 -100 -93 -97 -100 -100 -99 -93 -92 -98 -97 -94 -100 -100 -99 -98 -100 -100 -100 -99 -99 -100",
"output": "-92 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -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 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -98 -97 -97 -97 -97 -97 -96 -96 -95 -95 -94 -93 -93 -93 -93 -93 -100 "
}
] | 0 | 0 | -1 | 1,226 |
574 | Bear and Three Musketeers | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other. | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
"input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11",
"output": "4"
},
{
"input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5",
"output": "27"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 2\n2 3\n2 1",
"output": "-1"
},
{
"input": "3 3\n3 1\n3 2\n2 1",
"output": "0"
},
{
"input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2",
"output": "3"
},
{
"input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6",
"output": "2"
},
{
"input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1",
"output": "3"
},
{
"input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4",
"output": "7"
},
{
"input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204",
"output": "6"
},
{
"input": "4000 0",
"output": "-1"
}
] | 2,000 | 71,270,400 | 0 | 1,228 |
|
358 | Dima and Continuous Line | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).
Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696",
"output": "yes"
},
{
"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": "no"
},
{
"input": "11\n1 11 10 2 3 9 8 4 5 7 6",
"output": "no"
},
{
"input": "10\n3 2 4 5 1 6 9 7 8 10",
"output": "yes"
},
{
"input": "11\n3 4 2 5 1 6 11 7 10 8 9",
"output": "no"
},
{
"input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8",
"output": "no"
},
{
"input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3",
"output": "yes"
},
{
"input": "1\n0",
"output": "no"
},
{
"input": "4\n3 1 4 2",
"output": "yes"
},
{
"input": "5\n0 2 4 -2 5",
"output": "no"
},
{
"input": "5\n1 9 8 7 0",
"output": "yes"
},
{
"input": "3\n5 10 0",
"output": "no"
},
{
"input": "6\n1 3 -1 5 2 4",
"output": "yes"
},
{
"input": "4\n3 2 4 1",
"output": "no"
},
{
"input": "4\n10 5 15 0",
"output": "no"
},
{
"input": "2\n-5 -10",
"output": "no"
},
{
"input": "3\n1 0 3",
"output": "no"
},
{
"input": "4\n-2 -4 1 -3",
"output": "yes"
},
{
"input": "4\n3 6 0 2",
"output": "no"
},
{
"input": "4\n-9 10 -10 0",
"output": "yes"
},
{
"input": "4\n5 10 1 15",
"output": "no"
},
{
"input": "3\n1 0 2",
"output": "no"
},
{
"input": "4\n2 3 4 1",
"output": "no"
},
{
"input": "4\n7 5 9 12",
"output": "no"
}
] | 62 | 0 | 0 | 1,229 |
|
573 | Bear and Poker | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 2,000 | 10,137,600 | 0 | 1,231 |
|
259 | Little Elephant and Magic Square | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 280 | 0 | 3 | 1,237 |
|
712 | Memory and Crow | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1",
"output": "0 0 0 0 0 0 0 0 0 -1 "
},
{
"input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 0 0 0 0 0 0 0 0 1000000000 "
},
{
"input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12",
"output": "656 -110 5840 6358 828 717 7359 7628 22 -12 "
},
{
"input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240",
"output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 "
}
] | 421 | 8,294,400 | 3 | 1,239 |
|
1,008 | Turn the Rectangles | [
"greedy",
"sortings"
] | null | null | There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.
Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles.
Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle. | Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"3\n3 4\n4 6\n3 5\n",
"2\n3 4\n5 5\n"
] | [
"YES\n",
"NO\n"
] | In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].
In the second test, there is no way the second rectangle will be not higher than the first one. | [
{
"input": "3\n3 4\n4 6\n3 5",
"output": "YES"
},
{
"input": "2\n3 4\n5 5",
"output": "NO"
},
{
"input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1",
"output": "NO"
},
{
"input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685",
"output": "NO"
},
{
"input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685",
"output": "YES"
},
{
"input": "1\n1 1",
"output": "YES"
},
{
"input": "4\n10 10\n8 8\n8 15\n9 9",
"output": "NO"
},
{
"input": "4\n10 10\n8 8\n8 9\n9 9",
"output": "NO"
},
{
"input": "3\n3 4\n4 5\n5 5",
"output": "NO"
},
{
"input": "3\n10 10\n5 5\n10 10",
"output": "NO"
},
{
"input": "3\n5 5\n4 6\n5 5",
"output": "NO"
},
{
"input": "3\n5 7\n3 9\n8 10",
"output": "NO"
},
{
"input": "3\n10 10\n1 1\n2 2",
"output": "NO"
},
{
"input": "3\n3 5\n1 2\n3 4",
"output": "NO"
},
{
"input": "3\n4 8\n6 25\n12 12",
"output": "NO"
},
{
"input": "3\n3 5\n4 10\n6 6",
"output": "NO"
},
{
"input": "3\n200 200\n300 20\n50 50",
"output": "NO"
},
{
"input": "3\n5 3\n6 4\n5 5",
"output": "NO"
},
{
"input": "4\n5 5\n4 6\n4 4\n5 5",
"output": "NO"
},
{
"input": "3\n10 10\n1 100\n20 20",
"output": "NO"
},
{
"input": "4\n1 3\n2 4\n3 5\n4 6",
"output": "NO"
},
{
"input": "3\n1 60\n70 55\n56 80",
"output": "NO"
},
{
"input": "3\n5 6\n5 7\n6 8",
"output": "NO"
},
{
"input": "3\n6 6\n5 7\n6 6",
"output": "NO"
}
] | 312 | 9,011,200 | 3 | 1,242 |
|
886 | Vlad and Cafes | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 186 | 13,516,800 | 3 | 1,243 |
|
596 | Wilbur and Array | [
"greedy",
"implementation"
] | null | null | Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*.
Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input.
The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). | Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. | [
"5\n1 2 3 4 5\n",
"4\n1 2 2 1\n"
] | [
"5",
"3"
] | In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.
In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1. | [
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 2 2 1",
"output": "3"
},
{
"input": "3\n1 2 4",
"output": "4"
},
{
"input": "6\n1 2 3 6 5 4",
"output": "8"
},
{
"input": "10\n2 1 4 3 6 5 8 7 10 9",
"output": "19"
},
{
"input": "7\n12 6 12 13 4 3 2",
"output": "36"
},
{
"input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7",
"output": "55"
},
{
"input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8",
"output": "36"
},
{
"input": "6\n1000 1 2000 1 3000 1",
"output": "11995"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n1000000000 1 1000000000 1 1000000000",
"output": "4999999996"
},
{
"input": "5\n1000000000 0 1000000000 0 1000000000",
"output": "5000000000"
},
{
"input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0",
"output": "10000000000"
},
{
"input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "19000000000"
},
{
"input": "7\n0 1000000000 0 1000000000 0 1000000000 0",
"output": "6000000000"
},
{
"input": "4\n1000000000 -1000000000 1000000000 -1000000000",
"output": "7000000000"
},
{
"input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "39000000000"
},
{
"input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000",
"output": "11000000000"
},
{
"input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "9000000000"
},
{
"input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "43000000000"
}
] | 295 | 18,841,600 | 3 | 1,244 |
|
1,009 | Minimum Ternary String | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
"input": "021",
"output": "012"
},
{
"input": "2",
"output": "2"
},
{
"input": "201",
"output": "120"
},
{
"input": "2112120",
"output": "1112220"
},
{
"input": "102",
"output": "012"
},
{
"input": "202",
"output": "202"
},
{
"input": "220201",
"output": "122020"
},
{
"input": "12",
"output": "12"
},
{
"input": "100022202",
"output": "000122202"
},
{
"input": "01",
"output": "01"
},
{
"input": "1",
"output": "1"
}
] | 217 | 1,024,000 | -1 | 1,245 |
|
701 | Cells Not Under Attack | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14",
"output": "841 784 729 702 650 600 600 552 506 484 441 400 380 380 361 342 324 289 272 272 255 240 225 225 210 196 182 182 168 143 "
},
{
"input": "70 31\n22 39\n33 43\n50 27\n70 9\n20 67\n61 24\n60 4\n60 28\n4 25\n30 29\n46 47\n51 48\n37 5\n14 29\n45 44\n68 35\n52 21\n7 37\n18 43\n44 22\n26 12\n39 37\n51 55\n50 23\n51 16\n16 49\n22 62\n35 45\n56 2\n20 51\n3 37",
"output": "4761 4624 4489 4356 4225 4096 3969 3906 3782 3660 3540 3422 3306 3249 3136 3025 2916 2809 2756 2652 2550 2499 2450 2401 2352 2256 2208 2115 2024 1978 1935 "
},
{
"input": "330 17\n259 262\n146 20\n235 69\n84 74\n131 267\n153 101\n32 232\n214 212\n239 157\n121 156\n10 45\n266 78\n52 258\n109 279\n193 276\n239 142\n321 89",
"output": "108241 107584 106929 106276 105625 104976 104329 103684 103041 102400 101761 101124 100489 99856 99225 98910 98282 "
},
{
"input": "500 43\n176 85\n460 171\n233 260\n73 397\n474 35\n290 422\n309 318\n280 415\n485 169\n106 22\n355 129\n180 301\n205 347\n197 93\n263 318\n336 382\n314 350\n476 214\n367 277\n333 166\n500 376\n236 17\n94 73\n116 204\n166 50\n168 218\n144 369\n340 91\n274 360\n171 360\n41 251\n262 478\n27 163\n151 491\n208 415\n448 386\n293 486\n371 479\n330 435\n220 374\n163 316\n155 158\n26 126",
"output": "249001 248004 247009 246016 245025 244036 243049 242064 241081 240100 239121 238144 237169 236196 235710 234740 233772 232806 231842 230880 229920 228962 228006 227052 226100 225150 224202 223256 222312 221840 220899 219960 219023 218088 217620 216688 215758 214830 213904 212980 212058 211138 210220 "
},
{
"input": "99999 1\n54016 16192",
"output": "9999600004 "
},
{
"input": "99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281",
"output": "9998000100 9997800121 9997600144 9997400169 9997200196 9997000225 9996800256 9996600289 9996400324 "
},
{
"input": "1 1\n1 1",
"output": "0 "
}
] | 670 | 18,739,200 | 3 | 1,246 |
|
557 | Arthur and Table | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg.
A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table. | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\n15 16 19 5 14 19 6 17 7 19\n140 183 186 195 67 25 70 56 54 132",
"output": "387"
},
{
"input": "20\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\n24 137 173 189 43 164 2 11 142 153 16 200 53 58 150 199 169 172 38 78",
"output": "1111"
},
{
"input": "30\n20 27 26 17 29 9 25 13 6 21 15 1 14 22 26 2 15 18 20 23 27 9 15 29 11 2 19 23 14 12\n133 199 22 151 9 134 196 119 197 189 117 84 156 6 61 195 98 197 145 75 142 85 187 24 159 3 60 138 156 161",
"output": "2804"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 3",
"output": "5"
},
{
"input": "5\n1 1 2 2 3\n2 2 2 2 7",
"output": "8"
},
{
"input": "10\n1 1 3 4 5 6 7 8 9 10\n10 10 4 2 3 4 2 2 2 2",
"output": "21"
},
{
"input": "1\n5\n4",
"output": "0"
},
{
"input": "2\n3 3\n4 5",
"output": "0"
},
{
"input": "2\n4 5\n3 3",
"output": "3"
},
{
"input": "3\n3 3 3\n1 2 3",
"output": "0"
},
{
"input": "3\n1 2 3\n3 3 3",
"output": "6"
}
] | 1,000 | 17,715,200 | 0 | 1,248 |
|
377 | Maze | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#"
},
{
"input": "1 1 0\n.",
"output": "."
},
{
"input": "2 3 1\n..#\n#..",
"output": "X.#\n#.."
},
{
"input": "2 3 1\n#..\n..#",
"output": "#.X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n..#",
"output": "...\n.#X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n#..",
"output": "...\nX#.\n#.."
},
{
"input": "5 4 4\n#..#\n....\n.##.\n....\n#..#",
"output": "#XX#\nXX..\n.##.\n....\n#..#"
},
{
"input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..",
"output": "X#..#\nX.#.#\n#....\n##.#.\n###.."
},
{
"input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#",
"output": "#.....\n#X#.#X\nX#...#\n...#.#"
},
{
"input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#",
"output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#"
},
{
"input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###",
"output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###"
},
{
"input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################",
"output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################"
},
{
"input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#",
"output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#"
},
{
"input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###",
"output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###"
},
{
"input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######",
"output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######"
},
{
"input": "3 5 1\n#...#\n..#..\n..#..",
"output": "#...#\n..#..\nX.#.."
},
{
"input": "4 5 10\n.....\n.....\n..#..\n..#..",
"output": "XXX..\nXXX..\nXX#..\nXX#.."
},
{
"input": "3 5 3\n.....\n..#..\n..#..",
"output": ".....\nX.#..\nXX#.."
},
{
"input": "3 5 1\n#....\n..#..\n..###",
"output": "#....\n..#.X\n..###"
},
{
"input": "4 5 1\n.....\n.##..\n..#..\n..###",
"output": ".....\n.##..\n..#.X\n..###"
},
{
"input": "3 5 2\n..#..\n..#..\n....#",
"output": "X.#..\nX.#..\n....#"
},
{
"input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########",
"output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########"
},
{
"input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###",
"output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###"
},
{
"input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..",
"output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.."
},
{
"input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..",
"output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.."
},
{
"input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########",
"output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########"
},
{
"input": "4 5 1\n.....\n.###.\n..#..\n..#..",
"output": ".....\n.###.\n..#..\n.X#.."
},
{
"input": "2 5 2\n###..\n###..",
"output": "###X.\n###X."
},
{
"input": "2 5 3\n.....\n..#..",
"output": "X....\nXX#.."
},
{
"input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############",
"output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n#####",
"output": ".....\n.##.X\n..###\n..###\n#####"
},
{
"input": "4 4 1\n....\n.#..\n..##\n..##",
"output": "....\n.#.X\n..##\n..##"
},
{
"input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##",
"output": "....#\n.##..\n.##.X\n...##\n...##"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n..###",
"output": ".....\n.##.X\n..###\n..###\n..###"
},
{
"input": "4 5 1\n#....\n#.#..\n..###\n..###",
"output": "#....\n#.#.X\n..###\n..###"
},
{
"input": "4 4 3\n....\n.#..\n..##\n..##",
"output": "...X\n.#XX\n..##\n..##"
},
{
"input": "4 7 6\n.......\n....#..\n.##.#..\n....#..",
"output": "X......\nX...#..\nX##.#..\nXXX.#.."
},
{
"input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######",
"output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######"
}
] | 46 | 6,963,200 | 0 | 1,249 |
|
576 | Vasya and Petya's Game | [
"math",
"number theory"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about. | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter. | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "20",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "37",
"output": "19\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 "
},
{
"input": "211",
"output": "61\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 169 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 "
},
{
"input": "557",
"output": "123\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 "
},
{
"input": "907",
"output": "179\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "953",
"output": "186\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "289",
"output": "78\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 "
},
{
"input": "400",
"output": "97\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 "
},
{
"input": "900",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "625",
"output": "136\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 "
},
{
"input": "729",
"output": "152\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "784",
"output": "160\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "31",
"output": "17\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 31 "
},
{
"input": "44",
"output": "21\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 41 43 "
},
{
"input": "160",
"output": "50\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 "
},
{
"input": "322",
"output": "83\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 "
},
{
"input": "894",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "998",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "30",
"output": "16\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 "
}
] | 155 | 1,228,800 | 3 | 1,251 |
|
911 | Nearest Minimums | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "2\n10000000 10000000",
"output": "1"
},
{
"input": "5\n100000000 100000001 100000000 100000001 100000000",
"output": "2"
},
{
"input": "9\n4 3 4 3 4 1 3 3 1",
"output": "3"
},
{
"input": "3\n10000000 1000000000 10000000",
"output": "2"
},
{
"input": "12\n5 6 6 5 6 1 9 9 9 9 9 1",
"output": "6"
},
{
"input": "5\n5 5 1 2 1",
"output": "2"
},
{
"input": "5\n2 2 1 3 1",
"output": "2"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "3\n100000005 1000000000 100000005",
"output": "2"
},
{
"input": "5\n1 2 2 2 1",
"output": "4"
},
{
"input": "3\n10000 1000000 10000",
"output": "2"
},
{
"input": "3\n999999999 999999998 999999998",
"output": "1"
},
{
"input": "6\n2 1 1 2 3 4",
"output": "1"
},
{
"input": "4\n1000000000 900000000 900000000 1000000000",
"output": "1"
},
{
"input": "5\n7 7 2 7 2",
"output": "2"
},
{
"input": "6\n10 10 1 20 20 1",
"output": "3"
},
{
"input": "2\n999999999 999999999",
"output": "1"
},
{
"input": "10\n100000 100000 1 2 3 4 5 6 7 1",
"output": "7"
},
{
"input": "10\n3 3 1 2 2 1 10 10 10 10",
"output": "3"
},
{
"input": "5\n900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n3 3 2 5 2",
"output": "2"
},
{
"input": "2\n100000000 100000000",
"output": "1"
},
{
"input": "10\n10 15 10 2 54 54 54 54 2 10",
"output": "5"
},
{
"input": "2\n999999 999999",
"output": "1"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n1000000000 100000000 1000000000 1000000000 100000000",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "2"
},
{
"input": "5\n1 3 2 3 1",
"output": "4"
},
{
"input": "5\n2 2 1 4 1",
"output": "2"
},
{
"input": "6\n1 2 2 2 2 1",
"output": "5"
},
{
"input": "7\n3 7 6 7 6 7 3",
"output": "6"
},
{
"input": "8\n1 2 2 2 2 1 2 2",
"output": "5"
},
{
"input": "10\n2 2 2 3 3 1 3 3 3 1",
"output": "4"
},
{
"input": "2\n88888888 88888888",
"output": "1"
},
{
"input": "3\n100000000 100000000 100000000",
"output": "1"
},
{
"input": "10\n1 3 2 4 5 5 4 3 2 1",
"output": "9"
},
{
"input": "5\n2 2 1 2 1",
"output": "2"
},
{
"input": "6\n900000005 900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n41 41 1 41 1",
"output": "2"
},
{
"input": "6\n5 5 1 3 3 1",
"output": "3"
},
{
"input": "8\n1 2 2 2 1 2 2 2",
"output": "4"
},
{
"input": "7\n6 6 6 6 1 8 1",
"output": "2"
},
{
"input": "3\n999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n5 5 4 10 4",
"output": "2"
},
{
"input": "11\n2 2 3 4 1 5 3 4 2 5 1",
"output": "6"
},
{
"input": "5\n3 5 4 5 3",
"output": "4"
},
{
"input": "6\n6 6 6 6 1 1",
"output": "1"
},
{
"input": "7\n11 1 3 2 3 1 11",
"output": "4"
},
{
"input": "5\n3 3 1 2 1",
"output": "2"
},
{
"input": "5\n4 4 2 5 2",
"output": "2"
},
{
"input": "4\n10000099 10000567 10000099 10000234",
"output": "2"
},
{
"input": "4\n100000009 100000011 100000012 100000009",
"output": "3"
},
{
"input": "2\n1000000 1000000",
"output": "1"
},
{
"input": "2\n10000010 10000010",
"output": "1"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "8\n2 6 2 8 1 9 8 1",
"output": "3"
},
{
"input": "5\n7 7 1 8 1",
"output": "2"
},
{
"input": "7\n1 3 2 3 2 3 1",
"output": "6"
},
{
"input": "7\n2 3 2 1 3 4 1",
"output": "3"
},
{
"input": "5\n1000000000 999999999 1000000000 1000000000 999999999",
"output": "3"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n5 5 3 5 3",
"output": "2"
},
{
"input": "6\n2 3 3 3 3 2",
"output": "5"
},
{
"input": "4\n1 1 2 2",
"output": "1"
},
{
"input": "5\n1 1 2 2 2",
"output": "1"
},
{
"input": "6\n2 1 1 2 2 2",
"output": "1"
},
{
"input": "5\n1000000000 1000000000 100000000 1000000000 100000000",
"output": "2"
},
{
"input": "7\n2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "8\n2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "10\n2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "11\n2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "12\n2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "13\n2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1000000000 100000000 100000000 1000000000",
"output": "1"
},
{
"input": "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1 2 3 1",
"output": "3"
},
{
"input": "8\n5 5 5 5 3 5 5 3",
"output": "3"
},
{
"input": "7\n2 3 2 1 4 4 1",
"output": "3"
},
{
"input": "6\n3 3 1 2 4 1",
"output": "3"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "5\n3 3 2 8 2",
"output": "2"
},
{
"input": "5\n1 2 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 1 2",
"output": "2"
},
{
"input": "5\n3 1 1 3 2",
"output": "1"
},
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "4\n2 2 1 1",
"output": "1"
},
{
"input": "5\n1 2 2 1 2",
"output": "3"
},
{
"input": "7\n2 1 2 1 1 2 1",
"output": "1"
},
{
"input": "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "85\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1",
"output": "84"
},
{
"input": "5\n1000000000 1000000000 999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n2 1 2 2 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n1 2 1 1",
"output": "1"
},
{
"input": "6\n1 3 4 2 4 1",
"output": "5"
},
{
"input": "9\n2 2 5 1 6 8 7 9 1",
"output": "5"
},
{
"input": "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999",
"output": "6"
},
{
"input": "7\n3 3 1 2 4 1 2",
"output": "3"
},
{
"input": "7\n3 3 1 2 3 4 1",
"output": "4"
},
{
"input": "8\n10 5 10 1 10 10 10 1",
"output": "4"
}
] | 124 | 14,438,400 | 3 | 1,252 |
|
104 | Blackjack | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points. | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
},
{
"input": "22",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "9",
"output": "0"
},
{
"input": "13",
"output": "4"
},
{
"input": "14",
"output": "4"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "4"
},
{
"input": "19",
"output": "4"
},
{
"input": "21",
"output": "4"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "0"
}
] | 124 | 5,632,000 | 3.95851 | 1,253 |
746 | Tram | [
"constructive algorithms",
"implementation",
"math"
] | null | null | The tram in Berland goes along a straight line from the point 0 to the point *s* and back, passing 1 meter per *t*1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points *x*<==<=0 and *x*<==<=*s*.
Igor is at the point *x*1. He should reach the point *x*2. Igor passes 1 meter per *t*2 seconds.
Your task is to determine the minimum time Igor needs to get from the point *x*1 to the point *x*2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point *x*1.
Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per *t*2 seconds). He can also stand at some point for some time. | The first line contains three integers *s*, *x*1 and *x*2 (2<=≤<=*s*<=≤<=1000, 0<=≤<=*x*1,<=*x*2<=≤<=*s*, *x*1<=≠<=*x*2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.
The second line contains two integers *t*1 and *t*2 (1<=≤<=*t*1,<=*t*2<=≤<=1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.
The third line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=*s*<=-<=1, *d* is either 1 or ) — the position of the tram in the moment Igor came to the point *x*1 and the direction of the tram at this moment. If , the tram goes in the direction from the point *s* to the point 0. If *d*<==<=1, the tram goes in the direction from the point 0 to the point *s*. | Print the minimum time in seconds which Igor needs to get from the point *x*1 to the point *x*2. | [
"4 2 4\n3 4\n1 1\n",
"5 4 0\n1 2\n3 1\n"
] | [
"8\n",
"7\n"
] | In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.
In the second example Igor can, for example, go towards the point *x*<sub class="lower-index">2</sub> and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point *x*<sub class="lower-index">2</sub> in 7 seconds in total. | [
{
"input": "4 2 4\n3 4\n1 1",
"output": "8"
},
{
"input": "5 4 0\n1 2\n3 1",
"output": "7"
},
{
"input": "5 4 0\n5 14\n1 -1",
"output": "55"
},
{
"input": "10 7 2\n7 9\n9 -1",
"output": "45"
},
{
"input": "20 5 19\n163 174\n4 1",
"output": "2436"
},
{
"input": "1000 610 733\n226 690\n357 1",
"output": "84870"
},
{
"input": "40 31 14\n628 1000\n36 1",
"output": "17000"
},
{
"input": "100 20 83\n186 434\n64 -1",
"output": "27342"
},
{
"input": "200 179 81\n126 457\n37 -1",
"output": "44786"
},
{
"input": "400 30 81\n193 1000\n338 1",
"output": "51000"
},
{
"input": "500 397 440\n202 1000\n75 1",
"output": "43000"
},
{
"input": "600 443 587\n260 1000\n548 -1",
"output": "144000"
},
{
"input": "799 254 294\n539 1000\n284 -1",
"output": "40000"
},
{
"input": "801 489 351\n86 702\n125 1",
"output": "96836"
},
{
"input": "999 951 297\n62 106\n574 1",
"output": "69324"
},
{
"input": "1000 711 437\n42 126\n745 1",
"output": "34356"
},
{
"input": "1000 812 761\n230 1000\n696 -1",
"output": "51000"
},
{
"input": "1000 913 474\n34 162\n566 -1",
"output": "71118"
},
{
"input": "1000 394 798\n155 673\n954 -1",
"output": "271560"
},
{
"input": "1000 876 884\n299 1000\n825 1",
"output": "8000"
},
{
"input": "2 0 2\n1 1\n1 1",
"output": "2"
},
{
"input": "5 4 2\n1 2\n3 1",
"output": "4"
},
{
"input": "4 2 4\n3 4\n2 1",
"output": "6"
},
{
"input": "200 10 100\n1 100\n20 1",
"output": "480"
},
{
"input": "6 4 2\n1 2\n3 1",
"output": "4"
},
{
"input": "3 1 3\n1 2\n1 1",
"output": "2"
},
{
"input": "10 3 6\n1 2\n3 1",
"output": "3"
},
{
"input": "1000 50 51\n1 3\n50 1",
"output": "1"
},
{
"input": "100 1 2\n1 100\n1 1",
"output": "1"
},
{
"input": "5 1 4\n1 100\n1 1",
"output": "3"
},
{
"input": "10 0 5\n1 100\n7 1",
"output": "18"
},
{
"input": "5 4 1\n1 100\n4 -1",
"output": "3"
},
{
"input": "10 6 9\n3 100\n5 1",
"output": "12"
},
{
"input": "50 10 30\n1 50\n10 1",
"output": "20"
},
{
"input": "4 1 4\n1 100\n2 1",
"output": "10"
},
{
"input": "10 5 9\n1 10\n5 1",
"output": "4"
},
{
"input": "20 15 10\n5 2\n3 1",
"output": "10"
},
{
"input": "2 2 0\n7 3\n1 1",
"output": "6"
},
{
"input": "10 1 9\n1 10\n1 1",
"output": "8"
},
{
"input": "1000 2 902\n1 1000\n2 1",
"output": "900"
},
{
"input": "100 9 6\n3 100\n5 1",
"output": "300"
},
{
"input": "10 1 6\n1 10\n3 -1",
"output": "9"
},
{
"input": "1000 902 2\n1 1000\n902 -1",
"output": "900"
},
{
"input": "100 50 25\n1 1000\n10 1",
"output": "165"
},
{
"input": "5 3 0\n1 2\n4 -1",
"output": "4"
},
{
"input": "4 1 2\n1 10\n3 1",
"output": "7"
},
{
"input": "10 4 8\n1 5\n4 -1",
"output": "12"
}
] | 62 | 0 | 0 | 1,255 |
|
499 | Lecture | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b",
"output": "f jpggvr b hnxsd b"
},
{
"input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb",
"output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs"
},
{
"input": "1 1\namit am\namit",
"output": "am"
},
{
"input": "1 1\na c\na",
"output": "a"
}
] | 61 | 19,456,000 | 0 | 1,256 |
|
740 | Alyona and flowers | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once. | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3",
"output": "10"
},
{
"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8",
"output": "0"
},
{
"input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2",
"output": "0"
},
{
"input": "3 3\n1 -1 3\n1 2\n2 3\n1 3",
"output": "5"
},
{
"input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6",
"output": "13"
},
{
"input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4",
"output": "50"
},
{
"input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5",
"output": "0"
},
{
"input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3",
"output": "59"
},
{
"input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3",
"output": "67"
},
{
"input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35",
"output": "170"
},
{
"input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13",
"output": "1502"
},
{
"input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54",
"output": "804"
},
{
"input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5",
"output": "103"
},
{
"input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3",
"output": "121"
},
{
"input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2",
"output": "27"
},
{
"input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7",
"output": "0"
},
{
"input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5",
"output": "26"
},
{
"input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3",
"output": "261"
},
{
"input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6",
"output": "81"
},
{
"input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5",
"output": "163"
},
{
"input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3",
"output": "0"
},
{
"input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8",
"output": "74"
},
{
"input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7",
"output": "0"
},
{
"input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5",
"output": "72"
},
{
"input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4",
"output": "79"
},
{
"input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4",
"output": "0"
},
{
"input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9",
"output": "0"
},
{
"input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3",
"output": "127"
},
{
"input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3",
"output": "140"
},
{
"input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3",
"output": "22"
},
{
"input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4",
"output": "6"
},
{
"input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71",
"output": "3076"
},
{
"input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27",
"output": "1366"
},
{
"input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6",
"output": "777"
},
{
"input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62",
"output": "82"
},
{
"input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4",
"output": "140"
},
{
"input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2",
"output": "9"
},
{
"input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4",
"output": "120"
}
] | 77 | 0 | 3 | 1,261 |
|
11 | Increasing Sequence | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,000 | 0 | 0 | 1,263 |
796 | Police Stations | [
"constructive algorithms",
"dfs and similar",
"dp",
"graphs",
"shortest paths",
"trees"
] | null | null | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most *d* kilometers along the roads.
There are *n* cities in the country, numbered from 1 to *n*, connected only by exactly *n*<=-<=1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has *k* police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city.
However, Zane feels like having as many as *n*<=-<=1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible.
Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads. | The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — each denoting the city each police station is located in.
The *i*-th of the following *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities directly connected by the road with index *i*.
It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within *d* kilometers. | In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down.
In the second line, print *s* distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | [
"6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n"
] | [
"1\n5\n",
"2\n4 5 "
] | In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | [
{
"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "1\n3 "
},
{
"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6",
"output": "2\n4 5 "
},
{
"input": "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "0"
},
{
"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11",
"output": "0"
},
{
"input": "2 1 1\n1\n1 2",
"output": "0"
}
] | 2,000 | 85,708,800 | 0 | 1,264 |
|
952 | Quirky Quantifiers | [
"math"
] | null | null | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999).
Output 0 or 1. | The input contains a single integer *a* (10<=≤<=*a*<=≤<=999). | Output 0 or 1. | [
"13\n",
"927\n",
"48\n"
] | [
"1\n",
"1\n",
"0\n"
] | none | [
{
"input": "13",
"output": "1"
},
{
"input": "927",
"output": "1"
},
{
"input": "48",
"output": "0"
},
{
"input": "10",
"output": "0"
},
{
"input": "999",
"output": "1"
},
{
"input": "142",
"output": "0"
},
{
"input": "309",
"output": "1"
},
{
"input": "572",
"output": "0"
},
{
"input": "835",
"output": "1"
},
{
"input": "990",
"output": "0"
},
{
"input": "168",
"output": "0"
},
{
"input": "431",
"output": "1"
},
{
"input": "694",
"output": "0"
},
{
"input": "957",
"output": "1"
},
{
"input": "932",
"output": "0"
}
] | 31 | 0 | 3 | 1,265 |
|
120 | Quiz League | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*. | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output": "3"
},
{
"input": "3 1\n0 1 0",
"output": "2"
},
{
"input": "3 3\n1 0 1",
"output": "3"
},
{
"input": "4 4\n1 0 1 0",
"output": "1"
},
{
"input": "5 3\n0 1 0 1 1",
"output": "4"
},
{
"input": "6 4\n1 0 0 0 0 1",
"output": "6"
},
{
"input": "7 5\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0",
"output": "82"
},
{
"input": "200 31\n1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0",
"output": "33"
},
{
"input": "17 13\n0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1",
"output": "13"
},
{
"input": "102 9\n0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1",
"output": "10"
}
] | 140 | 0 | 3 | 1,266 |
|
89 | Robbery | [
"greedy"
] | A. Robbery | 1 | 256 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to *n* from the left to the right.
Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.
Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an *n*<=-<=1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.
Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than *m* times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.
In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only *k* minutes left before morning, and on each of these *k* minutes he can perform no more than *m* operations. All that remains in Joe's pocket, is considered his loot.
Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | The first line contains integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=104, 1<=≤<=*m*,<=*k*<=≤<=109). The next line contains *n* numbers. The *i*-th number is equal to the amount of diamonds in the *i*-th cell — it is an integer from 0 to 105. | Print a single number — the maximum number of diamonds Joe can steal. | [
"2 3 1\n2 3\n",
"3 2 2\n4 1 3\n"
] | [
"0",
"2"
] | In the second sample Joe can act like this:
The diamonds' initial positions are 4 1 3.
During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.
By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.
During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.
By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.
Now Joe leaves with 2 diamonds in his pocket. | [
{
"input": "2 3 1\n2 3",
"output": "0"
},
{
"input": "3 2 2\n4 1 3",
"output": "2"
},
{
"input": "5 10 10\n7 0 7 0 7",
"output": "7"
},
{
"input": "6 10 4\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "7 5 2\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "16 100 100\n30 89 12 84 62 24 10 59 98 21 13 69 65 12 54 32",
"output": "0"
},
{
"input": "99 999 999\n9 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 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 9 9 9 9 9 9",
"output": "9"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 64 25\n100000",
"output": "1600"
},
{
"input": "1 1000000000 1\n100",
"output": "100"
},
{
"input": "1 1 1000000000\n100",
"output": "100"
},
{
"input": "1 1000000000 1000000000\n100",
"output": "100"
},
{
"input": "5 2 9494412\n5484 254 1838 18184 9421",
"output": "0"
},
{
"input": "5 10 7\n98765 78654 25669 45126 98745",
"output": "21"
},
{
"input": "13 94348844 381845400\n515 688 5464 155 441 9217 114 21254 55 9449 1800 834 384",
"output": "55"
},
{
"input": "17 100 100\n47 75 22 18 42 53 95 98 94 50 63 55 46 80 9 20 99",
"output": "9"
},
{
"input": "47 20 1000000\n81982 19631 19739 13994 50426 14232 79125 95908 20227 79428 84065 86233 30742 82664 54626 10849 11879 67198 15667 75866 47242 90766 23115 20130 37293 8312 57308 52366 49768 28256 56085 39722 40397 14166 16743 28814 40538 50753 60900 99449 94318 54247 10563 5260 76407 42235 417",
"output": "0"
},
{
"input": "58 5858758 7544547\n6977 5621 6200 6790 7495 5511 6214 6771 6526 6557 5936 7020 6925 5462 7519 6166 5974 6839 6505 7113 5674 6729 6832 6735 5363 5817 6242 7465 7252 6427 7262 5885 6327 7046 6922 5607 7238 5471 7145 5822 5465 6369 6115 5694 6561 7330 7089 7397 7409 7093 7537 7279 7613 6764 7349 7095 6967 5984",
"output": "0"
},
{
"input": "79 5464 64574\n3800 2020 2259 503 4922 975 5869 6140 3808 2635 3420 992 4683 3748 5732 4787 6564 3302 6153 4955 2958 6107 2875 3449 1755 5029 5072 5622 2139 1892 4640 1199 3918 1061 4074 5098 4939 5496 2019 356 5849 4796 4446 4633 1386 1129 3351 639 2040 3769 4106 4048 3959 931 3457 1938 4587 6438 2938 132 2434 3727 3926 2135 1665 2871 2798 6359 989 6220 97 2116 2048 251 4264 3841 4428 5286 1914",
"output": "97"
},
{
"input": "95 97575868 5\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 4220 3955 2142 4638 2832 2702 2115 2045 4085 3599 2452 5495 4767 1368 2344 4625 4132 5755 5815 2581 6259 1330 4938 815 5430 1628 3108 4342 3692 2928 1941 3714 4498 4471 4842 1822 867 3395 2587 3372 6394 6423 3728 3720 6525 4296 2091 4400 994 1321 3454 5285 2989 1755 504 5019 2629 3834 3191 6254 844 5338 615 5608 4898 2497 4482 850 5308 2763 1943 6515 5459 5556 829 4646 5258 2019 5582 1226",
"output": "815"
},
{
"input": "77 678686 878687\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",
"output": "1"
},
{
"input": "2 7597 8545\n74807 22362",
"output": "0"
},
{
"input": "3 75579860 8570575\n10433 30371 14228",
"output": "10433"
}
] | 93 | 6,758,400 | 0 | 1,274 |
441 | Valera and Fruits | [
"greedy",
"implementation"
] | null | null | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? | The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. | Print a single integer — the maximum number of fruit that Valera can collect. | [
"2 3\n1 5\n2 3\n",
"5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n"
] | [
"8\n",
"60\n"
] | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | [
{
"input": "2 3\n1 5\n2 3",
"output": "8"
},
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20",
"output": "60"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202",
"output": "10596"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426",
"output": "4740"
},
{
"input": "2 1500\n2 575\n1 2522",
"output": "3097"
},
{
"input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772",
"output": "18465"
},
{
"input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757",
"output": "25893"
},
{
"input": "1 10\n3000 30",
"output": "20"
},
{
"input": "2 1\n30 3\n31 2",
"output": "3"
},
{
"input": "4 2061\n1 426\n3 2522\n1 772\n1 1447",
"output": "5167"
},
{
"input": "2 1\n1 1\n1 1",
"output": "2"
},
{
"input": "1 10\n3000 20",
"output": "20"
},
{
"input": "1 1000\n3000 2000",
"output": "2000"
},
{
"input": "2 100\n3000 100\n3000 100",
"output": "200"
},
{
"input": "2 3\n1 6\n3 6",
"output": "12"
},
{
"input": "1 40\n3000 42",
"output": "42"
},
{
"input": "1 100\n3000 200",
"output": "200"
},
{
"input": "1 50\n3000 100",
"output": "100"
},
{
"input": "1 1\n3000 2",
"output": "2"
},
{
"input": "2 3000\n3000 3000\n3000 3000",
"output": "6000"
},
{
"input": "2 2\n2999 3\n3000 2",
"output": "5"
},
{
"input": "1 2\n3000 3",
"output": "3"
},
{
"input": "2 5\n2999 10\n3000 5",
"output": "15"
},
{
"input": "1 3\n5 3",
"output": "3"
},
{
"input": "2 1000\n2999 2000\n3000 1000",
"output": "3000"
},
{
"input": "1 5\n3000 10",
"output": "10"
},
{
"input": "1 10\n3000 15",
"output": "15"
},
{
"input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100",
"output": "10"
},
{
"input": "1 1\n3000 3000",
"output": "2"
},
{
"input": "2 10\n2999 100\n3000 100",
"output": "30"
},
{
"input": "1 10\n3000 100",
"output": "20"
}
] | 218 | 4,096,000 | 0 | 1,280 |
|
851 | Arpa and a research in Mexican wave | [
"implementation",
"math"
] | null | null | Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits.
Arpa wants to know how many spectators are standing at time *t*. | The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*). | Print single integer: how many spectators are standing at time *t*. | [
"10 5 3\n",
"10 5 7\n",
"10 5 12\n"
] | [
"3\n",
"5\n",
"3\n"
] | In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1 ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2 ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3 ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4 ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5 ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6 -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7 --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8 ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9 ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. | [
{
"input": "10 5 3",
"output": "3"
},
{
"input": "10 5 7",
"output": "5"
},
{
"input": "10 5 12",
"output": "3"
},
{
"input": "840585600 770678331 788528791",
"output": "770678331"
},
{
"input": "25462281 23343504 8024619",
"output": "8024619"
},
{
"input": "723717988 205757169 291917494",
"output": "205757169"
},
{
"input": "27462087 20831796 15492397",
"output": "15492397"
},
{
"input": "966696824 346707476 1196846860",
"output": "116557440"
},
{
"input": "290274403 41153108 327683325",
"output": "3744186"
},
{
"input": "170963478 151220598 222269210",
"output": "99914866"
},
{
"input": "14264008 309456 11132789",
"output": "309456"
},
{
"input": "886869816 281212106 52891064",
"output": "52891064"
},
{
"input": "330543750 243917820 205522400",
"output": "205522400"
},
{
"input": "457658451 18625039 157624558",
"output": "18625039"
},
{
"input": "385908940 143313325 509731380",
"output": "19490885"
},
{
"input": "241227633 220621961 10025257",
"output": "10025257"
},
{
"input": "474139818 268918981 388282504",
"output": "268918981"
},
{
"input": "25963410 3071034 820199",
"output": "820199"
},
{
"input": "656346757 647995766 75748423",
"output": "75748423"
},
{
"input": "588568132 411878522 521753621",
"output": "411878522"
},
{
"input": "735788762 355228487 139602545",
"output": "139602545"
},
{
"input": "860798593 463398487 506871376",
"output": "463398487"
},
{
"input": "362624055 110824996 194551217",
"output": "110824996"
},
{
"input": "211691721 195866131 313244576",
"output": "94313276"
},
{
"input": "45661815 26072719 9643822",
"output": "9643822"
},
{
"input": "757183104 590795077 709609355",
"output": "590795077"
},
{
"input": "418386749 1915035 197248338",
"output": "1915035"
},
{
"input": "763782282 297277890 246562421",
"output": "246562421"
},
{
"input": "893323188 617630677 607049638",
"output": "607049638"
},
{
"input": "506708261 356545583 296093684",
"output": "296093684"
},
{
"input": "984295813 427551190 84113823",
"output": "84113823"
},
{
"input": "774984967 61373612 96603505",
"output": "61373612"
},
{
"input": "774578969 342441237 91492393",
"output": "91492393"
},
{
"input": "76495801 8780305 56447339",
"output": "8780305"
},
{
"input": "48538385 582843 16805978",
"output": "582843"
},
{
"input": "325794610 238970909 553089099",
"output": "11676420"
},
{
"input": "834925315 316928679 711068031",
"output": "316928679"
},
{
"input": "932182199 454838315 267066713",
"output": "267066713"
},
{
"input": "627793782 552043394 67061810",
"output": "67061810"
},
{
"input": "24317170 17881607 218412",
"output": "218412"
},
{
"input": "1000000000 1000 1",
"output": "1"
},
{
"input": "1000000000 1000 2",
"output": "2"
},
{
"input": "1000000000 1 1000",
"output": "1"
},
{
"input": "100 100 100",
"output": "100"
},
{
"input": "100 100 99",
"output": "99"
},
{
"input": "100 100 101",
"output": "99"
},
{
"input": "100 100 199",
"output": "1"
},
{
"input": "1000000000 1000000000 1999999999",
"output": "1"
},
{
"input": "10 5 5",
"output": "5"
},
{
"input": "5 3 5",
"output": "3"
},
{
"input": "10 3 3",
"output": "3"
},
{
"input": "10 5 6",
"output": "5"
},
{
"input": "3 2 4",
"output": "1"
},
{
"input": "10 5 14",
"output": "1"
},
{
"input": "6 1 4",
"output": "1"
},
{
"input": "10 10 19",
"output": "1"
},
{
"input": "10 4 11",
"output": "3"
},
{
"input": "2 2 3",
"output": "1"
},
{
"input": "10 5 11",
"output": "4"
},
{
"input": "600 200 700",
"output": "100"
},
{
"input": "2000 1000 2001",
"output": "999"
},
{
"input": "1000 1000 1001",
"output": "999"
},
{
"input": "5 4 6",
"output": "3"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "10 3 10",
"output": "3"
},
{
"input": "15 10 10",
"output": "10"
},
{
"input": "10 5 13",
"output": "2"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "5 5 6",
"output": "4"
},
{
"input": "10 6 12",
"output": "4"
},
{
"input": "7 5 8",
"output": "4"
},
{
"input": "10 4 9",
"output": "4"
},
{
"input": "9 2 6",
"output": "2"
},
{
"input": "5 2 6",
"output": "1"
},
{
"input": "6 2 6",
"output": "2"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "3 3 5",
"output": "1"
},
{
"input": "10 2 5",
"output": "2"
},
{
"input": "5 3 7",
"output": "1"
},
{
"input": "5 4 8",
"output": "1"
},
{
"input": "10 6 11",
"output": "5"
},
{
"input": "5 3 6",
"output": "2"
},
{
"input": "10 6 14",
"output": "2"
},
{
"input": "10 10 10",
"output": "10"
},
{
"input": "1000000000 1 1000000000",
"output": "1"
},
{
"input": "20 4 22",
"output": "2"
},
{
"input": "5 4 4",
"output": "4"
},
{
"input": "4 3 6",
"output": "1"
},
{
"input": "12 8 18",
"output": "2"
},
{
"input": "10 5 10",
"output": "5"
},
{
"input": "100 50 149",
"output": "1"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "7 6 9",
"output": "4"
},
{
"input": "16 10 21",
"output": "5"
},
{
"input": "10 2 11",
"output": "1"
},
{
"input": "600 200 500",
"output": "200"
},
{
"input": "100 30 102",
"output": "28"
},
{
"input": "10 10 18",
"output": "2"
},
{
"input": "15 3 10",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "5 5 5",
"output": "5"
},
{
"input": "10 3 12",
"output": "1"
},
{
"input": "747 457 789",
"output": "415"
},
{
"input": "5 4 7",
"output": "2"
},
{
"input": "15 5 11",
"output": "5"
},
{
"input": "3 2 2",
"output": "2"
},
{
"input": "7 6 8",
"output": "5"
},
{
"input": "7 4 8",
"output": "3"
},
{
"input": "10 4 13",
"output": "1"
},
{
"input": "10 3 9",
"output": "3"
},
{
"input": "20 2 21",
"output": "1"
},
{
"input": "6 5 9",
"output": "2"
},
{
"input": "10 9 18",
"output": "1"
},
{
"input": "12 4 9",
"output": "4"
},
{
"input": "10 7 15",
"output": "2"
},
{
"input": "999999999 999999998 1500000000",
"output": "499999997"
},
{
"input": "20 5 20",
"output": "5"
},
{
"input": "4745 4574 4757",
"output": "4562"
},
{
"input": "10 7 12",
"output": "5"
},
{
"input": "17 15 18",
"output": "14"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "100 3 7",
"output": "3"
},
{
"input": "6 2 7",
"output": "1"
},
{
"input": "8 5 10",
"output": "3"
},
{
"input": "3 3 3",
"output": "3"
},
{
"input": "9 5 10",
"output": "4"
},
{
"input": "10 6 13",
"output": "3"
},
{
"input": "13 10 14",
"output": "9"
},
{
"input": "13 12 15",
"output": "10"
},
{
"input": "10 4 12",
"output": "2"
},
{
"input": "41 3 3",
"output": "3"
},
{
"input": "1000000000 1000000000 1400000000",
"output": "600000000"
},
{
"input": "10 3 11",
"output": "2"
},
{
"input": "12 7 18",
"output": "1"
},
{
"input": "15 3 17",
"output": "1"
},
{
"input": "10 2 8",
"output": "2"
},
{
"input": "1000000000 1000 1000000999",
"output": "1"
},
{
"input": "5 5 9",
"output": "1"
},
{
"input": "100 3 6",
"output": "3"
},
{
"input": "100 5 50",
"output": "5"
},
{
"input": "10000 10 10000",
"output": "10"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "4"
},
{
"input": "9979797 555554 10101010",
"output": "434341"
},
{
"input": "13 5 12",
"output": "5"
},
{
"input": "9 4 10",
"output": "3"
},
{
"input": "7 5 10",
"output": "2"
},
{
"input": "100000000 10000000 100005000",
"output": "9995000"
},
{
"input": "100000 50000 100001",
"output": "49999"
},
{
"input": "15 10 20",
"output": "5"
},
{
"input": "4 4 5",
"output": "3"
},
{
"input": "5 3 3",
"output": "3"
},
{
"input": "30 5 30",
"output": "5"
},
{
"input": "200000 10 200005",
"output": "5"
},
{
"input": "10 9 12",
"output": "7"
},
{
"input": "10 6 15",
"output": "1"
},
{
"input": "1000000000 10 1000000000",
"output": "10"
},
{
"input": "7 5 11",
"output": "1"
},
{
"input": "9 4 4",
"output": "4"
},
{
"input": "14 3 15",
"output": "2"
},
{
"input": "1000000000 100000000 1000000000",
"output": "100000000"
},
{
"input": "40 10 22",
"output": "10"
},
{
"input": "50 10 51",
"output": "9"
},
{
"input": "999999997 999999995 1999999991",
"output": "1"
},
{
"input": "92 79 144",
"output": "27"
},
{
"input": "8 4 4",
"output": "4"
}
] | 155 | 0 | 3 | 1,282 |
|
721 | One-dimensional Japanese Crossword | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 46 | 0 | 3 | 1,283 |
|
855 | Tom Riddle's Diary | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 77 | 0 | 0 | 1,289 |
|
853 | Jury Meeting | [
"greedy",
"sortings",
"two pointers"
] | null | null | Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to *n* there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires *k* days of work. For all of these *k* days each of the *n* jury members should be present in Metropolis to be able to work on problems.
You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day.
Gather everybody for *k* days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for *k* days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than *k* days. | The first line of input contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=106).
The *i*-th of the following *m* lines contains the description of the *i*-th flight defined by four integers *d**i*, *f**i*, *t**i* and *c**i* (1<=≤<=*d**i*<=≤<=106, 0<=≤<=*f**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=106, exactly one of *f**i* and *t**i* equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost. | Output the only integer that is the minimum cost of gathering all jury members in city 0 for *k* days and then sending them back to their home cities.
If it is impossible to gather everybody in Metropolis for *k* days and then send them back to their home cities, output "-1" (without the quotes). | [
"2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n",
"2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n"
] | [
"24500\n",
"-1\n"
] | The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more.
In the second sample it is impossible to send jury member from city 2 back home from Metropolis. | [
{
"input": "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500",
"output": "24500"
},
{
"input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000",
"output": "-1"
},
{
"input": "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000",
"output": "11011"
},
{
"input": "2 4 5\n1 1 0 1\n2 2 0 10\n8 0 1 100\n9 0 2 1000",
"output": "1111"
},
{
"input": "1 2 1\n10 1 0 16\n20 0 1 7",
"output": "23"
},
{
"input": "1 2 10\n20 0 1 36\n10 1 0 28",
"output": "-1"
},
{
"input": "1 2 9\n20 0 1 97\n10 1 0 47",
"output": "144"
},
{
"input": "2 4 1\n20 0 1 72\n21 0 2 94\n9 2 0 43\n10 1 0 91",
"output": "300"
},
{
"input": "2 4 10\n20 0 1 7\n9 2 0 32\n10 1 0 27\n21 0 2 19",
"output": "-1"
},
{
"input": "2 4 9\n10 1 0 22\n21 0 2 92\n9 2 0 29\n20 0 1 37",
"output": "180"
},
{
"input": "3 6 1\n10 1 0 62\n8 3 0 83\n20 0 1 28\n22 0 3 61\n21 0 2 61\n9 2 0 75",
"output": "370"
},
{
"input": "3 6 10\n22 0 3 71\n20 0 1 57\n8 3 0 42\n10 1 0 26\n9 2 0 35\n21 0 2 84",
"output": "-1"
},
{
"input": "3 6 9\n10 1 0 93\n20 0 1 26\n8 3 0 51\n22 0 3 90\n21 0 2 78\n9 2 0 65",
"output": "403"
},
{
"input": "4 8 1\n9 2 0 3\n22 0 3 100\n20 0 1 40\n10 1 0 37\n23 0 4 49\n7 4 0 53\n21 0 2 94\n8 3 0 97",
"output": "473"
},
{
"input": "4 8 10\n8 3 0 65\n21 0 2 75\n7 4 0 7\n23 0 4 38\n20 0 1 27\n10 1 0 33\n22 0 3 91\n9 2 0 27",
"output": "-1"
},
{
"input": "4 8 9\n8 3 0 61\n9 2 0 94\n23 0 4 18\n21 0 2 19\n20 0 1 52\n10 1 0 68\n22 0 3 5\n7 4 0 59",
"output": "376"
},
{
"input": "5 10 1\n24 0 5 61\n22 0 3 36\n8 3 0 7\n21 0 2 20\n6 5 0 23\n20 0 1 28\n23 0 4 18\n9 2 0 40\n7 4 0 87\n10 1 0 8",
"output": "328"
},
{
"input": "5 10 10\n24 0 5 64\n23 0 4 17\n20 0 1 91\n9 2 0 35\n21 0 2 4\n22 0 3 51\n6 5 0 69\n7 4 0 46\n8 3 0 92\n10 1 0 36",
"output": "-1"
},
{
"input": "5 10 9\n22 0 3 13\n9 2 0 30\n24 0 5 42\n21 0 2 33\n23 0 4 36\n20 0 1 57\n10 1 0 39\n8 3 0 68\n7 4 0 85\n6 5 0 35",
"output": "438"
},
{
"input": "1 10 1\n278 1 0 4\n208 1 0 4\n102 0 1 9\n499 0 1 7\n159 0 1 8\n218 1 0 6\n655 0 1 5\n532 1 0 6\n318 0 1 6\n304 1 0 7",
"output": "9"
},
{
"input": "2 10 1\n5 0 2 5\n52 2 0 9\n627 0 2 6\n75 0 1 6\n642 0 1 8\n543 0 2 7\n273 1 0 2\n737 2 0 4\n576 0 1 7\n959 0 2 5",
"output": "23"
},
{
"input": "3 10 1\n48 2 0 9\n98 0 2 5\n43 0 1 8\n267 0 1 7\n394 3 0 7\n612 0 3 9\n502 2 0 6\n36 0 2 9\n602 0 1 3\n112 1 0 6",
"output": "-1"
},
{
"input": "4 10 1\n988 0 1 1\n507 1 0 9\n798 1 0 9\n246 0 3 7\n242 1 0 8\n574 4 0 7\n458 0 4 9\n330 0 2 9\n303 2 0 8\n293 0 3 9",
"output": "-1"
},
{
"input": "5 10 1\n132 0 4 7\n803 0 2 8\n280 3 0 5\n175 4 0 6\n196 1 0 7\n801 0 4 6\n320 0 5 7\n221 0 4 6\n446 4 0 8\n699 0 5 9",
"output": "-1"
},
{
"input": "6 10 1\n845 0 4 9\n47 0 4 8\n762 0 2 8\n212 6 0 6\n416 0 5 9\n112 5 0 9\n897 0 6 9\n541 0 4 5\n799 0 6 7\n252 2 0 9",
"output": "-1"
},
{
"input": "7 10 1\n369 6 0 9\n86 7 0 9\n696 0 4 8\n953 6 0 7\n280 4 0 9\n244 0 2 9\n645 6 0 8\n598 7 0 6\n598 0 7 8\n358 0 4 6",
"output": "-1"
},
{
"input": "8 10 1\n196 2 0 9\n67 2 0 9\n372 3 0 6\n886 6 0 6\n943 0 3 8\n430 3 0 6\n548 0 4 9\n522 0 3 8\n1 4 0 3\n279 4 0 8",
"output": "-1"
},
{
"input": "9 10 1\n531 8 0 5\n392 2 0 9\n627 8 0 9\n363 5 0 9\n592 0 5 3\n483 0 6 7\n104 3 0 8\n97 8 0 9\n591 0 7 9\n897 0 6 7",
"output": "-1"
},
{
"input": "10 10 1\n351 0 3 7\n214 0 9 9\n606 0 7 8\n688 0 9 3\n188 3 0 9\n994 0 1 7\n372 5 0 8\n957 0 3 6\n458 8 0 7\n379 0 4 7",
"output": "-1"
},
{
"input": "1 2 1\n5 0 1 91\n1 1 0 87",
"output": "178"
},
{
"input": "2 4 1\n1 1 0 88\n5 2 0 88\n3 0 1 46\n9 0 2 63",
"output": "-1"
},
{
"input": "3 6 1\n19 0 3 80\n11 0 2 32\n8 2 0 31\n4 0 1 45\n1 1 0 63\n15 3 0 76",
"output": "-1"
},
{
"input": "1 0 1",
"output": "-1"
},
{
"input": "5 0 1",
"output": "-1"
}
] | 732 | 22,016,000 | 3 | 1,291 |
|
443 | Anton and Letters | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 30 | 0 | 0 | 1,293 |
|
106 | Choosing Laptop | [
"brute force",
"implementation"
] | B. Choosing Laptop | 2 | 256 | Vasya is choosing a laptop. The shop has *n* laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one.
There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. | The first line contains number *n* (1<=≤<=*n*<=≤<=100).
Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides,
- *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1<=≤<=*hdd*<=≤<=500 is the HDD in gigabytes - 100<=≤<=*cost*<=≤<=1000 is price in tugriks
All laptops have different prices. | Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data. | [
"5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n"
] | [
"4"
] | In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop. | [
{
"input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150",
"output": "4"
},
{
"input": "2\n1500 500 50 755\n1600 600 80 700",
"output": "2"
},
{
"input": "2\n1500 512 50 567\n1600 400 70 789",
"output": "1"
},
{
"input": "4\n1000 300 5 700\n1100 400 10 600\n1200 500 15 500\n1300 600 20 400",
"output": "4"
},
{
"input": "10\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310",
"output": "2"
},
{
"input": "25\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310\n3447 3875 1 306\n3950 1901 31 526\n4130 1886 152 535\n1951 1840 122 814\n1798 3722 474 106\n2305 3979 82 971\n3656 3148 349 992\n1062 1648 320 491\n3113 3706 302 542\n3545 1317 184 853\n1277 2153 95 492\n2189 3495 427 655\n4014 3030 22 963\n1455 3840 155 485\n2760 717 309 891",
"output": "15"
},
{
"input": "1\n1200 512 300 700",
"output": "1"
},
{
"input": "1\n4200 4096 500 1000",
"output": "1"
},
{
"input": "1\n1000 256 1 100",
"output": "1"
},
{
"input": "2\n2000 500 200 100\n3000 600 100 200",
"output": "1"
},
{
"input": "2\n2000 500 200 200\n3000 600 100 100",
"output": "2"
},
{
"input": "2\n2000 600 100 100\n3000 500 200 200",
"output": "1"
},
{
"input": "2\n2000 700 100 200\n3000 500 200 100",
"output": "2"
},
{
"input": "2\n3000 500 100 100\n1500 600 200 200",
"output": "1"
},
{
"input": "2\n3000 500 100 300\n1500 600 200 200",
"output": "2"
},
{
"input": "3\n3467 1566 191 888\n3047 3917 3 849\n1795 1251 97 281",
"output": "2"
},
{
"input": "4\n3835 1035 5 848\n2222 3172 190 370\n2634 2698 437 742\n1748 3112 159 546",
"output": "2"
},
{
"input": "5\n3511 981 276 808\n3317 2320 354 878\n3089 702 20 732\n1088 2913 327 756\n3837 691 173 933",
"output": "4"
},
{
"input": "6\n1185 894 287 455\n2465 3317 102 240\n2390 2353 81 615\n2884 603 170 826\n3202 2070 320 184\n3074 3776 497 466",
"output": "5"
},
{
"input": "7\n3987 1611 470 720\n1254 4048 226 626\n1747 630 25 996\n2336 2170 402 123\n1902 3952 337 663\n1416 271 77 499\n1802 1399 419 929",
"output": "4"
},
{
"input": "10\n3888 1084 420 278\n2033 277 304 447\n1774 514 61 663\n2055 3437 67 144\n1237 1590 145 599\n3648 663 244 525\n3691 2276 332 504\n1496 2655 324 313\n2462 1930 13 644\n1811 331 390 284",
"output": "4"
},
{
"input": "13\n3684 543 70 227\n3953 1650 151 681\n2452 655 102 946\n3003 990 121 411\n2896 1936 158 155\n1972 717 366 754\n3989 2237 32 521\n2738 2140 445 965\n2884 1772 251 369\n2240 741 465 209\n4073 2812 494 414\n3392 955 425 133\n4028 717 90 123",
"output": "11"
},
{
"input": "17\n3868 2323 290 182\n1253 3599 38 217\n2372 354 332 897\n1286 649 332 495\n1642 1643 301 216\n1578 792 140 299\n3329 3039 359 525\n1362 2006 172 183\n1058 3961 423 591\n3196 914 484 675\n3032 3752 217 954\n2391 2853 171 579\n4102 3170 349 516\n1218 1661 451 354\n3375 1997 196 404\n1030 918 198 893\n2546 2029 399 647",
"output": "14"
},
{
"input": "22\n1601 1091 249 107\n2918 3830 312 767\n4140 409 393 202\n3485 2409 446 291\n2787 530 272 147\n2303 3400 265 206\n2164 1088 143 667\n1575 2439 278 863\n2874 699 369 568\n4017 1625 368 641\n3446 916 53 509\n3627 3229 328 256\n1004 2525 109 670\n2369 3299 57 351\n4147 3038 73 309\n3510 3391 390 470\n3308 3139 268 736\n3733 1054 98 809\n3967 2992 408 873\n2104 3191 83 687\n2223 2910 209 563\n1406 2428 147 673",
"output": "3"
},
{
"input": "27\n1689 1927 40 270\n3833 2570 167 134\n2580 3589 390 300\n1898 2587 407 316\n1841 2772 411 187\n1296 288 407 506\n1215 263 236 307\n2737 1427 84 992\n1107 1879 284 866\n3311 2507 475 147\n2951 2214 209 375\n1352 2582 110 324\n2082 747 289 521\n2226 1617 209 108\n2253 1993 109 835\n2866 2360 29 206\n1431 3581 185 918\n3800 1167 463 943\n4136 1156 266 490\n3511 1396 478 169\n3498 1419 493 792\n2660 2165 204 172\n3509 2358 178 469\n1568 3564 276 319\n3871 2660 472 366\n3569 2829 146 761\n1365 2943 460 611",
"output": "10"
},
{
"input": "2\n1000 2000 300 120\n1000 2000 300 130",
"output": "1"
},
{
"input": "10\n2883 1110 230 501\n2662 821 163 215\n2776 1131 276 870\n2776 1131 276 596\n2776 1131 276 981\n2662 821 163 892\n2662 821 163 997\n2883 1110 230 132\n2776 1131 276 317\n2883 1110 230 481",
"output": "8"
},
{
"input": "23\n1578 3681 380 163\n2640 3990 180 576\n3278 2311 131 386\n3900 513 443 873\n1230 1143 267 313\n2640 3990 180 501\n1230 1143 267 428\n1578 3681 380 199\n1578 3681 380 490\n3900 513 443 980\n3900 513 443 882\n3278 2311 131 951\n3278 2311 131 863\n2640 3990 180 916\n3278 2311 131 406\n3278 2311 131 455\n3278 2311 131 239\n1230 1143 267 439\n3900 513 443 438\n3900 513 443 514\n3278 2311 131 526\n1578 3681 380 123\n1578 3681 380 263",
"output": "22"
},
{
"input": "6\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n1000 256 1 100",
"output": "4"
},
{
"input": "2\n1000 256 1 100\n1000 256 1 101",
"output": "1"
},
{
"input": "2\n1500 500 300 1000\n1500 500 300 900",
"output": "2"
},
{
"input": "4\n1000 256 1 500\n1000 256 1 400\n1000 256 1 300\n1000 256 1 200",
"output": "4"
},
{
"input": "3\n1500 1024 300 150\n1200 512 150 100\n1000 256 50 200",
"output": "1"
}
] | 92 | 0 | 3.977 | 1,295 |
818 | Permutation Game | [
"implementation"
] | null | null | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1. | The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step. | Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1. | [
"4 5\n2 3 1 4 4\n",
"3 3\n3 1 2\n"
] | [
"3 1 2 4 \n",
"-1\n"
] | Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4. | [
{
"input": "4 5\n2 3 1 4 4",
"output": "3 1 2 4 "
},
{
"input": "3 3\n3 1 2",
"output": "-1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 "
},
{
"input": "6 8\n2 5 4 2 5 4 2 5",
"output": "1 3 2 4 5 6 "
},
{
"input": "100 1\n6",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "10 5\n7 7 9 9 3",
"output": "-1"
},
{
"input": "10 20\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6",
"output": "-1"
},
{
"input": "20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17",
"output": "7 1 18 3 4 5 6 9 10 12 8 11 13 14 16 17 15 19 2 20 "
},
{
"input": "100 100\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63",
"output": "1 2 3 4 5 6 7 8 10 11 12 13 49 14 15 17 18 19 20 21 22 23 51 39 24 25 27 28 16 29 30 32 33 34 9 35 36 37 40 41 42 43 44 31 79 45 46 47 48 26 52 53 54 55 56 57 58 59 60 62 63 88 66 64 65 67 68 69 70 71 72 73 50 61 38 87 74 75 76 78 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 77 97 98 99 100 "
},
{
"input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "-1"
},
{
"input": "20 20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11",
"output": "19 17 15 13 11 9 7 5 3 1 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "20 5\n1 20 2 19 3",
"output": "19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2 "
},
{
"input": "19 19\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "-1"
},
{
"input": "100 100\n1 99 2 98 3 97 4 96 5 95 6 94 7 93 8 92 9 91 10 90 11 89 12 88 13 87 14 86 15 85 16 84 17 83 18 82 19 81 20 80 21 79 22 78 23 77 24 76 25 75 26 74 27 73 28 72 29 71 30 70 31 69 32 68 33 67 34 66 35 65 36 64 37 63 38 62 39 61 40 60 41 59 42 58 43 57 44 56 45 55 46 54 47 53 48 52 49 51 50 50",
"output": "98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 100 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 "
},
{
"input": "51 18\n8 32 24 19 1 29 49 24 39 33 5 37 37 26 17 28 2 19",
"output": "-1"
},
{
"input": "5 5\n1 2 5 2 4",
"output": "-1"
},
{
"input": "6 6\n1 2 1 1 3 6",
"output": "-1"
},
{
"input": "4 4\n4 3 4 2",
"output": "-1"
},
{
"input": "3 3\n2 2 3",
"output": "-1"
},
{
"input": "4 6\n1 1 2 4 4 4",
"output": "-1"
},
{
"input": "9 4\n8 2 8 3",
"output": "-1"
},
{
"input": "4 6\n2 3 1 4 4 1",
"output": "-1"
},
{
"input": "2 3\n1 1 2",
"output": "-1"
},
{
"input": "5 7\n4 3 4 3 3 4 5",
"output": "-1"
},
{
"input": "2 9\n1 1 1 1 2 1 1 1 1",
"output": "-1"
},
{
"input": "4 4\n2 4 4 4",
"output": "1 2 3 4 "
},
{
"input": "3 3\n1 1 3",
"output": "-1"
},
{
"input": "2 5\n1 2 2 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 3",
"output": "-1"
},
{
"input": "3 4\n1 3 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 1",
"output": "-1"
},
{
"input": "66 67\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5",
"output": "-1"
},
{
"input": "3 3\n3 3 2",
"output": "-1"
},
{
"input": "27 28\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23",
"output": "-1"
},
{
"input": "4 3\n1 1 2",
"output": "-1"
},
{
"input": "4 4\n2 4 2 3",
"output": "-1"
},
{
"input": "2 3\n2 2 1",
"output": "-1"
},
{
"input": "2 2\n2 2",
"output": "1 2 "
},
{
"input": "3 4\n2 3 3 1",
"output": "-1"
},
{
"input": "5 6\n1 4 4 2 1 4",
"output": "-1"
},
{
"input": "4 3\n2 3 4",
"output": "-1"
},
{
"input": "2 3\n1 2 1",
"output": "-1"
},
{
"input": "10 4\n5 6 5 7",
"output": "-1"
},
{
"input": "3 3\n1 1 2",
"output": "-1"
},
{
"input": "4 5\n1 4 1 3 2",
"output": "-1"
},
{
"input": "6 5\n1 2 4 1 3",
"output": "-1"
}
] | 46 | 4,608,000 | 0 | 1,299 |
|
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 | 1,300 |
|
837 | Flag of Berland | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=×<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"output": "NO"
},
{
"input": "1 3\nGRB",
"output": "YES"
},
{
"input": "3 1\nR\nG\nB",
"output": "YES"
},
{
"input": "4 3\nRGB\nGRB\nGRB\nGRB",
"output": "NO"
},
{
"input": "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB",
"output": "NO"
},
{
"input": "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nGRB",
"output": "NO"
},
{
"input": "3 100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRG",
"output": "NO"
},
{
"input": "3 1\nR\nR\nB",
"output": "NO"
},
{
"input": "3 2\nRR\nBB\nRR",
"output": "NO"
},
{
"input": "3 2\nRR\nBG\nBG",
"output": "NO"
},
{
"input": "3 2\nBB\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nRRR",
"output": "NO"
},
{
"input": "3 3\nGGG\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 3\nRGG",
"output": "NO"
},
{
"input": "4 3\nRGR\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "3 4\nRRGG\nRRGG\nBBBB",
"output": "NO"
},
{
"input": "3 3\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "3 1\nR\nG\nR",
"output": "NO"
},
{
"input": "5 3\nBBG\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nRRR",
"output": "NO"
},
{
"input": "1 3\nRGR",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "6 6\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "4 3\nRRR\nGGG\nBBB\nBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nBBB\nRRR",
"output": "NO"
},
{
"input": "3 1\nB\nR\nB",
"output": "NO"
},
{
"input": "1 3\nBGB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nBBBB\nRRRR",
"output": "NO"
},
{
"input": "1 6\nRGGGBB",
"output": "NO"
},
{
"input": "9 3\nBBB\nBBB\nBBB\nGGG\nGGG\nGRG\nRGR\nRRR\nRRR",
"output": "NO"
},
{
"input": "4 4\nRGBB\nRGBB\nRGBB\nRGBB",
"output": "NO"
},
{
"input": "3 3\nRBR\nRBR\nRBR",
"output": "NO"
},
{
"input": "1 6\nRRRRBB",
"output": "NO"
},
{
"input": "1 6\nRRRRRR",
"output": "NO"
},
{
"input": "1 6\nRRGGGG",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "3 1\nB\nG\nB",
"output": "NO"
},
{
"input": "3 1\nR\nR\nR",
"output": "NO"
},
{
"input": "1 9\nRRRGGGBBB",
"output": "YES"
},
{
"input": "1 3\nRRR",
"output": "NO"
},
{
"input": "3 5\nRRRRR\nBBBBB\nBBBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 1\nR",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "1 3\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nGBR\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGB\nRGB",
"output": "YES"
},
{
"input": "1 3\nBRB",
"output": "NO"
},
{
"input": "2 1\nR\nB",
"output": "NO"
},
{
"input": "1 3\nRBR",
"output": "NO"
},
{
"input": "3 5\nRRGBB\nRRGBB\nRRGBB",
"output": "NO"
},
{
"input": "5 3\nBBR\nBBR\nBBR\nBBR\nBBR",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBG\nRGB",
"output": "NO"
},
{
"input": "1 2\nRB",
"output": "NO"
},
{
"input": "4 3\nBBB\nBBB\nBBB\nBBB",
"output": "NO"
},
{
"input": "36 6\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR",
"output": "NO"
},
{
"input": "4 1\nR\nB\nG\nR",
"output": "NO"
},
{
"input": "13 12\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR",
"output": "NO"
},
{
"input": "2 2\nRR\nRR",
"output": "NO"
},
{
"input": "6 6\nRRGGBB\nGRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "NO"
},
{
"input": "70 3\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG",
"output": "NO"
},
{
"input": "4 3\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "6 3\nBBB\nGGG\nRRR\nBRG\nBRG\nBRG",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRBBBGG\nRBBBGG",
"output": "NO"
},
{
"input": "6 6\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\nGGGGGG\nGGGGGG",
"output": "NO"
},
{
"input": "6 1\nR\nB\nG\nR\nB\nG",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nBBBBB\nGGGGG\nRRRRR\nBBBBB\nGGGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nGGG\nBBB\nRRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nGGGGG",
"output": "NO"
},
{
"input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "NO"
},
{
"input": "21 10\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBGBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG",
"output": "NO"
},
{
"input": "3 2\nRR\nGB\nGB",
"output": "NO"
},
{
"input": "3 2\nRG\nRG\nBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGBR\nBRG",
"output": "NO"
},
{
"input": "1 3\nRBB",
"output": "NO"
},
{
"input": "3 3\nBGR\nBGR\nBGR",
"output": "YES"
},
{
"input": "6 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 2\nRR\nGG\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nGGG",
"output": "NO"
},
{
"input": "8 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nGGGG",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "6 1\nR\nR\nR\nR\nR\nR",
"output": "NO"
},
{
"input": "1 6\nRRBBGG",
"output": "YES"
},
{
"input": "1 6\nRGBRGB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nGGGG\nRRRR",
"output": "NO"
},
{
"input": "3 3\nRRB\nGRG\nGBB",
"output": "NO"
},
{
"input": "3 7\nRRGGBBB\nRRGGBBB\nRRGGBBB",
"output": "NO"
},
{
"input": "3 1\nG\nR\nR",
"output": "NO"
},
{
"input": "2 3\nRGG\nRBB",
"output": "NO"
},
{
"input": "3 3\nRRG\nGGG\nBBB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 1\nB\nR\nR",
"output": "NO"
},
{
"input": "1 3\nGRR",
"output": "NO"
},
{
"input": "4 4\nRRRR\nGGGG\nBBBB\nBBBB",
"output": "NO"
},
{
"input": "1 3\nGGR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nGGGGGG\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nBBBBBB\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "3 1\nG\nB\nR",
"output": "YES"
},
{
"input": "3 3\nGGB\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nGRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nGGGGGG\nBBBBBB\nRRRRRR",
"output": "NO"
},
{
"input": "3 3\nRRR\nGBG\nBBB",
"output": "NO"
},
{
"input": "3 8\nRRGGBBBB\nRRGGBBBB\nRRGGBBBB",
"output": "NO"
},
{
"input": "2 2\nRR\nGG",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGR\nRGB",
"output": "NO"
},
{
"input": "1 3\nRBG",
"output": "YES"
},
{
"input": "2 6\nRRGGBB\nGGRRBB",
"output": "NO"
},
{
"input": "6 2\nRR\nGG\nBB\nRR\nGG\nBB",
"output": "NO"
},
{
"input": "1 5\nRRGGB",
"output": "NO"
},
{
"input": "1 2\nRG",
"output": "NO"
},
{
"input": "1 6\nRGBRBG",
"output": "NO"
},
{
"input": "1 6\nRRRGGB",
"output": "NO"
},
{
"input": "1 3\nRGB",
"output": "YES"
},
{
"input": "4 3\nRRR\nBBR\nGBB\nGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nBBB\nBBB\nBBB\nGGG\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nRBG\nRBG",
"output": "YES"
},
{
"input": "6 3\nRRR\nBBB\nGGG\nRRR\nBBB\nGGG",
"output": "NO"
},
{
"input": "1 4\nRGBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nBRG\nGBR",
"output": "NO"
},
{
"input": "6 10\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB",
"output": "NO"
},
{
"input": "20 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 1\nR\nG\nB\nR",
"output": "NO"
},
{
"input": "1 4\nRGBR",
"output": "NO"
},
{
"input": "2 4\nRGBB\nRRGB",
"output": "NO"
}
] | 62 | 4,915,200 | 0 | 1,303 |
|
650 | Watchmen | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
"input": "2\n315 845\n-669 -762",
"output": "0"
},
{
"input": "3\n8911 7861\n-6888 7861\n8911 7861",
"output": "3"
},
{
"input": "2\n-1 1000000000\n0 -1",
"output": "0"
},
{
"input": "2\n1000000000 0\n-7 1",
"output": "0"
},
{
"input": "2\n1 4\n2 1",
"output": "0"
},
{
"input": "2\n1 0\n0 2333333",
"output": "0"
},
{
"input": "2\n2 1\n1 2",
"output": "0"
},
{
"input": "2\n1 1000000000\n2 -1000000000",
"output": "0"
},
{
"input": "2\n0 1000000000\n1 -7",
"output": "0"
},
{
"input": "2\n1 0\n0 19990213",
"output": "0"
}
] | 3,000 | 15,667,200 | 0 | 1,305 |
|
812 | Sagheer and Nubian Market | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<=*x**k*, then the cost of item *x**j* is *a**x**j*<=+<=*x**j*·*k* for 1<=≤<=*j*<=≤<=*k*. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor *k*.
Sagheer wants to buy as many souvenirs as possible without paying more than *S* Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task? | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"output": "3 27"
},
{
"input": "86 96\n89 48 14 55 5 35 7 79 49 70 74 18 64 63 35 93 63 97 90 77 33 11 100 75 60 99 54 38 3 6 55 1 7 64 56 90 21 76 35 16 61 78 38 78 93 21 89 1 58 53 34 77 56 37 46 59 30 5 85 1 52 87 84 99 97 9 15 66 29 60 17 16 59 23 88 93 32 2 98 89 63 42 9 86 70 80",
"output": "3 71"
},
{
"input": "9 2727\n73 41 68 90 51 7 20 48 69",
"output": "9 872"
},
{
"input": "35 792600\n61 11 82 29 3 50 65 60 62 86 83 78 15 82 7 77 38 87 100 12 93 86 96 79 14 58 60 47 94 39 36 23 69 93 18",
"output": "35 24043"
},
{
"input": "63 47677090\n53 4 59 68 6 12 47 63 28 93 9 53 61 63 53 70 77 63 49 76 70 23 4 40 4 34 24 70 42 83 84 95 11 46 38 83 26 85 34 29 67 96 3 62 97 7 42 65 49 45 50 54 81 74 83 59 10 87 95 87 89 27 3",
"output": "63 130272"
},
{
"input": "88 631662736\n93 75 25 7 6 55 92 23 22 32 4 48 61 29 91 79 16 18 18 9 66 9 57 62 3 81 48 16 21 90 93 58 30 8 31 47 44 70 34 85 52 71 58 42 99 53 43 54 96 26 6 13 38 4 13 60 1 48 32 100 52 8 27 99 66 34 98 45 19 50 37 59 31 56 58 70 61 14 100 66 74 85 64 57 92 89 7 92",
"output": "88 348883"
},
{
"input": "12 12\n1232 1848 2048 4694 5121 3735 9968 4687 2040 6033 5839 2507",
"output": "0 0"
},
{
"input": "37 5271\n368 6194 4856 8534 944 4953 2085 5350 788 7772 9786 1321 4310 4453 7078 9912 5799 4066 5471 5079 5161 9773 1300 5474 1202 1353 9499 9694 9020 6332 595 7619 1271 7430 1199 3127 8867",
"output": "5 4252"
},
{
"input": "65 958484\n9597 1867 5346 637 6115 5833 3318 6059 4430 9169 8155 7895 3534 7962 9900 9495 5694 3461 5370 1945 1724 9264 3475 618 3421 551 8359 6889 1843 6716 9216 2356 1592 6265 2945 6496 4947 2840 9057 6141 887 4823 4004 8027 1993 1391 796 7059 5500 4369 4012 4983 6495 8990 3633 5439 421 1129 6970 8796 7826 1200 8741 6555 5037",
"output": "65 468998"
},
{
"input": "90 61394040\n2480 6212 4506 829 8191 797 5336 6722 3178 1007 5849 3061 3588 6684 5983 5452 7654 5321 660 2569 2809 2179 679 4858 6887 2580 6880 6120 4159 5542 4999 8703 2386 8221 7046 1229 1662 4542 7089 3548 4298 1973 1854 2473 5507 241 359 5248 7907 5201 9624 4596 1723 2622 4800 4716 693 961 7402 9004 7994 8048 6590 5866 7502 3304 4331 5218 6906 1016 5342 6644 2205 5823 8525 4839 1914 2651 3940 7751 3489 4178 7234 6640 7602 9765 8559 7819 5827 163",
"output": "90 795634"
},
{
"input": "14 891190480\n1424 3077 9632 6506 4568 9650 5534 1085 6934 9340 2867 367 7075 618",
"output": "14 70147"
},
{
"input": "39 43\n22166 81842 15513 80979 39645 60168 96994 13493 12904 79871 49910 45356 93691 51829 18226 34288 11525 41944 40433 67295 30123 1081 55623 22279 75814 82316 2963 39329 38223 8445 43202 61912 15122 86367 37200 68113 57194 38541 49641",
"output": "0 0"
},
{
"input": "67 8824\n75515 67590 86373 34191 3446 27408 31581 24727 40005 23718 39738 30960 4786 51040 32590 80454 14335 47173 20079 41204 67289 58347 88969 88396 37681 43963 13886 85690 12259 14732 42036 62620 15011 41890 20150 59469 62104 30136 47163 19790 25699 27453 36151 52914 52684 20503 78622 81082 94500 55756 94030 54764 72763 37830 13210 64559 53600 87998 80472 19001 83769 79700 88794 10161 99980 95184 74439",
"output": "2 8268"
},
{
"input": "16 56532535\n84567 85265 99012 62115 58908 10120 27355 90226 17191 35588 43807 6327 89157 71156 16253 22387",
"output": "16 821610"
},
{
"input": "42 818723640\n57019 99450 43192 25131 80678 41786 52490 34454 51620 56132 41773 94622 23949 11597 96944 51420 44164 85727 72959 26622 1838 36302 99335 35572 92734 10651 22293 97601 38634 24066 81870 10904 5825 71968 2377 61198 3104 4191 97851 99920 65295 1385",
"output": "42 2094569"
}
] | 61 | 307,200 | 0 | 1,306 |
|
218 | Airport | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency).
The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer?
The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets.
The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane. | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7",
"output": "37 37"
},
{
"input": "40 10\n1 2 3 4 5 6 7 10 10 10",
"output": "223 158"
},
{
"input": "1 1\n6",
"output": "6 6"
},
{
"input": "1 2\n10 9",
"output": "10 9"
},
{
"input": "2 1\n7",
"output": "13 13"
},
{
"input": "2 2\n7 2",
"output": "13 3"
},
{
"input": "3 2\n4 7",
"output": "18 9"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "3 3\n2 1 1",
"output": "4 4"
},
{
"input": "10 10\n3 1 2 2 1 1 2 1 2 3",
"output": "20 13"
},
{
"input": "10 2\n7 3",
"output": "34 34"
},
{
"input": "10 1\n19",
"output": "145 145"
},
{
"input": "100 3\n29 36 35",
"output": "1731 1731"
},
{
"input": "100 5\n3 38 36 35 2",
"output": "2019 1941"
},
{
"input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62",
"output": "50279 5479"
},
{
"input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4",
"output": "1501 1501"
},
{
"input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2",
"output": "12204 8871"
}
] | 186 | 5,632,000 | 3 | 1,307 |
|
197 | Plate Game | [
"constructive algorithms",
"games",
"math"
] | null | null | You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well. | A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. | If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). | [
"5 5 2\n",
"6 7 4\n"
] | [
"First\n",
"Second\n"
] | In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.
In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. | [
{
"input": "5 5 2",
"output": "First"
},
{
"input": "6 7 4",
"output": "Second"
},
{
"input": "100 100 1",
"output": "First"
},
{
"input": "1 1 100",
"output": "Second"
},
{
"input": "13 7 3",
"output": "First"
},
{
"input": "23 7 3",
"output": "First"
},
{
"input": "9 9 2",
"output": "First"
},
{
"input": "13 13 2",
"output": "First"
},
{
"input": "21 21 10",
"output": "First"
},
{
"input": "20 21 10",
"output": "First"
},
{
"input": "20 20 10",
"output": "First"
},
{
"input": "9 13 2",
"output": "First"
},
{
"input": "19 7 3",
"output": "First"
},
{
"input": "19 19 10",
"output": "Second"
},
{
"input": "19 20 10",
"output": "Second"
},
{
"input": "19 21 10",
"output": "Second"
},
{
"input": "1 100 1",
"output": "Second"
},
{
"input": "2 100 1",
"output": "First"
},
{
"input": "3 100 1",
"output": "First"
},
{
"input": "100 100 49",
"output": "First"
},
{
"input": "100 100 50",
"output": "First"
},
{
"input": "100 100 51",
"output": "Second"
},
{
"input": "100 99 50",
"output": "Second"
},
{
"input": "4 10 5",
"output": "Second"
},
{
"input": "8 11 2",
"output": "First"
},
{
"input": "3 12 5",
"output": "Second"
},
{
"input": "14 15 5",
"output": "First"
},
{
"input": "61 2 3",
"output": "Second"
},
{
"input": "82 20 5",
"output": "First"
},
{
"input": "16 80 10",
"output": "Second"
},
{
"input": "2 1 20",
"output": "Second"
},
{
"input": "78 82 5",
"output": "First"
},
{
"input": "8 55 7",
"output": "Second"
},
{
"input": "75 55 43",
"output": "Second"
},
{
"input": "34 43 70",
"output": "Second"
},
{
"input": "86 74 36",
"output": "First"
},
{
"input": "86 74 37",
"output": "First"
},
{
"input": "86 74 38",
"output": "Second"
},
{
"input": "24 70 11",
"output": "First"
},
{
"input": "24 70 12",
"output": "First"
},
{
"input": "24 70 13",
"output": "Second"
},
{
"input": "78 95 38",
"output": "First"
},
{
"input": "78 95 39",
"output": "First"
},
{
"input": "78 95 40",
"output": "Second"
},
{
"input": "88 43 21",
"output": "First"
},
{
"input": "88 43 22",
"output": "Second"
},
{
"input": "88 43 23",
"output": "Second"
},
{
"input": "30 40 14",
"output": "First"
},
{
"input": "30 40 15",
"output": "First"
},
{
"input": "30 40 16",
"output": "Second"
},
{
"input": "2 5 2",
"output": "Second"
},
{
"input": "5 100 3",
"output": "Second"
},
{
"input": "44 58 5",
"output": "First"
},
{
"input": "4 4 6",
"output": "Second"
},
{
"input": "10 20 6",
"output": "Second"
},
{
"input": "100 1 1",
"output": "Second"
},
{
"input": "60 60 1",
"output": "First"
},
{
"input": "100 1 2",
"output": "Second"
},
{
"input": "2 4 2",
"output": "Second"
},
{
"input": "10 90 11",
"output": "Second"
},
{
"input": "20 5 6",
"output": "Second"
},
{
"input": "1 44 2",
"output": "Second"
},
{
"input": "10 5 5",
"output": "Second"
},
{
"input": "5 100 4",
"output": "Second"
},
{
"input": "99 99 50",
"output": "Second"
},
{
"input": "1 100 2",
"output": "Second"
},
{
"input": "100 20 12",
"output": "Second"
},
{
"input": "10 2 4",
"output": "Second"
},
{
"input": "1 50 2",
"output": "Second"
},
{
"input": "10 4 3",
"output": "Second"
},
{
"input": "74 1 1",
"output": "Second"
},
{
"input": "6 6 1",
"output": "First"
},
{
"input": "10 10 1",
"output": "First"
},
{
"input": "21 41 5",
"output": "First"
},
{
"input": "13 1 2",
"output": "Second"
},
{
"input": "1 100 3",
"output": "Second"
},
{
"input": "1 64 2",
"output": "Second"
},
{
"input": "3 4 1",
"output": "First"
},
{
"input": "15 15 1",
"output": "First"
},
{
"input": "15 16 1",
"output": "First"
},
{
"input": "16 15 1",
"output": "First"
},
{
"input": "16 16 1",
"output": "First"
},
{
"input": "15 15 2",
"output": "First"
},
{
"input": "15 16 2",
"output": "First"
},
{
"input": "16 15 2",
"output": "First"
},
{
"input": "16 16 2",
"output": "First"
},
{
"input": "15 15 3",
"output": "First"
},
{
"input": "15 16 3",
"output": "First"
},
{
"input": "16 15 3",
"output": "First"
},
{
"input": "16 16 3",
"output": "First"
},
{
"input": "15 17 3",
"output": "First"
},
{
"input": "16 17 3",
"output": "First"
},
{
"input": "17 17 3",
"output": "First"
},
{
"input": "17 15 3",
"output": "First"
},
{
"input": "17 16 3",
"output": "First"
}
] | 436 | 9,523,200 | 0 | 1,310 |
|
620 | Grandfather Dovlet’s calculator | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.
For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12. | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "28733372"
},
{
"input": "1000000 1000000",
"output": "38"
},
{
"input": "222145 353252",
"output": "3860750"
},
{
"input": "2 1000000",
"output": "28733370"
},
{
"input": "1 999999",
"output": "28733334"
},
{
"input": "192 200",
"output": "122"
}
] | 280 | 21,606,400 | 3 | 1,313 |
|
1,003 | Polycarp's Pockets | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71",
"output": "51"
},
{
"input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29",
"output": "1"
},
{
"input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24",
"output": "2"
},
{
"input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6",
"output": "10"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "7\n1 2 3 3 3 1 2",
"output": "3"
},
{
"input": "5\n1 2 3 4 5",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 1 1",
"output": "3"
},
{
"input": "12\n1 2 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "13"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "14"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "16"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "10\n1 1 1 1 2 2 1 1 9 10",
"output": "6"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "56"
},
{
"input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92",
"output": "6"
},
{
"input": "10\n1 2 2 3 3 3 4 4 4 4",
"output": "4"
},
{
"input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21",
"output": "3"
},
{
"input": "5\n5 5 5 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 5 2 6",
"output": "3"
},
{
"input": "3\n58 59 58",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 8",
"output": "2"
},
{
"input": "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "97"
},
{
"input": "3\n95 95 4",
"output": "2"
},
{
"input": "3\n2 2 5",
"output": "2"
}
] | 62 | 0 | 3 | 1,316 |
|
839 | Arya and Bran | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*).
Print -1 if she can't give him *k* candies during *n* given days. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",
"output": "18"
},
{
"input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5",
"output": "30"
},
{
"input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47",
"output": "40"
},
{
"input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9",
"output": "-1"
},
{
"input": "37 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "30"
},
{
"input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "57"
},
{
"input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100",
"output": "38"
},
{
"input": "7 43\n4 3 7 9 3 8 10",
"output": "-1"
},
{
"input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8",
"output": "-1"
},
{
"input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8",
"output": "-1"
},
{
"input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5",
"output": "-1"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69",
"output": "13"
},
{
"input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53",
"output": "85"
},
{
"input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5",
"output": "100"
},
{
"input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6",
"output": "98"
},
{
"input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1",
"output": "18"
},
{
"input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2",
"output": "21"
},
{
"input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1",
"output": "-1"
},
{
"input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91",
"output": "45"
},
{
"input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90",
"output": "-1"
},
{
"input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50",
"output": "97"
},
{
"input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9",
"output": "24"
},
{
"input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42",
"output": "21"
},
{
"input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100",
"output": "1"
},
{
"input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5",
"output": "13"
},
{
"input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92",
"output": "14"
},
{
"input": "2 16\n10 6",
"output": "2"
},
{
"input": "2 8\n7 8",
"output": "2"
},
{
"input": "2 9\n4 8",
"output": "2"
},
{
"input": "3 19\n9 9 1",
"output": "3"
},
{
"input": "4 32\n9 9 9 5",
"output": "4"
},
{
"input": "2 15\n14 1",
"output": "2"
},
{
"input": "2 3\n3 3",
"output": "1"
},
{
"input": "3 10\n10 1 1",
"output": "2"
},
{
"input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4",
"output": "4"
},
{
"input": "4 15\n14 3 3 3",
"output": "2"
},
{
"input": "5 40\n10 10 10 10 1",
"output": "5"
},
{
"input": "4 31\n9 9 8 5",
"output": "4"
},
{
"input": "4 31\n20 7 1 1",
"output": "-1"
},
{
"input": "2 10\n9 1",
"output": "2"
},
{
"input": "10 50\n100 10 1 1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2 11\n10 2",
"output": "2"
},
{
"input": "3 21\n10 10 1",
"output": "3"
},
{
"input": "2 2\n1 2",
"output": "2"
},
{
"input": "3 2\n1 8 8",
"output": "2"
},
{
"input": "2 11\n10 1",
"output": "2"
},
{
"input": "2 16\n12 4",
"output": "2"
},
{
"input": "3 11\n9 2 2",
"output": "2"
},
{
"input": "3 11\n4 3 4",
"output": "3"
},
{
"input": "2 13\n7 6",
"output": "2"
},
{
"input": "3 24\n14 3 4",
"output": "-1"
},
{
"input": "2 13\n10 3",
"output": "2"
},
{
"input": "3 11\n9 2 1",
"output": "2"
},
{
"input": "2 15\n12 3",
"output": "2"
},
{
"input": "2 14\n11 4",
"output": "2"
}
] | 155 | 20,172,800 | 3 | 1,318 |
|
75 | Facetook Priority Wall | [
"expression parsing",
"implementation",
"strings"
] | B. Facetook Priority Wall | 2 | 256 | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall" (15 points), - 2. "*X* commented on *Y*'s post" (10 points), - 3. "*X* likes *Y*'s post" (5 points).
*X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*).
You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you. | The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters. | Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.
Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.
The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1<=≤<=*i*<=≤<=*min*(|*a*|,<=|*b*|)), that *a**i*<=<<=*b**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *a**j*<==<=*b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently. | [
"ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n",
"aba\n1\nlikes likes posted's post\n"
] | [
"fatma\nmona\n",
"likes\nposted\n"
] | none | [
{
"input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post",
"output": "fatma\nmona"
},
{
"input": "aba\n1\nlikes likes posted's post",
"output": "likes\nposted"
},
{
"input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\ng likes nu's post\ng posted on nu's wall\nqv commented on pwyndmh's post",
"output": "g\npwyndmh\nqv"
},
{
"input": "szfwtzfp\n5\nzqx posted on szfwtzfp's wall\nr commented on scguem's post\nr posted on civ's wall\nr likes scguem's post\nr likes scguem's post",
"output": "zqx\nciv\nr\nscguem"
},
{
"input": "oaquudhavr\n3\ni posted on cwfwujpc's wall\ni likes oaquudhavr's post\noaquudhavr commented on cwfwujpc's post",
"output": "cwfwujpc\ni"
},
{
"input": "eo\n4\neo commented on xkgjgwxtrx's post\neo posted on iqquh's wall\nn commented on xkgjgwxtrx's post\niqquh commented on n's post",
"output": "iqquh\nxkgjgwxtrx\nn"
},
{
"input": "plwun\n3\neusjuq commented on plwun's post\nagktgdar likes eusjuq's post\nagppcoil likes agktgdar's post",
"output": "eusjuq\nagktgdar\nagppcoil"
},
{
"input": "fgzrn\n3\nzhl likes fgzrn's post\nxryet likes fgzrn's post\nzhl commented on fgzrn's post",
"output": "zhl\nxryet"
},
{
"input": "qatugmdjwg\n3\nb posted on cf's wall\nyjxkat posted on b's wall\nko commented on qatugmdjwg's post",
"output": "ko\nb\ncf\nyjxkat"
},
{
"input": "dagwdwxsuf\n5\nesrvncb commented on dagwdwxsuf's post\nzcepigpbz posted on dagwdwxsuf's wall\nesrvncb commented on zcepigpbz's post\nesrvncb commented on dagwdwxsuf's post\ndagwdwxsuf commented on esrvncb's post",
"output": "esrvncb\nzcepigpbz"
},
{
"input": "a\n1\nb likes c's post",
"output": "b\nc"
},
{
"input": "a\n1\nc likes b's post",
"output": "b\nc"
},
{
"input": "wuaiz\n10\nmnbggnud posted on xttaqvel's wall\ns posted on xopffmspf's wall\nkysxb likes qnrtpzkh's post\ngptks likes quebtsup's post\nkgmd commented on kmtnhsiue's post\newqjtxtiyn commented on a's post\nol posted on iglplaj's wall\nif posted on yuo's wall\nfs posted on dwjtuhgrq's wall\nygmdprun likes tzfneuly's post",
"output": "a\ndwjtuhgrq\newqjtxtiyn\nfs\ngptks\nif\niglplaj\nkgmd\nkmtnhsiue\nkysxb\nmnbggnud\nol\nqnrtpzkh\nquebtsup\ns\ntzfneuly\nxopffmspf\nxttaqvel\nygmdprun\nyuo"
},
{
"input": "fzhzg\n11\nv likes xyf's post\nktqtpzhlh commented on ffsxarrn's post\nktqtpzhlh commented on lbt's post\njcdwpcycj commented on qbuigcgflm's post\nl likes pmg's post\nracszbmsk posted on ojr's wall\nojr commented on n's post\nnzqx commented on lkj's post\nv posted on lzoca's wall\nnwqnoham commented on gyivezpu's post\nfzhzg likes uqvzgzrpac's post",
"output": "uqvzgzrpac\nffsxarrn\ngyivezpu\njcdwpcycj\nktqtpzhlh\nl\nlbt\nlkj\nlzoca\nn\nnwqnoham\nnzqx\nojr\npmg\nqbuigcgflm\nracszbmsk\nv\nxyf"
},
{
"input": "qdrnpb\n12\nymklhj commented on dkcbo's post\nhcucrenckl posted on mut's wall\nnvkyta commented on eo's post\npvgow likes mut's post\nob likes wlwcxtf's post\npvgow commented on advpu's post\nkfflyfbr commented on igozjnrxw's post\nsq commented on qdrnpb's post\nmrvn posted on lahduc's wall\ngsnlicy likes u's post\ndltqujf commented on qgzk's post\nr posted on bey's wall",
"output": "sq\nadvpu\nbey\ndkcbo\ndltqujf\neo\ngsnlicy\nhcucrenckl\nigozjnrxw\nkfflyfbr\nlahduc\nmrvn\nmut\nnvkyta\nob\npvgow\nqgzk\nr\nu\nwlwcxtf\nymklhj"
},
{
"input": "biycvwb\n13\nhp likes cigobksf's post\nmcoqt commented on gaswzwat's post\nnz posted on xyvetbokl's wall\nqbnwy commented on ylkfbwjy's post\nqdwktrro likes rxgujnzecs's post\nbbsw commented on hwtatkfnps's post\ngspx posted on ugjxfnahuc's wall\nxlmut likes plle's post\numbwlleag commented on xfwlhen's post\nrlwxqksbwi commented on rypqtrgf's post\nbj posted on vovq's wall\nozpdpb commented on zti's post\nhqj posted on rxgujnzecs's wall",
"output": "bbsw\nbj\ncigobksf\ngaswzwat\ngspx\nhp\nhqj\nhwtatkfnps\nmcoqt\nnz\nozpdpb\nplle\nqbnwy\nqdwktrro\nrlwxqksbwi\nrxgujnzecs\nrypqtrgf\nugjxfnahuc\numbwlleag\nvovq\nxfwlhen\nxlmut\nxyvetbokl\nylkfbwjy\nzti"
},
{
"input": "kmircqsffq\n14\nfrnf likes xgmmp's post\nfnfdpupayp commented on syz's post\nxefshpn commented on xgmmp's post\nm posted on gdwydzktok's wall\neskm likes pqmbnuc's post\npnqiapduhz likes zzqvjdz's post\nx likes nouuurc's post\nvnyxhoukuo posted on uhblapjab's wall\nblpjpxn likes zvwbger's post\nj posted on vuknetvl's wall\nscsw commented on xaggwxlxe's post\npqmbnuc commented on ojwaibie's post\niaazdlqdew commented on kmircqsffq's post\nqznqshxdi commented on umdqztoqun's post",
"output": "iaazdlqdew\nblpjpxn\neskm\nfnfdpupayp\nfrnf\ngdwydzktok\nj\nm\nnouuurc\nojwaibie\npnqiapduhz\npqmbnuc\nqznqshxdi\nscsw\nsyz\nuhblapjab\numdqztoqun\nvnyxhoukuo\nvuknetvl\nx\nxaggwxlxe\nxefshpn\nxgmmp\nzvwbger\nzzqvjdz"
},
{
"input": "posted\n3\nposted posted on fatma's wall\nfatma commented on posted's post\nmona likes posted's post",
"output": "fatma\nmona"
},
{
"input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\nmona likes posted's post",
"output": "wall\nmona"
},
{
"input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\npost likes posted's post",
"output": "wall\npost"
},
{
"input": "wall\n5\nwall posted on posted's wall\nwall posted on on's wall\nwall posted on commented's wall\nwall posted on likes's wall\nwall posted on post's wall",
"output": "commented\nlikes\non\npost\nposted"
},
{
"input": "commented\n5\non commented on commented's post\npos commented on commented's post\nlikes commented on commented's post\nposted commented on commented's post\nwall commented on commented's post",
"output": "likes\non\npos\nposted\nwall"
},
{
"input": "likes\n3\nlikes posted on post's wall\nlikes commented on on's post\nlikes likes commented's post",
"output": "post\non\ncommented"
},
{
"input": "on\n4\non posted on posted's wall\non commented on commented's post\non posted on wall's wall\non commented on post's post",
"output": "posted\nwall\ncommented\npost"
},
{
"input": "wall\n9\nwall posted on posted's wall\non commented on wall's post\nwall likes post's post\nposted posted on wall's wall\nwall commented on post's post\nlikes likes wall's post\nwall posted on on's wall\npost commented on wall's post\nwall likes likes's post",
"output": "posted\non\npost\nlikes"
},
{
"input": "post\n9\npost posted on wall's wall\non commented on post's post\npost likes likes's post\ncommented posted on post's wall\npost commented on likes's post\nlikes likes post's post\npost posted on posted's wall\non commented on post's post\npost likes commented's post",
"output": "commented\nlikes\non\nposted\nwall"
},
{
"input": "ahmed\n9\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post\nahmeds posted on post's wall\npost commented on ahmeds's post\nahmeds likes post's post\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post",
"output": "ahmeds\npost"
}
] | 154 | 0 | 0 | 1,322 |
520 | Two Buttons | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*.
Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result? | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"output": "5"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "99 100",
"output": "50"
},
{
"input": "10 17",
"output": "3"
},
{
"input": "666 6666",
"output": "255"
},
{
"input": "6666 666",
"output": "6000"
},
{
"input": "1 8192",
"output": "13"
},
{
"input": "1 8193",
"output": "27"
},
{
"input": "9999 10000",
"output": "5000"
},
{
"input": "10000 9999",
"output": "1"
},
{
"input": "10000 1",
"output": "9999"
},
{
"input": "1234 5678",
"output": "528"
},
{
"input": "9102 9103",
"output": "4552"
},
{
"input": "8192 1",
"output": "8191"
},
{
"input": "9912 1023",
"output": "8889"
},
{
"input": "100 500",
"output": "41"
},
{
"input": "9997 9999",
"output": "4999"
},
{
"input": "5000 10000",
"output": "1"
},
{
"input": "4000 7997",
"output": "3"
},
{
"input": "1 10000",
"output": "20"
},
{
"input": "1 8191",
"output": "14"
},
{
"input": "9999 10000",
"output": "5000"
},
{
"input": "9097 9998",
"output": "4099"
},
{
"input": "886 9383",
"output": "305"
},
{
"input": "1 9",
"output": "7"
},
{
"input": "1918 10000",
"output": "671"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 10000",
"output": "19"
},
{
"input": "3 10000",
"output": "17"
},
{
"input": "4 10000",
"output": "18"
},
{
"input": "9998 10000",
"output": "4999"
},
{
"input": "5000 10000",
"output": "1"
},
{
"input": "5001 10000",
"output": "2"
},
{
"input": "10000 1",
"output": "9999"
},
{
"input": "1 9999",
"output": "21"
},
{
"input": "7777 9999",
"output": "2779"
},
{
"input": "2 100",
"output": "9"
},
{
"input": "10 8722",
"output": "18"
},
{
"input": "848 4561",
"output": "283"
},
{
"input": "9967 9973",
"output": "4982"
},
{
"input": "5555 10000",
"output": "556"
},
{
"input": "999 10000",
"output": "378"
},
{
"input": "3 6",
"output": "1"
},
{
"input": "9 38",
"output": "8"
}
] | 0 | 0 | -1 | 1,323 |
|
342 | Xenia and Divisors | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divides *c*.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three.
Help Xenia, find the required partition or else say that it doesn't exist. | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 3 6 6 3 1 3 1 6",
"output": "1 3 6\n1 3 6\n1 3 6"
},
{
"input": "6\n1 2 4 1 3 5",
"output": "-1"
},
{
"input": "3\n1 3 7",
"output": "-1"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "9\n1 2 4 1 2 4 1 3 6",
"output": "1 2 4\n1 2 4\n1 3 6"
},
{
"input": "12\n3 6 1 1 3 6 1 1 2 6 2 6",
"output": "1 3 6\n1 3 6\n1 2 6\n1 2 6"
},
{
"input": "9\n1 1 1 4 4 4 6 2 2",
"output": "-1"
},
{
"input": "9\n1 2 4 6 3 1 3 1 5",
"output": "-1"
},
{
"input": "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4",
"output": "1 2 4\n1 2 4\n1 3 6\n1 3 6\n1 2 6"
},
{
"input": "3\n2 3 6",
"output": "-1"
},
{
"input": "3\n2 4 6",
"output": "-1"
},
{
"input": "3\n2 5 6",
"output": "-1"
},
{
"input": "3\n2 4 7",
"output": "-1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "-1"
},
{
"input": "3\n7 7 7",
"output": "-1"
},
{
"input": "6\n1 2 4 7 7 7",
"output": "-1"
},
{
"input": "6\n1 1 2 6 6 6",
"output": "-1"
},
{
"input": "9\n1 1 1 3 3 2 4 4 6",
"output": "-1"
},
{
"input": "6\n1 2 4 5 5 5",
"output": "-1"
},
{
"input": "15\n1 1 1 1 1 2 2 2 2 4 4 6 6 6 6",
"output": "-1"
},
{
"input": "6\n1 1 5 5 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 5 6 7",
"output": "-1"
},
{
"input": "6\n1 1 4 4 7 7",
"output": "-1"
},
{
"input": "24\n1 1 1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 6 6 6",
"output": "-1"
},
{
"input": "3\n1 7 6",
"output": "-1"
},
{
"input": "6\n1 1 2 4 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 7 7 7 7 7 7",
"output": "-1"
},
{
"input": "9\n1 1 1 2 3 4 6 5 5",
"output": "-1"
}
] | 46 | 0 | 0 | 1,324 |
|
796 | Buying A House | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"output": "20"
},
{
"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20",
"output": "10"
},
{
"input": "7 5 1\n0 100 2 2 0 2 1",
"output": "20"
},
{
"input": "100 50 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 0 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": "10"
},
{
"input": "100 50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 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": "490"
},
{
"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0",
"output": "10"
},
{
"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "980"
},
{
"input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "10"
},
{
"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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 98",
"output": "890"
},
{
"input": "7 4 5\n1 0 6 0 5 6 0",
"output": "10"
},
{
"input": "7 4 5\n1 6 5 0 0 6 0",
"output": "10"
},
{
"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0",
"output": "90"
},
{
"input": "2 1 100\n0 1",
"output": "10"
},
{
"input": "2 2 100\n1 0",
"output": "10"
},
{
"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85",
"output": "90"
},
{
"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32",
"output": "10"
},
{
"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35",
"output": "60"
},
{
"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88",
"output": "10"
},
{
"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82",
"output": "70"
},
{
"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1",
"output": "180"
},
{
"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0",
"output": "210"
},
{
"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37",
"output": "80"
},
{
"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77",
"output": "190"
},
{
"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84",
"output": "190"
},
{
"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15",
"output": "580"
},
{
"input": "97 44 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 51 19",
"output": "520"
},
{
"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67",
"output": "490"
},
{
"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23",
"output": "890"
},
{
"input": "100 1 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 91 70 14",
"output": "970"
},
{
"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10",
"output": "990"
},
{
"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10",
"output": "490"
},
{
"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2",
"output": "500"
},
{
"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20",
"output": "50"
},
{
"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0",
"output": "990"
},
{
"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0",
"output": "10"
},
{
"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51",
"output": "140"
},
{
"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4",
"output": "390"
},
{
"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68",
"output": "130"
},
{
"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59",
"output": "10"
},
{
"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32",
"output": "10"
},
{
"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98",
"output": "160"
},
{
"input": "5 2 20\n27 0 32 21 19",
"output": "30"
},
{
"input": "6 4 10\n10 0 0 0 0 10",
"output": "20"
},
{
"input": "8 7 100\n1 0 0 0 0 0 0 1",
"output": "10"
},
{
"input": "5 3 20\n1 21 0 0 1",
"output": "20"
},
{
"input": "4 3 1\n0 0 0 1",
"output": "10"
},
{
"input": "5 2 3\n4 0 5 6 1",
"output": "30"
},
{
"input": "5 3 87\n88 89 0 1 90",
"output": "10"
},
{
"input": "5 3 20\n15 30 0 15 35",
"output": "10"
},
{
"input": "6 3 50\n0 0 0 1 2 0",
"output": "10"
},
{
"input": "6 4 9\n100 9 10 0 0 9",
"output": "20"
},
{
"input": "5 4 20\n0 20 0 0 20",
"output": "10"
},
{
"input": "6 3 3\n1 5 0 2 2 0",
"output": "10"
},
{
"input": "5 4 100\n0 1 0 0 1",
"output": "10"
}
] | 62 | 512,000 | 3 | 1,328 |
|
8 | Train and Peter | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 186 | 102,400 | 0 | 1,332 |
298 | Snow Footprints | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road.
You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 92 | 0 | -1 | 1,333 |
|
914 | Travelling Salesman and Special Numbers | [
"brute force",
"combinatorics",
"dp"
] | null | null | The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer *x* and reduce it to the number of bits set to 1 in the binary representation of *x*. For example for number 13 it's true that 1310<==<=11012, so it has 3 bits set and 13 will be reduced to 3 in one operation.
He calls a number special if the minimum number of operations to reduce it to 1 is *k*.
He wants to find out how many special numbers exist which are not greater than *n*. Please help the Travelling Salesman, as he is about to reach his destination!
Since the answer can be large, output it modulo 109<=+<=7. | The first line contains integer *n* (1<=≤<=*n*<=<<=21000).
The second line contains integer *k* (0<=≤<=*k*<=≤<=1000).
Note that *n* is given in its binary representation without any leading zeros. | Output a single integer — the number of special numbers not greater than *n*, modulo 109<=+<=7. | [
"110\n2\n",
"111111011\n2\n"
] | [
"3\n",
"169\n"
] | In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2). | [
{
"input": "110\n2",
"output": "3"
},
{
"input": "111111011\n2",
"output": "169"
},
{
"input": "100011110011110110100\n7",
"output": "0"
},
{
"input": "110100110\n0",
"output": "1"
},
{
"input": "10000000000000000000000000000000000000000000\n2",
"output": "79284496"
},
{
"input": "100000000000000000000100000000000010100100001001000010011101010\n3",
"output": "35190061"
},
{
"input": "101010110000\n3",
"output": "1563"
},
{
"input": "11010110000\n3",
"output": "1001"
},
{
"input": "100\n6",
"output": "0"
},
{
"input": "100100100100\n5",
"output": "0"
},
{
"input": "10000000000\n4",
"output": "120"
},
{
"input": "10\n868",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n0",
"output": "1"
},
{
"input": "101110011101100100010010101001010111001\n8",
"output": "0"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10",
"output": "0"
},
{
"input": "10000000000000000000000000000\n1",
"output": "28"
},
{
"input": "111111111111111111111111111111111111\n2",
"output": "338250841"
},
{
"input": "10010110001111110001100000110111010011010110100111100010001011000011000011000100011010000000000110110010111111\n2",
"output": "678359035"
},
{
"input": "11111100010011110101100110100010001011100111001011001111101111110111001111011011110101100101001000111001000100000011011110110010001000111101001101001010100011\n1",
"output": "157"
},
{
"input": "10011101000010110111001\n1",
"output": "22"
},
{
"input": "10000110011100011111100010011010111110111110100011110101110010000001111100110000001000101011001000111110111100110111010011011100000000111101001010110\n1",
"output": "148"
},
{
"input": "11101011101101101111101100001101110010011011101101010101101111100011101111010111011\n1",
"output": "82"
},
{
"input": "11101111100100100110010100010100101111\n4",
"output": "839492816"
},
{
"input": "111111000110010101000000101001111000101100000110100101111000001011001011110111000000000010\n0",
"output": "1"
},
{
"input": "10000001011010001011101011100010110001010110111100110001010011111111010110101100100010101111\n1",
"output": "91"
},
{
"input": "100111000100101100\n4",
"output": "42232"
},
{
"input": "11001101101010100\n3",
"output": "55119"
},
{
"input": "10000010100111000111001111011001\n1",
"output": "31"
},
{
"input": "110001010001001\n0",
"output": "1"
},
{
"input": "10000010111110110111000001011111111010111101000101001000100111101011001101001111111011110111101100001101100011011111010010001001010100011000111100110101100001100001011111000111001010010010110000111110011111010111001001000111010111111100101101010111100010010111001001111010100110011001111111100000101000100011001011100011000101010100000001100110011011001110101100000111001111011\n732",
"output": "0"
},
{
"input": "111001100100110011100111101100010000111100111\n37",
"output": "0"
},
{
"input": "110101100110100001001011010001011001100100000111000000111100000001010000010001111101000101110001001000110001110001100100100000110101000110111000011010101010011011011000110101110010010111110101101110000010000101101010100101010011010001010010101110001010000001010001111000110100101010001011001110110010\n481",
"output": "0"
},
{
"input": "101011000000101110010001011010000110010100001011101110110000000001001000101011100100110111100110100010010001010111001010110011001011110111100100110000000001000100101101101101010101011100101001010000001111110011101000111111110001000101110000000011111101001100101101100111000000101111011110110001110001001110010001011010000001100001010010000100011001111100000100010000000101011100001010011100110001100111111011011100101101011110110000101000001110010001111100110101010\n129",
"output": "0"
},
{
"input": "1010010001000110110001010110101110100110101100011111101000001001001000001100000000011\n296",
"output": "0"
},
{
"input": "1100001110101110010111011111000111011011100011001000010111000010010011000111111011000100110010100111000000001110101001000110010000111000001001000111011010001001000010001111000111101001100101110000001111110001110111011101011000011010010101001111101101100011101010010110\n6",
"output": "0"
},
{
"input": "101010111001011101010100110100001111010111011000101000100100100111101101101000001110111110011100001110010010010000110101011101011111111011110000001011011101101111001011000111001100000110100100110\n7",
"output": "0"
},
{
"input": "11100001100000001101001111111101000000111010000001001000111101000100100111101100100011100111101100010110000010100100101001101001101001111101101000101010111111110001011000010011011011101010110110011010111011111000100001010110000010000101011001110011011001010001000010000110010110101100010101001111101101111100010010011000000100001000111010011011101000100111001110000000001110000010110000100010110100110011010110000100111110001100001011101\n3",
"output": "591387665"
},
{
"input": "10001011100010111001100001010011011011001100111000000010110010000000010000000011011110011110111110110011000000011110010011110001110110100010111010100111111000000100011011111011111111010000000001110000100100010100111001001000011010010010010001011110010101001001000101110011110000110010011110111011000010110110110101110011100011111001111001111110001011111110111111111010100111101101011000101000100001101001101010101111011001100000110011000\n1",
"output": "436"
},
{
"input": "10101010100111001111011010\n1",
"output": "25"
},
{
"input": "1110100100000010010000001111\n7",
"output": "0"
},
{
"input": "10011000111011110111100110111100011000100111110\n7",
"output": "0"
},
{
"input": "110110000010000001110101000000110010101110000011110101001111000111001111100110001001100011011\n5",
"output": "0"
},
{
"input": "11000011000010000011010011001000100010\n5",
"output": "0"
},
{
"input": "1011100011101000001101111111101111011101000110110001111001010111110111101110101011111110\n7",
"output": "0"
},
{
"input": "100110100010110011010110011101110001010000110011001100011000101000010110111000\n3",
"output": "637252489"
},
{
"input": "11110110000010111011111100010000001010001110110000101001\n6",
"output": "0"
},
{
"input": "100000001100101011100111100101001101110\n3",
"output": "186506375"
},
{
"input": "10011001111000101010111100111010110110000100101001011101011100000010011111100011101\n1",
"output": "82"
},
{
"input": "1111101000100110001010001001\n3",
"output": "122853842"
},
{
"input": "11010101010101001100101110100001001100111001111100100000001100100010010001010001001100001000111010010101101001100101100000000101001011010011000010100011101010111111100010101011111001110000010000111001101101001100010011101000110101110110001101\n4",
"output": "571603984"
},
{
"input": "100001111010010111101010000100000010011000001100101001000110010010001101001101101001001110000101101010011000011101000101111011001101001111011111000000001100100100011011111010000010011111010011001011111010100100001011010011011001010111011111110111100001001101001001101110101101111000110011011100001011011111001110001000110001100110101100001010000001001100000001101010111110001010011101001111010111\n3",
"output": "329948438"
},
{
"input": "1111110000010010100110001010001000111100001101110100100011101110000011001100010\n3",
"output": "774501673"
},
{
"input": "101100101001110000011101\n3",
"output": "5671856"
},
{
"input": "1011\n3",
"output": "2"
},
{
"input": "100010100\n3",
"output": "150"
},
{
"input": "110110010000000011010010100011111001111101110011100100100110001111100001\n3",
"output": "134209222"
},
{
"input": "11101000011\n3",
"output": "1074"
},
{
"input": "1000000101100011101000101010110111101010111100110\n4",
"output": "325122368"
},
{
"input": "1101\n3",
"output": "3"
},
{
"input": "101100100\n2",
"output": "139"
},
{
"input": "11011011111000010101010100000100110101\n4",
"output": "363038940"
},
{
"input": "10010110100010001010000000110100001000010000\n4",
"output": "399815120"
},
{
"input": "101101000001111101010001110\n4",
"output": "41258563"
},
{
"input": "1100000110100011100011110000010001110111\n4",
"output": "615102266"
},
{
"input": "10011100101110000100000011001000\n4",
"output": "937000434"
},
{
"input": "1110111100101001000100\n4",
"output": "1562803"
},
{
"input": "101110100101001000\n2",
"output": "38552"
},
{
"input": "11110110001110101001101110011011010010010101011000\n3",
"output": "895709102"
},
{
"input": "111001001001101111000\n4",
"output": "680132"
},
{
"input": "111101001101101110110010100010000101011100111\n4",
"output": "632815766"
},
{
"input": "1010100110101101101100001001101001100\n3",
"output": "555759044"
},
{
"input": "1011010011010010111111000011111100001001101010100011011110101\n3",
"output": "760546372"
},
{
"input": "101110010111100010011010001001001111001\n3",
"output": "557969925"
},
{
"input": "11010011111101111111010011011101101111010001001001100000111\n3",
"output": "389792479"
},
{
"input": "1011110111001010110001100011010000011111000100000000011000000101010101010000\n4",
"output": "184972385"
},
{
"input": "1111101000110001110011101001001101000000001000010001110000100111100110100101001100110111010010110000100100011001000110110000010010000101000010101011110101001000101000001101000101011100000101011100101011011001110011111000001011111111011100110010100111010010101000010010001001010101010101001110001001011111101111001101011111110010011001011110001100100011101010110010001110101111110010011111111111\n4",
"output": "678711158"
},
{
"input": "10111010100111101011010100001101000111000001111101000101101001100101011000100110100010100101001011110101111001111011000011010000010100110000100110110011001110001001001010110001011111000100010010010111100010110001011010101101010000101110011011100001100101011110110101100010111011111001011110110111110100101100111001000101100111001100001\n3",
"output": "187155647"
},
{
"input": "10100001110001001101000111010111011011101010111100000101001101001010000100000011110110111\n4",
"output": "108160984"
},
{
"input": "1110011001101101000011001110011111100011101100100000010100111010111001110011100111011111100100111001010101000001001010010010110010100100000011111000000001111010110011000010000100101011000101110100100001101111011110011001000111111010100001010001111100000100100101000001011111011110010111010100111001101000001000111000110100000000010101110000011010010011001000111001111101\n3",
"output": "652221861"
},
{
"input": "100110011001000111111110001010011001110100111010010101100110000110011010111010011110101110011101111000001101010111010101111110100100111010010010101000111011111000010101\n3",
"output": "72690238"
},
{
"input": "111000000101110011000110000\n3",
"output": "54271713"
},
{
"input": "1001000100000\n2",
"output": "1196"
},
{
"input": "10110100000101000110011000010\n3",
"output": "177315776"
},
{
"input": "111000010010111110010111011111001011011011011000110\n4",
"output": "131135624"
},
{
"input": "11001101101100010101011111100111001011010011\n4",
"output": "249690295"
},
{
"input": "101111101000011110011\n3",
"output": "818095"
},
{
"input": "11\n1",
"output": "1"
},
{
"input": "1101000100001110101110101011000100100111111110000011010101100111010\n3",
"output": "748765378"
},
{
"input": "1101011100011011000110101100111010011101001000100011111011011\n3",
"output": "541620851"
},
{
"input": "111000110101110110000001011000000011111011100000000101000011111100101000110101111111001110011100010101011010000001011110101100100101001101110101011101111000\n3",
"output": "154788917"
},
{
"input": "10000010000001111111011111010000101101101101010000100101000101011001011101111100001111001000100010111011101110111011000001110011111001100101101100000001011110010111101010001100111011110110111100100001110100100011101011011000010110010110101010100100000101001110101100110110100111110110100011111100010000011110000101010111111001001101101111\n4",
"output": "46847153"
},
{
"input": "1001100001011111100011111010001111001000000000110101100100011000111101111011010111110001001001111110011100100111011111011110101101001011111100101011000110100110011001101111001011101110011111101011100001011010100000100111011011\n4",
"output": "449157617"
},
{
"input": "1111110011110000001101111011001110111100001101111111110011101110111001001000011101100101001000000001110001010001101111001000010111110100110010001001110111100111000010111100011101001010010001111001100011100100111001101100010100111001000101100010100100101011010000011011010100101111011111101100001100010111111011111010\n3",
"output": "20014881"
},
{
"input": "11011101110100111111011101110111001101001001000111010010011100010100000101010011111101011000000110000110111101001111010101111110111011000011101111001101101100101110101010111011100010110111110001001011111110011110000011000111011010111100011000011011001101111100001101000010100011100000\n4",
"output": "545014668"
},
{
"input": "110100011111110101001011010110011010000010001111111011010011111100101000111000010000000001000010100101011001110101011100111111100101111011000011100100111100100100001101100000011010111110000101110110001100110011000111001101001101011101111101111111011000101010100111100101010111110011011111001100011011101110010100001110100010111\n4",
"output": "228787489"
},
{
"input": "111111011010010110111111\n4",
"output": "7297383"
},
{
"input": "111100111101110100010001110010001001001101110011011011011001110000000111111100100011001011100010001011100101100011010101100000101010000001110111100000111110100010011001111011101010001111011110111100100100101111100000010100110110101000111100001001000011110111101101001110010011111001011011110111111110110110010111101011001100010011100010001101001010100000100101001110111010011011101000011001101000011010110100111011101011001001001001110100000100111011011101010001\n3",
"output": "703566590"
},
{
"input": "111000100110111000010100000010001000001011100000000011101010101100010001010111101011110101000101110100000110110010001010101001000101000010010101101000000001110111100101111101010011100011000001101101101011101111100100011011111111101000101011101111101111111101000111101101101100000001000001111111011100110011000010100111011100000000111100001000111100000011110100011100101001001101110011101110111001010011100011111010010000001011001001010111100011111110010011000100101110\n4",
"output": "518347346"
},
{
"input": "11110011010101111001001000010111000101000100000010010001010110011100011100110110011011011111000101111100011101101010001011010000110000101111100011110101010011110001110001011001010000110111001101111101000000110010101110001100010000000101001001001000000010010100000110000010000111100110110001000110011011100\n1000",
"output": "0"
},
{
"input": "10011010111010010111111110001010001010001010110010110010010111101111000101110101010111100101001100011001001001111011111100011110101011011001101101001111111101010010110011111101110010001000111111100011000000111111111100011000000000110101111000001011101000110000111110110000010000010011000011011110101111111101100101000100000100010001010000110100111010110011000010001101011101101001010111101101110000101010111001011001100101000010110011110110011011001111110100011010010110011101011001111101\n208",
"output": "0"
},
{
"input": "1100101001110100100010011111001011101100101\n1000",
"output": "0"
},
{
"input": "10\n1",
"output": "1"
},
{
"input": "111\n1",
"output": "2"
},
{
"input": "11100001111100111110011100111100110111100111001101\n1",
"output": "49"
},
{
"input": "1000000000000000000001010100101\n1",
"output": "30"
},
{
"input": "110\n1",
"output": "2"
},
{
"input": "11011100\n1",
"output": "7"
},
{
"input": "10000000000000000000\n1",
"output": "19"
},
{
"input": "1111111011111110111\n1",
"output": "18"
},
{
"input": "1000\n1",
"output": "3"
},
{
"input": "100\n1",
"output": "2"
}
] | 93 | 6,963,200 | -1 | 1,334 |
|
837 | Text Volume | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz",
"output": "105"
},
{
"input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g",
"output": "1"
},
{
"input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez",
"output": "50"
},
{
"input": "1\ne",
"output": "0"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ",
"output": "10"
},
{
"input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "200"
},
{
"input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "24\nHarbour Space UniversitY",
"output": "2"
},
{
"input": "5\naA AA",
"output": "2"
},
{
"input": "10\nas AS ASDA",
"output": "4"
},
{
"input": "10\nas AS ASDZ",
"output": "4"
},
{
"input": "3\na A",
"output": "1"
},
{
"input": "24\nHarbour space UniversitY",
"output": "2"
},
{
"input": "10\nas AS ASAa",
"output": "3"
},
{
"input": "15\naAb ABCDFGRHTJS",
"output": "11"
},
{
"input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR",
"output": "6"
},
{
"input": "10\nABC ABc AB",
"output": "3"
},
{
"input": "10\nA c de CDE",
"output": "3"
},
{
"input": "4\nA AB",
"output": "2"
},
{
"input": "18\nHARbour Space UNIV",
"output": "4"
},
{
"input": "13\na b c d e f A",
"output": "1"
},
{
"input": "6\nA B CA",
"output": "2"
},
{
"input": "4\naa A",
"output": "1"
},
{
"input": "3\nA a",
"output": "1"
}
] | 61 | 0 | 0 | 1,339 |
|
875 | High Cry | [
"binary search",
"bitmasks",
"combinatorics",
"data structures",
"divide and conquer"
] | null | null | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this ridge: if Rick and Morty begin crying simultaneously from different mountains, their cry would be heard between these mountains up to the height equal the bitwise OR of mountains they've climbed and all the mountains between them.
Bitwise OR is a binary operation which is determined the following way. Consider representation of numbers *x* and *y* in binary numeric system (probably with leading zeroes) *x*<==<=*x**k*... *x*1*x*0 and *y*<==<=*y**k*... *y*1*y*0. Then *z*<==<=*x* | *y* is defined following way: *z*<==<=*z**k*... *z*1*z*0, where *z**i*<==<=1, if *x**i*<==<=1 or *y**i*<==<=1, and *z**i*<==<=0 otherwise. In the other words, digit of bitwise OR of two numbers equals zero if and only if digits at corresponding positions is both numbers equals zero. For example bitwise OR of numbers 10<==<=10102 and 9<==<=10012 equals 11<==<=10112. In programming languages C/C++/Java/Python this operation is defined as «|», and in Pascal as «or».
Help Rick and Morty calculate the number of ways they can select two mountains in such a way that if they start crying from these mountains their cry will be heard above these mountains and all mountains between them. More formally you should find number of pairs *l* and *r* (1<=≤<=*l*<=<<=*r*<=≤<=*n*) such that bitwise OR of heights of all mountains between *l* and *r* (inclusive) is larger than the height of any mountain at this interval. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000), the number of mountains in the ridge.
Second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109), the heights of mountains in order they are located in the ridge. | Print the only integer, the number of ways to choose two different mountains. | [
"5\n3 2 1 6 5\n",
"4\n3 3 3 3\n"
] | [
"8\n",
"0\n"
] | In the first test case all the ways are pairs of mountains with the numbers (numbering from one):
In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of any mountain. | [
{
"input": "5\n3 2 1 6 5",
"output": "8"
},
{
"input": "4\n3 3 3 3",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 255 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7",
"output": "0"
},
{
"input": "50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "81\n52673 19697 35512 34827 62387 60516 43450 22979 133 42838 16525 37792 12752 47765 45874 64082 14727 51748 56809 604 51751 59450 43797 31724 1024 9648 59503 53771 60868 38612 62867 57026 62297 15806 10549 7660 47983 30060 20829 46168 64832 18145 32300 53558 56554 33754 21953 58346 13894 6318 33563 63571 41705 49407 26794 51159 29011 43310 6847 11688 45129 2180 50406 12475 58021 58899 32867 15910 25819 33961 18759 64166 34472 57376 10903 16958 22656 14459 26900 33012 11615",
"output": "3239"
},
{
"input": "69\n3 4 2 4 5 2 0 5 2 8 8 0 0 8 6 4 3 0 0 1 2 5 8 1 7 4 6 0 6 1 8 4 2 0 4 3 5 6 2 8 3 7 7 6 0 3 8 6 2 6 0 2 4 5 0 3 6 8 8 8 3 2 2 6 7 8 5 3 5",
"output": "2262"
},
{
"input": "92\n7 1 1 2 5 8 3 4 1 3 0 7 5 2 0 7 2 7 3 2 7 3 7 7 7 0 8 2 0 7 4 7 6 7 3 6 2 0 2 4 1 6 6 4 5 7 3 2 8 6 7 8 8 2 4 2 7 2 2 4 7 5 4 3 4 4 1 2 2 1 4 4 1 8 0 7 8 0 8 6 7 3 2 6 7 2 7 3 1 0 3 6",
"output": "3630"
},
{
"input": "79\n48952 12057 54091 43986 4825 65319 8888 63361 37922 29880 42348 16202 7107 33942 28418 5373 37969 36323 36644 8650 2951 22084 38174 65285 4123 19887 46516 40807 40062 20157 58343 52857 42065 28397 15571 29810 17508 34053 2732 26989 37441 53824 23112 13218 6696 46519 10848 37031 16381 32753 39768 8870 61745 57147 47588 1759 25424 29718 34450 31641 64681 59257 47088 36889 31207 23425 25712 41458 27960 49566 50455 10157 53577 34807 39258 31040 39873 10859 24672",
"output": "3081"
},
{
"input": "80\n2 3 2 2 3 5 4 0 2 3 3 8 4 8 3 8 4 0 0 8 1 7 3 0 7 2 8 5 5 3 0 0 2 7 4 1 6 0 6 2 5 3 0 4 8 6 7 0 3 2 3 3 8 5 6 5 5 6 3 4 0 5 8 3 6 3 6 8 1 7 8 8 3 0 3 8 0 4 2 3",
"output": "2997"
},
{
"input": "74\n63528 64641 32712 5228 59859 45909 4464 57592 27841 17687 62064 19286 40682 40598 63681 18441 53374 38527 16119 35588 42691 4015 20251 13679 50493 37149 34328 37977 24309 8750 54309 44091 12187 21917 24216 31326 40587 52208 19362 1642 13268 6596 10380 4937 37224 25970 59246 63483 20707 47702 57607 26046 30796 32636 7168 8816 11892 12934 53913 704 61887 65147 52243 14676 20993 33174 40778 23764 37017 5206 22521 55323 36803 9943",
"output": "2691"
},
{
"input": "47\n4 4 3 1 0 1 2 8 6 3 1 5 6 5 4 5 3 8 4 8 7 6 8 1 4 8 1 5 7 4 8 7 8 7 5 6 7 5 5 5 6 5 3 0 2 5 6",
"output": "1010"
},
{
"input": "53\n1 2 0 1 0 1 1 1 1 2 0 2 1 0 2 2 1 1 2 0 0 2 1 2 2 1 1 0 0 1 0 1 2 2 1 1 1 1 1 1 2 1 0 1 2 1 0 0 0 1 2 0 2",
"output": "1288"
},
{
"input": "85\n4 4 4 4 2 1 2 0 0 3 1 0 4 3 2 2 3 4 1 0 0 0 0 2 1 1 1 1 0 1 4 2 2 1 0 4 4 1 4 0 3 2 3 4 0 4 3 0 3 1 0 1 3 1 2 0 2 3 1 1 2 4 0 4 1 1 1 3 3 4 3 1 0 3 0 0 0 4 2 3 1 1 4 0 0",
"output": "3346"
},
{
"input": "100\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7",
"output": "0"
},
{
"input": "100\n1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 64 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4",
"output": "4950"
},
{
"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": "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": "0"
},
{
"input": "100\n1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512",
"output": "4950"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 32 32 32 32 32 32 32 32 32 32 64 64 64 64 64 64 64 64 64 64 128 128 128 128 128 128 128 128 128 128 256 256 256 256 256 256 256 256 256 256 512 512 512 512 512 512 512 512 512 512",
"output": "4500"
}
] | 62 | 0 | 0 | 1,340 |
|
802 | Send the Fool Further! (easy) | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.
Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?
Heidi's *n* friends are labeled 0 through *n*<=-<=1, and their network of connections forms a tree. In other words, every two of her friends *a*, *b* know each other, possibly indirectly (there is a sequence of friends starting from *a* and ending on *b* and such that each two consecutive friends in the sequence know each other directly), and there are exactly *n*<=-<=1 pairs of friends who know each other directly.
Jenny is given the number 0. | The first line of the input contains the number of friends *n* (3<=≤<=*n*<=≤<=100). The next *n*<=-<=1 lines each contain three space-separated integers *u*, *v* and *c* (0<=≤<=*u*,<=*v*<=≤<=*n*<=-<=1, 1<=≤<=*c*<=≤<=104), meaning that *u* and *v* are friends (know each other directly) and the cost for travelling between *u* and *v* is *c*.
It is guaranteed that the social network of the input forms a tree. | Output a single integer – the maximum sum of costs. | [
"4\n0 1 4\n0 2 2\n2 3 3\n",
"6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10\n",
"11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378\n"
] | [
"5\n",
"105\n",
"5551\n"
] | In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). | [
{
"input": "4\n0 1 4\n0 2 2\n2 3 3",
"output": "5"
},
{
"input": "3\n1 0 5987\n2 0 8891",
"output": "8891"
},
{
"input": "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647",
"output": "15685"
},
{
"input": "11\n1 0 6646\n2 0 8816\n3 2 9375\n4 2 5950\n5 1 8702\n6 2 2657\n7 2 885\n8 7 2660\n9 2 5369\n10 6 3798",
"output": "18191"
},
{
"input": "10\n0 1 7171\n0 2 2280\n1 3 9126\n2 4 2598\n5 4 8320\n6 2 1855\n3 7 9204\n7 8 2145\n4 9 10",
"output": "27646"
},
{
"input": "6\n1 2 3\n0 2 100\n1 4 2\n0 3 7\n3 5 10",
"output": "105"
},
{
"input": "11\n1 0 1664\n2 0 881\n3 2 4670\n4 2 1555\n5 1 1870\n6 2 1265\n7 2 288\n8 7 2266\n9 2 1536\n10 6 3378",
"output": "5551"
}
] | 140 | 20,172,800 | 3 | 1,343 |
|
628 | Tennis Tournament | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes.
Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). | The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* — the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
"output": "1497 500"
},
{
"input": "500 500 500",
"output": "499499 250000"
},
{
"input": "500 237 474",
"output": "237025 237000"
},
{
"input": "1 2 3",
"output": "0 3"
},
{
"input": "1 2 133",
"output": "0 133"
},
{
"input": "1 2 100",
"output": "0 100"
},
{
"input": "1 3 4",
"output": "0 4"
},
{
"input": "1 10 15",
"output": "0 15"
},
{
"input": "1 1 1",
"output": "0 1"
},
{
"input": "1 2 5",
"output": "0 5"
},
{
"input": "1 500 500",
"output": "0 500"
},
{
"input": "1 3 8",
"output": "0 8"
},
{
"input": "10 10 10",
"output": "189 100"
},
{
"input": "1 3 5",
"output": "0 5"
},
{
"input": "1 2 1",
"output": "0 1"
},
{
"input": "1 2 4",
"output": "0 4"
},
{
"input": "1 10 10",
"output": "0 10"
},
{
"input": "1 345 345",
"output": "0 345"
},
{
"input": "7 12 13",
"output": "150 91"
},
{
"input": "1 500 1",
"output": "0 1"
},
{
"input": "1 12 13",
"output": "0 13"
},
{
"input": "1 500 499",
"output": "0 499"
},
{
"input": "1 100 90",
"output": "0 90"
},
{
"input": "2 100 90",
"output": "201 180"
},
{
"input": "53 1 1",
"output": "156 53"
},
{
"input": "73 73 73",
"output": "10584 5329"
},
{
"input": "67 1 1",
"output": "198 67"
},
{
"input": "63 1 1",
"output": "186 63"
},
{
"input": "59 1 1",
"output": "174 59"
},
{
"input": "57 1 1",
"output": "168 57"
},
{
"input": "13 1 1",
"output": "36 13"
},
{
"input": "349 2 5",
"output": "1740 1745"
},
{
"input": "456 456 456",
"output": "415415 207936"
}
] | 156 | 20,172,800 | 3 | 1,345 |
|
0 | none | [
"none"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.
Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*. | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7",
"output": "4"
},
{
"input": "5\n1 1\n3 1\n5 1\n7 10\n8 10",
"output": "2"
},
{
"input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1",
"output": "4"
}
] | 530 | 25,395,200 | 0 | 1,352 |
|
317 | Perfect Pair | [
"brute force"
] | null | null | Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (*x*<=+<=*y*).
What is the minimum number of such operations one has to perform in order to make the given pair of integers *m*-perfect? | Single line of the input contains three integers *x*, *y* and *m* (<=-<=1018<=≤<=*x*, *y*, *m*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier. | Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the *m*-perfect one. | [
"1 2 5\n",
"-1 4 15\n",
"0 -1 5\n"
] | [
"2\n",
"4\n",
"-1\n"
] | In the first sample the following sequence of operations is suitable: (1, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (5, 2).
In the second sample: (-1, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (7, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (11, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (15, 4).
Finally, in the third sample *x*, *y* cannot be made positive, hence there is no proper sequence of operations. | [
{
"input": "1 2 5",
"output": "2"
},
{
"input": "-1 4 15",
"output": "4"
},
{
"input": "0 -1 5",
"output": "-1"
},
{
"input": "0 1 8",
"output": "5"
},
{
"input": "-134 -345 -134",
"output": "0"
},
{
"input": "-134 -345 -133",
"output": "-1"
},
{
"input": "999999999 -1000000000 1000000000",
"output": "3"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 0 1",
"output": "-1"
},
{
"input": "-1000000000000000000 1 1000000000000000000",
"output": "1000000000000000087"
},
{
"input": "-3 26 -1",
"output": "0"
},
{
"input": "-25 4 -8",
"output": "0"
},
{
"input": "12 30 -8",
"output": "0"
},
{
"input": "-12 17 3",
"output": "0"
},
{
"input": "4 -11 28",
"output": "8"
},
{
"input": "38 174 957147453",
"output": "33"
},
{
"input": "154 30 763391461",
"output": "33"
},
{
"input": "3 193 648520002",
"output": "32"
},
{
"input": "139 82 923851170",
"output": "33"
},
{
"input": "171 185 534908267",
"output": "31"
},
{
"input": "-868993006 -389009632 -766659629",
"output": "0"
},
{
"input": "-429468031 69656014 39767881",
"output": "0"
},
{
"input": "185212727 871828769 828159476",
"output": "0"
},
{
"input": "140457446 731228634 -75123935",
"output": "0"
},
{
"input": "223567628 -731033737 352248633",
"output": "5"
},
{
"input": "-187818082 -372699371 -301077133",
"output": "0"
},
{
"input": "-552043292 -693546115 415527936",
"output": "-1"
},
{
"input": "-29007970 -344600631 62206369",
"output": "-1"
},
{
"input": "101292660 -305927896 648565756",
"output": "8"
},
{
"input": "702748103 -278432024 995244274",
"output": "2"
},
{
"input": "0 0 -1",
"output": "0"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 0 1000000000",
"output": "-1"
},
{
"input": "0 0 1",
"output": "-1"
},
{
"input": "1 -999999999 239239239",
"output": "1000000040"
},
{
"input": "-1 -1 0",
"output": "-1"
},
{
"input": "-1 0 0",
"output": "0"
},
{
"input": "-1 0 1",
"output": "-1"
},
{
"input": "-1000000000 -1000000000 -1000000000",
"output": "0"
},
{
"input": "-1000000000 -1000000000 1000000000",
"output": "-1"
},
{
"input": "999999999 999999999 1000000000",
"output": "1"
},
{
"input": "-1 1 609276626",
"output": "44"
},
{
"input": "-1 2 926098525",
"output": "43"
},
{
"input": "0 0 698431198",
"output": "-1"
},
{
"input": "0 -3 702455284",
"output": "-1"
},
{
"input": "0 0 648749804",
"output": "-1"
},
{
"input": "-1 0 861856808",
"output": "-1"
},
{
"input": "2 2 -213745374",
"output": "0"
},
{
"input": "-1 1 21065410",
"output": "37"
},
{
"input": "3 -3 607820420",
"output": "42"
},
{
"input": "36 -58 428518679",
"output": "37"
},
{
"input": "8 55 931239629",
"output": "36"
},
{
"input": "-99 -91 523666385",
"output": "-1"
},
{
"input": "-56 -11 631827324",
"output": "-1"
},
{
"input": "-4 6 447215792",
"output": "39"
},
{
"input": "-47 -31 -669106932",
"output": "0"
},
{
"input": "12 -76 -999189104",
"output": "0"
},
{
"input": "39 15 -960040787",
"output": "0"
},
{
"input": "-96 26 -210129802",
"output": "0"
},
{
"input": "93 86 -850132431",
"output": "0"
},
{
"input": "1 -1000000000000000000 1000000000000000000",
"output": "1000000000000000087"
},
{
"input": "-2348349823443 234234545453 1000000000000000000",
"output": "43"
},
{
"input": "0 1 679891637638612258",
"output": "86"
},
{
"input": "-1000000000000000000 -1000000000000000000 -1000000000000000000",
"output": "0"
},
{
"input": "-1000000000000000000 -1000000000000000000 -999999999999999999",
"output": "-1"
},
{
"input": "-100000000000000 1 233",
"output": "100000000000012"
},
{
"input": "-1000000000000 2 1000000000000",
"output": "500000000057"
},
{
"input": "-1000000000000 3 1000000000",
"output": "333333333375"
},
{
"input": "10 -10 0",
"output": "0"
},
{
"input": "-1000000000000000 2 444",
"output": "500000000000012"
}
] | 62 | 0 | 0 | 1,360 |
|
606 | Testing Robots | [
"implementation"
] | null | null | The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (*x*0,<=*y*0) of a rectangular squared field of size *x*<=×<=*y*, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly *x*·*y* tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same.
After placing the objects on the field the robot will have to run a sequence of commands given by string *s*, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code.
Moving to the left decreases coordinate *y*, and moving to the right increases it. Similarly, moving up decreases the *x* coordinate, and moving down increases it.
The tests can go on for very long, so your task is to predict their results. For each *k* from 0 to *length*(*s*) your task is to find in how many tests the robot will run exactly *k* commands before it blows up. | The first line of the input contains four integers *x*, *y*, *x*0, *y*0 (1<=≤<=*x*,<=*y*<=≤<=500,<=1<=≤<=*x*0<=≤<=*x*,<=1<=≤<=*y*0<=≤<=*y*) — the sizes of the field and the starting coordinates of the robot. The coordinate axis *X* is directed downwards and axis *Y* is directed to the right.
The second line contains a sequence of commands *s*, which should be fulfilled by the robot. It has length from 1 to 100<=000 characters and only consists of characters 'L', 'R', 'U', 'D'. | Print the sequence consisting of (*length*(*s*)<=+<=1) numbers. On the *k*-th position, starting with zero, print the number of tests where the robot will run exactly *k* commands before it blows up. | [
"3 4 2 2\nUURDRDRL\n",
"2 2 2 2\nULD\n"
] | [
"1 1 0 1 1 1 1 0 6\n",
"1 1 1 1\n"
] | In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16bfda1e4f41cc00665c31f0a1d754d68cd9b4ab.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "3 4 2 2\nUURDRDRL",
"output": "1 1 0 1 1 1 1 0 6"
},
{
"input": "2 2 2 2\nULD",
"output": "1 1 1 1"
},
{
"input": "1 1 1 1\nURDLUURRDDLLURDL",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
},
{
"input": "15 17 8 9\nURRDLUULLDD",
"output": "1 1 1 1 1 1 0 1 1 1 1 245"
},
{
"input": "15 17 8 9\nURRDLUULLDDDRRUR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 241"
},
{
"input": "15 17 8 9\nURRDLUULLDDDRRURR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 241"
},
{
"input": "1 2 1 1\nR",
"output": "1 1"
},
{
"input": "2 1 1 1\nD",
"output": "1 1"
},
{
"input": "1 2 1 2\nLR",
"output": "1 1 0"
},
{
"input": "2 1 2 1\nUD",
"output": "1 1 0"
},
{
"input": "4 4 2 2\nDRUL",
"output": "1 1 1 1 12"
},
{
"input": "4 4 3 3\nLUDRUL",
"output": "1 1 1 0 0 1 12"
},
{
"input": "15 17 8 9\nURRDLU",
"output": "1 1 1 1 1 1 249"
},
{
"input": "15 17 8 9\nURRDLUULLDDR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 244"
},
{
"input": "15 17 8 9\nURRDLUULLDDRR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 0 244"
},
{
"input": "15 17 8 9\nURRDLUULLDDRRR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 0 0 244"
},
{
"input": "15 17 8 9\nURRDLUULLDDRRRR",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 244"
},
{
"input": "15 17 8 9\nURRDLUULLDDRRRRU",
"output": "1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 243"
}
] | 217 | 18,944,000 | 3 | 1,363 |
|
801 | Vicious Keyboard | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences. | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV",
"output": "14"
},
{
"input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK",
"output": "32"
},
{
"input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK",
"output": "32"
},
{
"input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK",
"output": "21"
},
{
"input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV",
"output": "25"
},
{
"input": "KKVVKVVKVVKKVVKKVKVVKKV",
"output": "7"
},
{
"input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV",
"output": "24"
},
{
"input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV",
"output": "35"
},
{
"input": "VKVVVKKKVKVVKVKVKVKVKVV",
"output": "9"
},
{
"input": "KKKKVKKVKVKVKKKVVVVKK",
"output": "6"
},
{
"input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK",
"output": "9"
},
{
"input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK",
"output": "22"
},
{
"input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK",
"output": "25"
},
{
"input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK",
"output": "29"
},
{
"input": "KKVKVVVKKVV",
"output": "3"
},
{
"input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK",
"output": "16"
},
{
"input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV",
"output": "13"
},
{
"input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV",
"output": "26"
},
{
"input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV",
"output": "26"
},
{
"input": "K",
"output": "0"
},
{
"input": "VKVK",
"output": "2"
},
{
"input": "VKVV",
"output": "2"
},
{
"input": "KV",
"output": "0"
},
{
"input": "KK",
"output": "1"
},
{
"input": "KKVK",
"output": "2"
},
{
"input": "KKKK",
"output": "1"
},
{
"input": "KKV",
"output": "1"
},
{
"input": "KKVKVK",
"output": "3"
},
{
"input": "VKKVK",
"output": "2"
},
{
"input": "VKKK",
"output": "2"
},
{
"input": "KKK",
"output": "1"
},
{
"input": "KVV",
"output": "1"
},
{
"input": "KKVKV",
"output": "2"
},
{
"input": "VVK",
"output": "1"
},
{
"input": "VVVKVKVKVKVKVKVK",
"output": "8"
},
{
"input": "KVVVK",
"output": "2"
},
{
"input": "VVVKK",
"output": "2"
},
{
"input": "KKVV",
"output": "1"
},
{
"input": "KKKKKKK",
"output": "1"
},
{
"input": "VKKKVK",
"output": "3"
},
{
"input": "KKVVV",
"output": "1"
},
{
"input": "VVVVVV",
"output": "1"
},
{
"input": "KKKV",
"output": "1"
},
{
"input": "VVKVV",
"output": "2"
},
{
"input": "VKVKKK",
"output": "3"
},
{
"input": "VKKV",
"output": "1"
},
{
"input": "VKKVV",
"output": "2"
},
{
"input": "VVKKVV",
"output": "2"
},
{
"input": "KKVVKKV",
"output": "2"
},
{
"input": "KKKKK",
"output": "1"
},
{
"input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK",
"output": "10"
},
{
"input": "VKVKVV",
"output": "3"
},
{
"input": "VKVVKVV",
"output": "3"
},
{
"input": "VVV",
"output": "1"
},
{
"input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
"output": "1"
},
{
"input": "VVKKKKKKVKK",
"output": "3"
},
{
"input": "KVKVKVV",
"output": "3"
}
] | 61 | 5,529,600 | 3 | 1,367 |
|
612 | The Text Splitting | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them. | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"output": "1\n1"
},
{
"input": "10 8 1\nuTl9w4lcdo",
"output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no"
},
{
"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61",
"output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61"
},
{
"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6",
"output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6"
},
{
"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde",
"output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde"
},
{
"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu",
"output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu"
},
{
"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj",
"output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj"
},
{
"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY",
"output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY"
},
{
"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc",
"output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc"
},
{
"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE",
"output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE"
},
{
"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB",
"output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB"
},
{
"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ",
"output": "-1"
},
{
"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn",
"output": "-1"
},
{
"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT",
"output": "-1"
},
{
"input": "10 3 1\nXQ2vXLPShy",
"output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny"
},
{
"input": "4 2 3\naaaa",
"output": "2\naa\naa"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\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"
},
{
"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 2 3\nhavanahavan",
"output": "4\nha\nvan\naha\nvan"
},
{
"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa"
},
{
"input": "17 3 5\ngopstopmipodoshli",
"output": "5\ngop\nsto\npmi\npod\noshli"
},
{
"input": "5 4 3\nfoyku",
"output": "-1"
},
{
"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "-1"
},
{
"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit",
"output": "-1"
},
{
"input": "11 2 3\nqibwnnvqqgo",
"output": "4\nqi\nbwn\nnvq\nqgo"
},
{
"input": "4 4 3\nhhhh",
"output": "1\nhhhh"
},
{
"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh"
},
{
"input": "10 5 9\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "10 5 9\naaaaaaaaaa",
"output": "2\naaaaa\naaaaa"
},
{
"input": "11 3 2\nmlmqpohwtsf",
"output": "5\nmlm\nqp\noh\nwt\nsf"
},
{
"input": "3 3 2\nzyx",
"output": "1\nzyx"
},
{
"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "4 2 3\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "3 2 3\nejt",
"output": "1\nejt"
},
{
"input": "5 2 4\nzyxwv",
"output": "-1"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na"
},
{
"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa"
},
{
"input": "3 2 2\nzyx",
"output": "-1"
},
{
"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "-1"
},
{
"input": "26 8 9\nabcabcabcabcabcabcabcabcab",
"output": "3\nabcabcab\ncabcabcab\ncabcabcab"
},
{
"input": "6 3 5\naaaaaa",
"output": "2\naaa\naaa"
},
{
"input": "3 2 3\nzyx",
"output": "1\nzyx"
},
{
"input": "5 5 2\naaaaa",
"output": "1\naaaaa"
},
{
"input": "4 3 2\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "5 4 3\nzyxwv",
"output": "-1"
},
{
"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab"
},
{
"input": "3 2 2\naaa",
"output": "-1"
},
{
"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj",
"output": "-1"
},
{
"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "-1"
},
{
"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab"
},
{
"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "-1"
},
{
"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb",
"output": "-1"
},
{
"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy",
"output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy"
},
{
"input": "16 3 7\naaaaaaaaaaaaaaaa",
"output": "4\naaa\naaa\naaa\naaaaaaa"
},
{
"input": "11 10 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 8 8\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 7 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab"
},
{
"input": "11 3 2\naaaaaaaaaaa",
"output": "5\naaa\naa\naa\naa\naa"
},
{
"input": "14 9 4\nabcdefghijklmn",
"output": "-1"
},
{
"input": "9 9 5\n123456789",
"output": "1\n123456789"
},
{
"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw",
"output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw"
},
{
"input": "17 16 3\ndxyhgtsxtuyljmclj",
"output": "-1"
},
{
"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd",
"output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd"
},
{
"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor",
"output": "-1"
},
{
"input": "7 5 3\nzyxwvut",
"output": "-1"
},
{
"input": "17 16 4\nctvfhkiakagcilrdw",
"output": "-1"
}
] | 31 | 5,529,600 | 0 | 1,368 |
|
685 | Robbers' watch | [
"brute force",
"combinatorics",
"dp",
"math"
] | null | null | Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in *n* hours, and each hour in *m* minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to *n*<=-<=1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to *m*<=-<=1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number. | The first line of the input contains two integers, given in the decimal notation, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of hours in one day and the number of minutes in one hour, respectively. | Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct. | [
"2 3\n",
"8 2\n"
] | [
"4\n",
"5\n"
] | In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | [
{
"input": "2 3",
"output": "4"
},
{
"input": "8 2",
"output": "5"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "8 8",
"output": "0"
},
{
"input": "50 50",
"output": "0"
},
{
"input": "344 344",
"output": "0"
},
{
"input": "282475250 282475250",
"output": "0"
},
{
"input": "8 282475250",
"output": "0"
},
{
"input": "1000000000 1000000000",
"output": "0"
},
{
"input": "16808 7",
"output": "720"
},
{
"input": "2402 50",
"output": "0"
},
{
"input": "343 2401",
"output": "5040"
},
{
"input": "1582 301",
"output": "2874"
},
{
"input": "421414245 4768815",
"output": "0"
},
{
"input": "2401 343",
"output": "5040"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "282475250 8",
"output": "0"
},
{
"input": "8 7",
"output": "35"
},
{
"input": "50 7",
"output": "120"
},
{
"input": "16808 8",
"output": "0"
},
{
"input": "2402 49",
"output": "720"
},
{
"input": "123 123",
"output": "360"
},
{
"input": "123 456",
"output": "150"
},
{
"input": "1 9",
"output": "0"
},
{
"input": "1 10",
"output": "1"
},
{
"input": "50 67",
"output": "6"
},
{
"input": "7 117649",
"output": "5040"
},
{
"input": "2400 342",
"output": "5040"
},
{
"input": "2400 227",
"output": "3360"
},
{
"input": "117648 5",
"output": "3600"
},
{
"input": "16808 41",
"output": "0"
},
{
"input": "3 16808",
"output": "240"
},
{
"input": "823542 3",
"output": "0"
},
{
"input": "3 823544",
"output": "0"
},
{
"input": "117650 5",
"output": "0"
},
{
"input": "50 50",
"output": "0"
},
{
"input": "50 3",
"output": "40"
},
{
"input": "2402 343",
"output": "0"
}
] | 0 | 0 | -1 | 1,369 |
|
18 | Seller Bob | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1",
"output": "2147483646"
},
{
"input": "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819",
"output": "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054..."
},
{
"input": "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304",
"output": "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648"
},
{
"input": "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257",
"output": "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273..."
},
{
"input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165",
"output": "0"
},
{
"input": "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312",
"output": "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933..."
},
{
"input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838",
"output": "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779..."
},
{
"input": "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157",
"output": "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144"
},
{
"input": "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549",
"output": "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096"
},
{
"input": "1\nsell 2000",
"output": "0"
},
{
"input": "1\nwin 2000",
"output": "0"
},
{
"input": "2\nwin 2000\nsell 2000",
"output": "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..."
}
] | 92 | 4,608,000 | 0 | 1,377 |
791 | Bear and Big Brother | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob? | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "4"
},
{
"input": "1 6",
"output": "5"
},
{
"input": "1 7",
"output": "5"
},
{
"input": "1 8",
"output": "6"
},
{
"input": "1 9",
"output": "6"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "2 5",
"output": "3"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "4"
},
{
"input": "2 8",
"output": "4"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "2 10",
"output": "4"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "3 4",
"output": "1"
},
{
"input": "3 5",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "3 9",
"output": "3"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "4 10",
"output": "3"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "1"
},
{
"input": "5 7",
"output": "1"
},
{
"input": "5 8",
"output": "2"
},
{
"input": "5 9",
"output": "2"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "6 9",
"output": "2"
},
{
"input": "6 10",
"output": "2"
},
{
"input": "7 7",
"output": "1"
},
{
"input": "7 8",
"output": "1"
},
{
"input": "7 9",
"output": "1"
},
{
"input": "7 10",
"output": "1"
},
{
"input": "8 8",
"output": "1"
},
{
"input": "8 9",
"output": "1"
},
{
"input": "8 10",
"output": "1"
},
{
"input": "9 9",
"output": "1"
},
{
"input": "9 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "1 2",
"output": "2"
}
] | 46 | 0 | 3 | 1,381 |
Subsets and Splits