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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
603 | Pastoral Oddities | [
"data structures",
"divide and conquer",
"dsu",
"math",
"trees"
] | null | null | In the land of Bovinia there are *n* pastures, but no paths connecting the pastures. Of course, this is a terrible situation, so Kevin Sun is planning to rectify it by constructing *m* undirected paths connecting pairs of distinct pastures. To make transportation more efficient, he also plans to pave some of these new paths.
Kevin is very particular about certain aspects of path-paving. Since he loves odd numbers, he wants each pasture to have an odd number of paved paths connected to it. Thus we call a paving sunny if each pasture is incident to an odd number of paved paths. He also enjoys short paths more than long paths, so he would like the longest paved path to be as short as possible. After adding each path, Kevin wants to know if a sunny paving exists for the paths of Bovinia, and if at least one does, the minimum possible length of the longest path in such a paving. Note that "longest path" here means maximum-weight edge. | The first line contains two integers *n* (2<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=300<=000), denoting the number of pastures and paths, respectively. The next *m* lines each contain three integers *a**i*, *b**i* and *l**i*, describing the *i*-th path. The *i*-th path connects pastures *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) and has length *l**i* (1<=≤<=*l**i*<=≤<=109). Paths are given in the order in which they are constructed. | Output *m* lines. The *i*-th line should contain a single integer denoting the minimum possible length of the longest path (maximum-weight edge) in a sunny paving using only the first *i* paths. If Kevin cannot pave a set of paths so that each pasture is incident to an odd number of paved paths, output <=-<=1.
Note that the paving is only hypothetical—your answer after adding the *i*-th path should not be affected by any of your previous answers. | [
"4 4\n1 3 4\n2 4 8\n1 2 2\n3 4 3\n",
"3 2\n1 2 3\n2 3 4\n",
"4 10\n2 1 987\n3 2 829\n4 1 768\n4 2 608\n3 4 593\n3 2 488\n4 2 334\n2 1 204\n1 3 114\n1 4 39\n"
] | [
"-1\n8\n8\n3\n",
"-1\n-1\n",
"-1\n-1\n829\n829\n768\n768\n768\n488\n334\n204\n"
] | For the first sample, these are the paths that Kevin should pave after building the *i*-th path:
1. No set of paths works. 1. Paths 1 (length 4) and 2 (length 8). 1. Paths 1 (length 4) and 2 (length 8). 1. Paths 3 (length 2) and 4 (length 3).
In the second sample, there never exists a paving that makes Kevin happy. | [] | 46 | 0 | 0 | 571,006 |
|
464 | World of Darkraft - 2 | [
"dp",
"probabilities"
] | null | null | Roma found a new character in the game "World of Darkraft - 2". In this game the character fights monsters, finds the more and more advanced stuff that lets him fight stronger monsters.
The character can equip himself with *k* distinct types of items. Power of each item depends on its level (positive integer number). Initially the character has one 1-level item of each of the *k* types.
After the victory over the monster the character finds exactly one new randomly generated item. The generation process looks as follows. Firstly the type of the item is defined; each of the *k* types has the same probability. Then the level of the new item is defined. Let's assume that the level of player's item of the chosen type is equal to *t* at the moment. Level of the new item will be chosen uniformly among integers from segment [1; *t*<=+<=1].
From the new item and the current player's item of the same type Roma chooses the best one (i.e. the one with greater level) and equips it (if both of them has the same level Roma choses any). The remaining item is sold for coins. Roma sells an item of level *x* of any type for *x* coins.
Help Roma determine the expected number of earned coins after the victory over *n* monsters. | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=105; 1<=≤<=*k*<=≤<=100). | Print a real number — expected number of earned coins after victory over *n* monsters. The answer is considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"1 3\n",
"2 1\n",
"10 2\n"
] | [
"1.0000000000\n",
"2.3333333333\n",
"15.9380768924\n"
] | none | [] | 30 | 0 | 0 | 571,350 |
|
935 | Fafa and Array | [
"data structures",
"greedy"
] | null | null | Fafa has an array *A* of *n* positive integers, the function *f*(*A*) is defined as . He wants to do *q* queries of two types:
- 1<=*l*<=*r*<=*x* — find the maximum possible value of *f*(*A*), if *x* is to be added to one element in the range [*l*,<=<=*r*]. You can choose to which element to add *x*. - 2<=*l*<=*r*<=*x* — increase all the elements in the range [*l*,<=<=*r*] by value *x*.
Note that queries of type 1 don't affect the array elements. | The first line contains one integer *n* (3<=≤<=*n*<=≤<=105) — the length of the array.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (0<=<<=*a**i*<=≤<=109) — the array elements.
The third line contains an integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
Then *q* lines follow, line *i* describes the *i*-th query and contains four integers *t**i*<=*l**i*<=*r**i*<=*x**i* .
It is guaranteed that at least one of the queries is of type 1. | For each query of type 1, print the answer to the query. | [
"5\n1 1 1 1 1\n5\n1 2 4 1\n2 2 3 1\n2 4 4 2\n2 3 4 1\n1 3 3 2\n",
"5\n1 2 3 4 5\n4\n1 2 4 2\n2 2 4 1\n2 3 4 1\n1 2 4 2\n"
] | [
"2\n8\n",
"6\n10\n"
] | none | [
{
"input": "5\n1 1 1 1 1\n5\n1 2 4 1\n2 2 3 1\n2 4 4 2\n2 3 4 1\n1 3 3 2",
"output": "2\n8"
},
{
"input": "5\n1 2 3 4 5\n4\n1 2 4 2\n2 2 4 1\n2 3 4 1\n1 2 4 2",
"output": "6\n10"
},
{
"input": "5\n1000 100 1 100 10000\n4\n1 2 4 10\n1 2 4 1000\n1 2 4 100\n1 2 4 59",
"output": "10998\n12602\n10998\n10998"
},
{
"input": "4\n4 3 2 1\n1\n1 2 3 2",
"output": "5"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n11\n2 2 3 1000000000\n2 5 6 1000000000\n2 2 2 1000000000\n2 6 6 1000000000\n1 2 6 1000000000\n1 2 6 1\n2 2 6 1000000000\n1 2 6 1000000000\n1 2 6 1\n1 3 5 1000000000\n1 4 4 1000000000",
"output": "10000000000\n8000000002\n12000000000\n10000000002\n10000000000\n8000000000"
},
{
"input": "7\n20 10 3 1 7 10 20\n25\n1 4 4 2\n1 4 4 3\n1 4 4 4\n1 4 4 5\n1 4 4 7\n1 4 4 100\n1 2 6 2\n1 2 6 3\n1 2 6 4\n1 2 6 5\n1 2 6 7\n1 2 6 100\n2 3 3 4\n1 4 4 2\n1 4 4 3\n1 4 4 4\n1 4 4 5\n1 4 4 7\n1 4 4 100\n1 2 6 2\n1 2 6 3\n1 2 6 4\n1 2 6 5\n1 2 6 7\n1 2 6 100",
"output": "34\n34\n34\n34\n36\n222\n38\n38\n40\n42\n46\n232\n34\n32\n30\n28\n28\n214\n38\n38\n40\n42\n46\n232"
},
{
"input": "3\n1 2 3\n3\n1 2 2 3\n2 2 2 5\n1 2 2 3",
"output": "6\n16"
},
{
"input": "3\n5 1 10\n15\n1 2 2 1\n1 2 2 2\n1 2 2 3\n1 2 2 4\n1 2 2 5\n1 2 2 6\n1 2 2 7\n1 2 2 8\n1 2 2 9\n1 2 2 10\n1 2 2 11\n1 2 2 12\n1 2 2 13\n1 2 2 14\n1 2 2 1000000000",
"output": "11\n9\n7\n5\n5\n5\n5\n5\n5\n7\n9\n11\n13\n15\n1999999987"
},
{
"input": "8\n1 3 5 7 8 10 12 14\n15\n1 3 7 1\n1 3 7 2\n1 3 7 3\n1 3 7 4\n2 2 3 3\n1 3 7 1\n1 3 7 2\n1 3 7 3\n1 3 7 4\n2 2 2 4\n1 3 7 1\n1 3 7 2\n1 3 7 3\n1 3 7 4\n2 2 2 4",
"output": "13\n15\n17\n19\n17\n19\n21\n23\n19\n19\n21\n23"
},
{
"input": "6\n10 7 6 6 8 11\n5\n1 2 5 1\n1 2 5 2\n1 2 5 3\n1 2 5 4\n1 3 4 2",
"output": "9\n11\n13\n15\n11"
},
{
"input": "30\n1000 990 980 970 960 950 940 930 920 910 900 890 880 870 869 870 880 890 900 910 920 930 940 950 960 970 980 990 1000 1010\n1\n1 2 29 1000",
"output": "2268"
}
] | 46 | 0 | 0 | 571,708 |
|
681 | Runaway to a Shadow | [
"geometry",
"sortings"
] | null | null | Dima is living in a dormitory, as well as some cockroaches.
At the moment 0 Dima saw a cockroach running on a table and decided to kill it. Dima needs exactly *T* seconds for aiming, and after that he will precisely strike the cockroach and finish it.
To survive the cockroach has to run into a shadow, cast by round plates standing on the table, in *T* seconds. Shadow casted by any of the plates has the shape of a circle. Shadow circles may intersect, nest or overlap arbitrarily.
The cockroach uses the following strategy: first he equiprobably picks a direction to run towards and then runs towards it with the constant speed *v*. If at some moment *t*<=≤<=*T* it reaches any shadow circle, it immediately stops in the shadow and thus will stay alive. Otherwise the cockroach is killed by the Dima's precise strike. Consider that the Dima's precise strike is instant.
Determine the probability of that the cockroach will stay alive. | In the first line of the input the four integers *x*0, *y*0, *v*, *T* (|*x*0|,<=|*y*0|<=≤<=109, 0<=≤<=*v*,<=*T*<=≤<=109) are given — the cockroach initial position on the table in the Cartesian system at the moment 0, the cockroach's constant speed and the time in seconds Dima needs for aiming respectively.
In the next line the only number *n* (1<=≤<=*n*<=≤<=100<=000) is given — the number of shadow circles casted by plates.
In the next *n* lines shadow circle description is given: the *i**th* of them consists of three integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=109, 0<=≤<=*r*<=≤<=109) — the *i**th* shadow circle on-table position in the Cartesian system and its radius respectively.
Consider that the table is big enough for the cockroach not to run to the table edges and avoid Dima's precise strike. | Print the only real number *p* — the probability of that the cockroach will stay alive.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4. | [
"0 0 1 1\n3\n1 1 1\n-1 -1 1\n-2 2 1\n",
"0 0 1 0\n1\n1 0 1\n"
] | [
"0.50000000000",
"1.00000000000"
] | The picture for the first sample is given below.
Red color stands for points which being chosen as the cockroach's running direction will cause him being killed, green color for those standing for survival directions. Please note that despite containing a circle centered in ( - 2, 2) a part of zone is colored red because the cockroach is not able to reach it in one second. | [] | 46 | 0 | 0 | 574,384 |
|
150 | Mission Impassable | [
"dp",
"strings"
] | null | null | Market stalls now have the long-awaited game The Colder Scrools V: Nvodsk. The game turned out to be difficult as hell and most students can't complete the last quest ("We don't go to Nvodsk..."). That threatened winter exams. The rector already started to wonder whether he should postpone the winter exams till April (in fact, he wanted to complete the quest himself). But all of a sudden a stranger appeared at the door of his office. "Good afternoon. My name is Chuck and I solve any problems" — he said.
And here they are sitting side by side but still they can't complete the mission. The thing is, to kill the final boss one should prove one's perfect skills in the art of managing letters. One should be a real magician to do that. And can you imagine what happens when magicians start competing...
But let's put it more formally: you are given a string and a set of integers *a**i*. You are allowed to choose any substring that is a palindrome and delete it. At that we receive some number of points equal to *a**k*, where *k* is the length of the deleted palindrome. For some *k*, *a**k*<==<=-1, which means that deleting palindrome strings of such length is forbidden. After a substring is deleted, the remaining part "shifts together", that is, at no moment of time the string has gaps. The process is repeated while the string has at least one palindrome substring that can be deleted. All gained points are summed up.
Determine what maximum number of points can be earned.
"Oh" — said Chuck, raising from the chair, — "I used to love deleting palindromes, just like you, but one day I took an arrow in the Knee". | The first line contains an integer *l* (1<=≤<=*l*<=≤<=150) — the length of the string.
The second line contains exactly *l* integers *a**k* (<=-<=1<=≤<=*a**k*<=≤<=105) — the points a player gains for deleting.
The third line contains exactly *l* lowercase Latin letters — the original string from which a player can delete palindromes. The line contains no other characters apart from the newline character at the end of the string. | Print a single number — the maximum number of points one can gain if he plays on the given string. | [
"7\n-1 -1 -1 -1 -1 -1 -1\nabacaba\n",
"7\n1 -1 -1 -1 -1 -1 -1\nabacaba\n",
"7\n1 5 -1 -1 -1 -1 10\nabacaba\n"
] | [
"0\n",
"7\n",
"16\n"
] | In the first sample we cannot delete any substring, so the best result is 0. In the second sample we are allowed to delete only those palindromes whose length equals 1, thus, if we delete the whole string, we get 7 points. In the third sample the optimal strategy is: first we delete character c, then string aa, then bb, and the last one aa. At that we get 1 + 3 * 5 = 16 points. | [] | 92 | 0 | 0 | 576,509 |
|
292 | Beautiful IP Addresses | [
"brute force"
] | null | null | The problem uses a simplified TCP/IP address model, please read the statement carefully.
An IP address is a 32-bit integer, represented as a group of four decimal 8-bit integers (without leading zeroes), separated by commas. For example, record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In the given problem an arbitrary group of four 8-bit integers is a correct IP address.
Our hero Polycarpus still works as a system administrator in some large corporation. He likes beautiful IP addresses. To check if some IP address is beautiful, he should do the following:
1. write out in a line four 8-bit numbers of the IP address, without the commas; 1. check if the resulting string is a palindrome.
Let us remind you that a palindrome is a string that reads the same from right to left and from left to right.
For example, IP addresses 12.102.20.121 and 0.3.14.130 are beautiful (as strings "1210220121" and "0314130" are palindromes), and IP addresses 1.20.20.1 and 100.4.4.1 are not.
Polycarpus wants to find all beautiful IP addresses that have the given set of digits. Each digit from the set must occur in the IP address at least once. IP address must not contain any other digits. Help him to cope with this difficult task. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=10) — the number of digits in the set. The second line contains the set of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=9). It is guaranteed that all digits in the set are distinct. | In the first line print a single integer *k* — the number of beautiful IP addresses that contain the given set of digits. In the following *k* lines print the IP addresses, one per line in the arbitrary order. | [
"6\n0 1 2 9 8 7\n",
"1\n4\n"
] | [
"6\n78.190.209.187\n79.180.208.197\n87.190.209.178\n89.170.207.198\n97.180.208.179\n98.170.207.189\n",
"16\n4.4.4.4\n4.4.4.44\n4.4.44.4\n4.4.44.44\n4.44.4.4\n4.44.4.44\n4.44.44.4\n4.44.44.44\n44.4.4.4\n44.4.4.44\n44.4.44.4\n44.4.44.44\n44.44.4.4\n44.44.4.44\n44.44.44.4\n44.44.44.44\n"
] | none | [
{
"input": "6\n0 1 2 9 8 7",
"output": "6\n78.190.209.187\n79.180.208.197\n87.190.209.178\n89.170.207.198\n97.180.208.179\n98.170.207.189"
},
{
"input": "1\n4",
"output": "16\n4.4.4.4\n4.4.4.44\n4.4.44.4\n4.4.44.44\n4.44.4.4\n4.44.4.44\n4.44.44.4\n4.44.44.44\n44.4.4.4\n44.4.4.44\n44.4.44.4\n44.4.44.44\n44.44.4.4\n44.44.4.44\n44.44.44.4\n44.44.44.44"
},
{
"input": "1\n0",
"output": "1\n0.0.0.0"
},
{
"input": "6\n9 2 3 0 5 1",
"output": "20\n35.190.209.153\n35.209.190.253\n39.105.250.193\n39.150.205.193\n50.193.239.105\n50.239.193.205\n53.190.209.135\n53.209.190.235\n59.103.230.195\n59.130.203.195\n90.135.253.109\n90.153.235.109\n90.235.153.209\n90.253.135.209\n93.105.250.139\n93.150.205.139\n93.205.150.239\n93.250.105.239\n95.103.230.159\n95.130.203.159"
},
{
"input": "2\n0 1",
"output": "231\n0.1.1.0\n1.0.0.1\n0.1.0.10\n0.1.1.10\n1.1.0.11\n0.0.1.100\n0.1.1.110\n1.0.1.101\n0.0.10.0\n0.1.11.0\n1.0.10.1\n0.1.11.10\n0.0.10.100\n0.0.11.100\n0.1.10.110\n0.1.11.110\n1.0.10.101\n1.0.11.101\n1.1.10.111\n0.0.110.0\n0.1.111.0\n1.0.110.1\n0.1.101.10\n0.1.111.10\n1.1.101.11\n0.0.100.100\n0.0.111.100\n0.1.100.110\n0.1.111.110\n1.0.100.101\n1.0.111.101\n1.1.100.111\n0.10.1.0\n0.11.1.0\n1.10.1.1\n0.10.0.10\n0.11.1.10\n1.10.0.11\n0.11.0.110\n0.11.1.110\n1.11.0.111\n0.11.11.0\n0.10.10.10\n0.11.11.10\n1.10.1..."
},
{
"input": "2\n1 2",
"output": "1666\n1.2.2.1\n2.1.1.2\n1.1.2.11\n1.2.1.21\n1.2.2.21\n2.1.1.12\n2.1.2.12\n2.2.1.22\n1.1.2.211\n1.2.1.121\n1.2.2.221\n2.1.1.112\n2.1.2.212\n2.2.1.122\n1.1.21.1\n1.2.12.1\n1.2.22.1\n2.1.11.2\n2.1.21.2\n2.2.12.2\n1.1.22.11\n1.2.11.21\n1.2.22.21\n2.1.11.12\n2.1.22.12\n2.2.11.22\n1.1.12.111\n1.1.21.211\n1.1.22.211\n1.2.11.121\n1.2.12.121\n1.2.21.221\n1.2.22.221\n2.1.11.112\n2.1.12.112\n2.1.21.212\n2.1.22.212\n2.2.11.122\n2.2.12.122\n2.2.21.222\n1.1.221.1\n1.2.112.1\n1.2.222.1\n2.1.111.2\n2.1.221.2\n2.2.112.2\n1..."
},
{
"input": "5\n1 2 3 4 5",
"output": "816\n3.41.252.143\n3.42.151.243\n3.51.242.153\n3.52.141.253\n4.31.252.134\n4.32.151.234\n4.51.232.154\n4.52.131.254\n5.31.242.135\n5.32.141.235\n5.41.232.145\n5.42.131.245\n3.124.54.213\n3.125.45.213\n3.214.54.123\n3.215.45.123\n4.123.53.214\n4.125.35.214\n4.213.53.124\n4.215.35.124\n5.123.43.215\n5.124.34.215\n5.213.43.125\n5.214.34.125\n3.145.254.13\n3.154.245.13\n3.245.154.23\n3.254.145.23\n4.135.253.14\n4.153.235.14\n4.235.153.24\n4.253.135.24\n5.134.243.15\n5.143.234.15\n5.234.143.25\n5.243.134.25\n34..."
},
{
"input": "10\n0 1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "2\n0 3",
"output": "30\n0.3.3.0\n3.0.0.3\n0.3.0.30\n0.3.3.30\n3.3.0.33\n0.0.30.0\n0.3.33.0\n3.0.30.3\n0.3.33.30\n0.30.3.0\n0.33.3.0\n3.30.3.3\n0.30.0.30\n0.33.3.30\n3.30.0.33\n0.33.33.0\n0.30.30.30\n0.33.33.30\n3.30.30.33\n30.0.0.3\n30.3.0.3\n33.0.3.3\n33.0.0.33\n30.3.30.3\n33.0.30.33\n30.33.0.3\n33.30.3.33\n30.30.30.3\n30.33.30.3\n33.30.33.3"
},
{
"input": "2\n6 1",
"output": "591\n1.6.6.1\n6.1.1.6\n1.1.6.11\n1.6.1.61\n1.6.6.61\n6.1.1.16\n6.1.6.16\n6.6.1.66\n1.6.1.161\n6.1.1.116\n6.6.1.166\n1.1.61.1\n1.6.16.1\n1.6.66.1\n6.1.11.6\n6.1.61.6\n6.6.16.6\n1.1.66.11\n1.6.11.61\n1.6.66.61\n6.1.11.16\n6.1.66.16\n6.6.11.66\n1.1.16.111\n1.6.11.161\n1.6.16.161\n6.1.11.116\n6.1.16.116\n6.6.11.166\n6.6.16.166\n1.6.116.1\n6.1.111.6\n6.6.116.6\n1.1.161.11\n1.6.111.61\n1.6.161.61\n6.1.111.16\n6.1.161.16\n6.6.111.66\n6.6.161.66\n1.1.166.111\n1.6.111.161\n1.6.166.161\n6.1.111.116\n6.1.166.116\n6.6..."
},
{
"input": "2\n2 1",
"output": "1666\n1.2.2.1\n2.1.1.2\n1.1.2.11\n1.2.1.21\n1.2.2.21\n2.1.1.12\n2.1.2.12\n2.2.1.22\n1.1.2.211\n1.2.1.121\n1.2.2.221\n2.1.1.112\n2.1.2.212\n2.2.1.122\n1.1.21.1\n1.2.12.1\n1.2.22.1\n2.1.11.2\n2.1.21.2\n2.2.12.2\n1.1.22.11\n1.2.11.21\n1.2.22.21\n2.1.11.12\n2.1.22.12\n2.2.11.22\n1.1.12.111\n1.1.21.211\n1.1.22.211\n1.2.11.121\n1.2.12.121\n1.2.21.221\n1.2.22.221\n2.1.11.112\n2.1.12.112\n2.1.21.212\n2.1.22.212\n2.2.11.122\n2.2.12.122\n2.2.21.222\n1.1.221.1\n1.2.112.1\n1.2.222.1\n2.1.111.2\n2.1.221.2\n2.2.112.2\n1..."
},
{
"input": "3\n2 6 3",
"output": "698\n2.3.6.32\n2.6.3.62\n3.2.6.23\n3.6.2.63\n6.2.3.26\n6.3.2.36\n6.3.2.236\n2.3.63.2\n2.6.36.2\n3.2.62.3\n3.6.26.3\n6.2.32.6\n6.3.23.6\n2.3.66.32\n2.6.33.62\n3.2.66.23\n3.6.22.63\n6.2.33.26\n6.3.22.36\n2.3.26.232\n3.2.26.223\n3.3.26.233\n6.2.23.226\n6.3.22.236\n6.3.23.236\n6.3.26.236\n3.6.226.3\n6.3.223.6\n2.6.232.62\n3.6.222.63\n3.6.232.63\n6.2.232.26\n6.3.222.36\n6.3.232.36\n6.6.232.66\n6.2.233.226\n6.3.222.236\n6.3.233.236\n2.36.3.2\n2.63.6.2\n3.26.2.3\n3.62.6.3\n6.23.2.6\n6.32.3.6\n2.36.6.32\n2.63.3.62..."
},
{
"input": "3\n7 3 8",
"output": "240\n3.7.8.73\n3.8.7.83\n7.3.8.37\n7.8.3.87\n8.3.7.38\n8.7.3.78\n3.7.87.3\n3.8.78.3\n7.3.83.7\n7.8.38.7\n8.3.73.8\n8.7.37.8\n3.7.88.73\n3.8.77.83\n7.3.88.37\n7.8.33.87\n8.3.77.38\n8.7.33.78\n3.78.7.3\n3.87.8.3\n7.38.3.7\n7.83.8.7\n8.37.3.8\n8.73.7.8\n3.78.8.73\n3.87.7.83\n7.38.8.37\n7.83.3.87\n8.37.7.38\n8.73.3.78\n3.78.87.3\n3.87.78.3\n7.38.83.7\n7.83.38.7\n8.37.73.8\n8.73.37.8\n3.37.87.33\n3.38.78.33\n3.73.83.73\n3.77.87.73\n3.78.38.73\n3.78.78.73\n3.78.88.73\n3.83.73.83\n3.87.37.83\n3.87.77.83\n3.87.87...."
},
{
"input": "3\n5 6 7",
"output": "240\n5.6.7.65\n5.7.6.75\n6.5.7.56\n6.7.5.76\n7.5.6.57\n7.6.5.67\n5.6.76.5\n5.7.67.5\n6.5.75.6\n6.7.57.6\n7.5.65.7\n7.6.56.7\n5.6.77.65\n5.7.66.75\n6.5.77.56\n6.7.55.76\n7.5.66.57\n7.6.55.67\n5.67.6.5\n5.76.7.5\n6.57.5.6\n6.75.7.6\n7.56.5.7\n7.65.6.7\n5.67.7.65\n5.76.6.75\n6.57.7.56\n6.75.5.76\n7.56.6.57\n7.65.5.67\n5.67.76.5\n5.76.67.5\n6.57.75.6\n6.75.57.6\n7.56.65.7\n7.65.56.7\n5.56.76.55\n5.57.67.55\n5.65.75.65\n5.66.76.65\n5.67.57.65\n5.67.67.65\n5.67.77.65\n5.75.65.75\n5.76.56.75\n5.76.66.75\n5.76.76...."
},
{
"input": "4\n2 6 7 1",
"output": "1362\n2.6.17.162\n2.7.16.172\n6.1.27.216\n6.2.17.126\n6.7.12.176\n7.1.26.217\n7.2.16.127\n7.6.12.167\n2.6.171.62\n2.7.161.72\n6.2.171.26\n6.7.121.76\n6.7.212.76\n7.2.161.27\n7.6.121.67\n7.6.212.67\n2.6.177.162\n2.7.166.172\n6.2.177.126\n6.7.122.176\n7.2.166.127\n7.6.122.167\n2.61.7.162\n2.71.6.172\n6.12.7.216\n6.21.7.126\n6.71.2.176\n7.12.6.217\n7.21.6.127\n7.61.2.167\n1.26.76.21\n1.27.67.21\n1.62.72.61\n1.67.27.61\n1.72.62.71\n1.76.26.71\n2.16.76.12\n2.17.67.12\n2.61.71.62\n2.67.17.62\n2.71.61.72\n2.76.16..."
},
{
"input": "4\n2 0 6 4",
"output": "240\n0.4.26.240\n4.0.26.204\n6.0.24.206\n6.4.20.246\n0.6.242.60\n4.6.202.64\n6.4.202.46\n6.0.244.206\n6.4.200.246\n0.42.6.240\n6.42.0.246\n0.24.64.20\n0.26.46.20\n0.42.62.40\n0.46.26.40\n0.62.42.60\n0.64.24.60\n2.40.60.42\n2.60.40.62\n4.20.60.24\n4.60.20.64\n6.20.40.26\n6.40.20.46\n0.42.66.240\n0.64.246.0\n4.60.206.4\n6.40.204.6\n0.46.226.40\n0.64.224.60\n4.60.220.64\n6.40.220.46\n6.42.202.246\n0.246.4.20\n4.206.0.24\n6.204.0.26\n6.240.4.26\n0.246.42.0\n6.240.42.6\n0.246.64.20\n4.206.60.24\n6.204.40.26\n0...."
},
{
"input": "4\n1 8 4 6",
"output": "810\n4.6.18.164\n4.8.16.184\n6.4.18.146\n6.8.14.186\n8.4.16.148\n8.6.14.168\n4.6.181.64\n4.8.161.84\n6.4.181.46\n6.8.141.86\n8.4.161.48\n8.6.141.68\n4.6.188.164\n4.8.166.184\n6.4.188.146\n6.8.144.186\n8.4.166.148\n8.6.144.168\n4.61.8.164\n4.81.6.184\n6.41.8.146\n6.81.4.186\n8.41.6.148\n8.61.4.168\n1.46.86.41\n1.48.68.41\n1.64.84.61\n1.68.48.61\n1.84.64.81\n1.86.46.81\n4.16.86.14\n4.18.68.14\n4.61.81.64\n4.68.18.64\n4.81.61.84\n4.86.16.84\n6.14.84.16\n6.18.48.16\n6.41.81.46\n6.48.18.46\n6.81.41.86\n6.84.14...."
},
{
"input": "5\n4 0 5 6 9",
"output": "0"
},
{
"input": "5\n1 0 2 9 6",
"output": "242\n6.91.202.196\n9.61.202.169\n0.126.96.210\n0.129.69.210\n0.216.96.120\n0.219.69.120\n6.120.90.216\n6.210.90.126\n9.120.60.219\n9.210.60.129\n6.190.209.16\n6.209.190.26\n9.160.206.19\n9.206.160.29\n60.2.191.206\n69.1.202.196\n90.2.161.209\n96.1.202.169\n10.26.96.201\n10.29.69.201\n20.16.96.102\n20.19.69.102\n26.10.90.162\n29.10.60.192\n60.12.92.106\n60.19.29.106\n60.21.91.206\n60.29.19.206\n61.20.90.216\n62.10.90.126\n69.10.20.196\n90.12.62.109\n90.16.26.109\n90.21.61.209\n90.26.16.209\n91.20.60.219\n92..."
},
{
"input": "5\n5 7 3 9 1",
"output": "168\n35.17.97.153\n35.19.79.153\n37.15.95.173\n37.19.59.173\n39.15.75.193\n39.17.57.193\n53.17.97.135\n53.19.79.135\n57.13.93.175\n57.19.39.175\n59.13.73.195\n59.17.37.195\n73.15.95.137\n73.19.59.137\n75.13.93.157\n75.19.39.157\n79.13.53.197\n79.15.35.197\n93.15.75.139\n93.17.57.139\n95.13.73.159\n95.17.37.159\n97.13.53.179\n97.15.35.179\n35.79.197.53\n35.97.179.53\n37.59.195.73\n37.95.159.73\n39.57.175.93\n39.75.157.93\n53.79.197.35\n53.97.179.35\n57.39.193.75\n57.93.139.75\n59.37.173.95\n59.73.137.95\n73..."
},
{
"input": "6\n0 1 4 7 8 6",
"output": "0"
},
{
"input": "6\n0 8 9 2 4 5",
"output": "0"
},
{
"input": "6\n8 4 6 5 2 0",
"output": "0"
},
{
"input": "7\n7 5 1 8 0 9 2",
"output": "0"
},
{
"input": "7\n3 6 9 5 0 4 7",
"output": "0"
},
{
"input": "8\n2 4 0 1 9 8 6 3",
"output": "0"
},
{
"input": "8\n6 9 1 7 8 2 5 0",
"output": "0"
},
{
"input": "9\n4 0 7 3 9 5 6 8 1",
"output": "0"
},
{
"input": "9\n7 0 6 5 1 3 8 2 4",
"output": "0"
},
{
"input": "1\n6",
"output": "16\n6.6.6.6\n6.6.6.66\n6.6.66.6\n6.6.66.66\n6.66.6.6\n6.66.6.66\n6.66.66.6\n6.66.66.66\n66.6.6.6\n66.6.6.66\n66.6.66.6\n66.6.66.66\n66.66.6.6\n66.66.6.66\n66.66.66.6\n66.66.66.66"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "24\n35.164.246.153\n35.246.164.253\n36.145.254.163\n36.154.245.163\n45.163.236.154\n45.236.163.254\n46.135.253.164\n46.153.235.164\n53.164.246.135\n53.246.164.235\n54.163.236.145\n54.236.163.245\n56.134.243.165\n56.143.234.165\n63.145.254.136\n63.154.245.136\n63.245.154.236\n63.254.145.236\n64.135.253.146\n64.153.235.146\n64.235.153.246\n64.253.135.246\n65.134.243.156\n65.143.234.156"
},
{
"input": "6\n1 2 3 4 5 0",
"output": "36\n30.145.254.103\n30.154.245.103\n30.245.154.203\n30.254.145.203\n34.105.250.143\n34.150.205.143\n34.205.150.243\n34.250.105.243\n35.104.240.153\n35.140.204.153\n35.204.140.253\n35.240.104.253\n40.135.253.104\n40.153.235.104\n40.235.153.204\n40.253.135.204\n43.105.250.134\n43.150.205.134\n43.205.150.234\n43.250.105.234\n45.103.230.154\n45.130.203.154\n45.203.130.254\n45.230.103.254\n50.134.243.105\n50.143.234.105\n50.234.143.205\n50.243.134.205\n53.104.240.135\n53.140.204.135\n53.204.140.235\n53.240.104...."
},
{
"input": "6\n1 4 5 2 7 0",
"output": "20\n45.170.207.154\n45.207.170.254\n47.105.250.174\n47.150.205.174\n50.174.247.105\n50.247.174.205\n54.170.207.145\n54.207.170.245\n57.104.240.175\n57.140.204.175\n70.145.254.107\n70.154.245.107\n70.245.154.207\n70.254.145.207\n74.105.250.147\n74.150.205.147\n74.205.150.247\n74.250.105.247\n75.104.240.157\n75.140.204.157"
},
{
"input": "6\n7 8 9 1 2 3",
"output": "6\n78.193.239.187\n79.183.238.197\n87.193.239.178\n89.173.237.198\n97.183.238.179\n98.173.237.189"
},
{
"input": "6\n6 7 8 2 1 0",
"output": "6\n67.180.208.176\n68.170.207.186\n76.180.208.167\n78.160.206.187\n86.170.207.168\n87.160.206.178"
},
{
"input": "4\n0 1 2 3",
"output": "1556\n0.1.23.210\n0.2.13.120\n0.3.12.130\n0.3.21.230\n1.0.23.201\n1.3.20.231\n2.0.13.102\n2.3.10.132\n3.0.12.103\n3.0.21.203\n3.1.20.213\n3.2.10.123\n0.1.232.10\n0.2.131.20\n0.3.121.30\n0.3.212.30\n1.3.202.31\n2.3.101.32\n3.1.202.13\n3.2.101.23\n0.1.233.210\n0.2.133.120\n0.3.122.130\n0.3.211.230\n1.0.233.201\n1.3.200.231\n2.0.133.102\n2.3.100.132\n3.0.122.103\n3.0.211.203\n3.1.200.213\n3.2.100.123\n0.12.3.210\n0.21.3.120\n0.31.2.130\n0.32.1.230\n1.32.0.231\n2.31.0.132\n3.12.0.213\n3.21.0.123\n0.12.32.10\n0..."
},
{
"input": "4\n0 1 9 8",
"output": "392\n0.8.19.180\n0.9.18.190\n8.0.19.108\n8.9.10.198\n9.0.18.109\n9.8.10.189\n0.8.191.80\n0.9.181.90\n8.9.101.98\n9.8.101.89\n0.8.199.180\n0.9.188.190\n8.0.199.108\n8.9.100.198\n9.0.188.109\n9.8.100.189\n0.81.9.180\n0.91.8.190\n8.91.0.198\n9.81.0.189\n0.18.98.10\n0.19.89.10\n0.81.91.80\n0.89.19.80\n0.91.81.90\n0.98.18.90\n1.80.90.81\n1.90.80.91\n8.10.90.18\n8.90.10.98\n9.10.80.19\n9.80.10.89\n0.81.99.180\n0.91.88.190\n0.89.198.0\n0.98.189.0\n8.90.109.8\n9.80.108.9\n0.89.119.80\n0.98.118.90\n8.90.110.98\n9.8..."
},
{
"input": "5\n0 1 2 3 4",
"output": "496\n0.31.242.130\n0.32.141.230\n0.41.232.140\n0.42.131.240\n3.41.202.143\n3.42.101.243\n4.31.202.134\n4.32.101.234\n0.123.43.210\n0.124.34.210\n0.213.43.120\n0.214.34.120\n3.120.40.213\n3.210.40.123\n4.120.30.214\n4.210.30.124\n0.134.243.10\n0.143.234.10\n0.234.143.20\n0.243.134.20\n3.104.240.13\n3.140.204.13\n3.204.140.23\n3.240.104.23\n4.103.230.14\n4.130.203.14\n4.203.130.24\n4.230.103.24\n30.1.242.103\n30.2.141.203\n34.1.202.143\n34.2.101.243\n40.1.232.104\n40.2.131.204\n43.1.202.134\n43.2.101.234\n10..."
},
{
"input": "4\n9 8 7 6",
"output": "120\n6.78.98.76\n6.79.89.76\n6.87.97.86\n6.89.79.86\n6.97.87.96\n6.98.78.96\n7.68.98.67\n7.69.89.67\n7.86.96.87\n7.89.69.87\n7.96.86.97\n7.98.68.97\n8.67.97.68\n8.69.79.68\n8.76.96.78\n8.79.69.78\n8.96.76.98\n8.97.67.98\n9.67.87.69\n9.68.78.69\n9.76.86.79\n9.78.68.79\n9.86.76.89\n9.87.67.89\n67.8.98.76\n67.9.89.76\n68.7.97.86\n68.9.79.86\n69.7.87.96\n69.8.78.96\n76.8.98.67\n76.9.89.67\n78.6.96.87\n78.9.69.87\n79.6.86.97\n79.8.68.97\n86.7.97.68\n86.9.79.68\n87.6.96.78\n87.9.69.78\n89.6.76.98\n89.7.67.98\n96..."
},
{
"input": "1\n2",
"output": "81\n2.2.2.2\n2.2.2.22\n2.2.2.222\n2.2.22.2\n2.2.22.22\n2.2.22.222\n2.2.222.2\n2.2.222.22\n2.2.222.222\n2.22.2.2\n2.22.2.22\n2.22.2.222\n2.22.22.2\n2.22.22.22\n2.22.22.222\n2.22.222.2\n2.22.222.22\n2.22.222.222\n2.222.2.2\n2.222.2.22\n2.222.2.222\n2.222.22.2\n2.222.22.22\n2.222.22.222\n2.222.222.2\n2.222.222.22\n2.222.222.222\n22.2.2.2\n22.2.2.22\n22.2.2.222\n22.2.22.2\n22.2.22.22\n22.2.22.222\n22.2.222.2\n22.2.222.22\n22.2.222.222\n22.22.2.2\n22.22.2.22\n22.22.2.222\n22.22.22.2\n22.22.22.22\n22.22.22.222\n..."
},
{
"input": "3\n0 1 9",
"output": "524\n0.1.9.10\n0.9.1.90\n1.9.0.91\n9.1.0.19\n0.9.1.190\n9.0.1.109\n0.1.91.0\n0.9.19.0\n1.0.90.1\n9.0.10.9\n0.1.99.10\n0.9.11.90\n0.0.19.100\n0.1.19.110\n0.9.10.190\n0.9.11.190\n0.9.19.190\n1.0.19.101\n1.9.10.191\n9.0.10.109\n9.0.11.109\n9.0.19.109\n9.1.10.119\n9.9.10.199\n0.9.119.0\n9.0.110.9\n0.1.191.10\n0.9.101.90\n0.9.111.90\n0.9.191.90\n1.9.101.91\n9.1.101.19\n9.9.101.99\n0.0.199.100\n0.1.199.110\n0.9.100.190\n0.9.111.190\n0.9.199.190\n1.0.199.101\n1.9.100.191\n9.0.100.109\n9.0.111.109\n9.0.199.109\n9...."
},
{
"input": "3\n0 2 5",
"output": "524\n0.2.5.20\n0.5.2.50\n2.5.0.52\n5.2.0.25\n0.5.2.250\n5.0.2.205\n0.2.52.0\n0.5.25.0\n2.0.50.2\n5.0.20.5\n0.2.55.20\n0.5.22.50\n0.0.25.200\n0.2.25.220\n0.5.20.250\n0.5.22.250\n0.5.25.250\n2.0.25.202\n2.5.20.252\n5.0.20.205\n5.0.22.205\n5.0.25.205\n5.2.20.225\n5.5.20.255\n0.5.225.0\n5.0.220.5\n0.2.252.20\n0.5.202.50\n0.5.222.50\n0.5.252.50\n2.5.202.52\n5.2.202.25\n5.5.202.55\n0.0.255.200\n0.2.255.220\n0.5.200.250\n0.5.222.250\n0.5.255.250\n2.0.255.202\n2.5.200.252\n5.0.200.205\n5.0.222.205\n5.0.255.205\n5...."
},
{
"input": "3\n0 1 2",
"output": "1802\n0.1.2.10\n0.2.1.20\n1.2.0.21\n2.1.0.12\n0.1.2.210\n0.2.1.120\n1.0.2.201\n2.0.1.102\n0.1.21.0\n0.2.12.0\n1.0.20.1\n2.0.10.2\n0.1.22.10\n0.2.11.20\n0.0.12.100\n0.0.21.200\n0.1.12.110\n0.1.20.210\n0.1.21.210\n0.1.22.210\n0.2.10.120\n0.2.11.120\n0.2.12.120\n0.2.21.220\n1.0.12.101\n1.0.20.201\n1.0.21.201\n1.0.22.201\n1.1.20.211\n1.2.10.121\n1.2.20.221\n2.0.10.102\n2.0.11.102\n2.0.12.102\n2.0.21.202\n2.1.10.112\n2.1.20.212\n2.2.10.122\n0.1.221.0\n0.2.112.0\n1.0.220.1\n2.0.110.2\n0.1.121.10\n0.1.202.10\n0.1..."
},
{
"input": "3\n1 2 7",
"output": "2328\n1.2.7.21\n1.7.2.71\n2.1.7.12\n2.7.1.72\n7.1.2.17\n7.2.1.27\n2.7.1.172\n7.1.2.217\n7.2.1.127\n1.2.72.1\n1.7.27.1\n2.1.71.2\n2.7.17.2\n7.1.21.7\n7.2.12.7\n1.2.77.21\n1.7.22.71\n2.1.77.12\n2.7.11.72\n7.1.22.17\n7.2.11.27\n1.1.27.211\n1.2.17.121\n1.2.27.221\n1.7.12.171\n2.1.17.112\n2.1.27.212\n2.2.17.122\n2.7.11.172\n2.7.12.172\n2.7.17.172\n7.1.12.117\n7.1.21.217\n7.1.22.217\n7.1.27.217\n7.2.11.127\n7.2.12.127\n7.2.17.127\n7.2.21.227\n7.7.12.177\n1.7.227.1\n2.7.117.2\n7.1.221.7\n7.2.112.7\n1.2.171.21\n1...."
}
] | 310 | 268,390,400 | 0 | 576,881 |
|
282 | Yet Another Number Game | [
"dp",
"games"
] | null | null | Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.
BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn:
- Take one of the integers (we'll denote it as *a**i*). Choose integer *x* (1<=≤<=*x*<=≤<=*a**i*). And then decrease *a**i* by *x*, that is, apply assignment: *a**i*<==<=*a**i*<=-<=*x*. - Choose integer *x* . And then decrease all *a**i* by *x*, that is, apply assignment: *a**i*<==<=*a**i*<=-<=*x*, for all *i*.
The player who cannot make a move loses.
You're given the initial sequence *a*1,<=*a*2,<=...,<=*a**n*. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=3).
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=300). | Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes). | [
"2\n1 1\n",
"2\n1 2\n",
"3\n1 2 1\n"
] | [
"BitLGM\n",
"BitAryo\n",
"BitLGM\n"
] | none | [
{
"input": "2\n1 1",
"output": "BitLGM"
},
{
"input": "2\n1 2",
"output": "BitAryo"
},
{
"input": "3\n1 2 1",
"output": "BitLGM"
},
{
"input": "2\n1 3",
"output": "BitLGM"
},
{
"input": "2\n3 5",
"output": "BitAryo"
},
{
"input": "2\n9 10",
"output": "BitLGM"
},
{
"input": "2\n6 8",
"output": "BitLGM"
},
{
"input": "3\n0 0 0",
"output": "BitAryo"
},
{
"input": "2\n223 58",
"output": "BitLGM"
},
{
"input": "2\n106 227",
"output": "BitLGM"
},
{
"input": "2\n125 123",
"output": "BitLGM"
},
{
"input": "3\n31 132 7",
"output": "BitLGM"
},
{
"input": "2\n41 29",
"output": "BitLGM"
},
{
"input": "3\n103 286 100",
"output": "BitLGM"
},
{
"input": "3\n9 183 275",
"output": "BitLGM"
},
{
"input": "3\n19 88 202",
"output": "BitLGM"
},
{
"input": "3\n234 44 69",
"output": "BitLGM"
},
{
"input": "3\n244 241 295",
"output": "BitLGM"
},
{
"input": "1\n6",
"output": "BitLGM"
},
{
"input": "1\n231",
"output": "BitLGM"
},
{
"input": "2\n241 289",
"output": "BitLGM"
},
{
"input": "2\n200 185",
"output": "BitLGM"
},
{
"input": "2\n218 142",
"output": "BitLGM"
},
{
"input": "3\n124 47 228",
"output": "BitLGM"
},
{
"input": "3\n134 244 95",
"output": "BitLGM"
},
{
"input": "1\n0",
"output": "BitAryo"
},
{
"input": "1\n10",
"output": "BitLGM"
},
{
"input": "1\n2",
"output": "BitLGM"
},
{
"input": "1\n1",
"output": "BitLGM"
},
{
"input": "1\n99",
"output": "BitLGM"
},
{
"input": "2\n44 27",
"output": "BitAryo"
},
{
"input": "2\n280 173",
"output": "BitAryo"
},
{
"input": "2\n29 47",
"output": "BitAryo"
},
{
"input": "2\n16 26",
"output": "BitAryo"
},
{
"input": "2\n58 94",
"output": "BitAryo"
},
{
"input": "2\n17 28",
"output": "BitAryo"
},
{
"input": "2\n59 96",
"output": "BitAryo"
},
{
"input": "2\n164 101",
"output": "BitAryo"
},
{
"input": "2\n143 88",
"output": "BitAryo"
},
{
"input": "2\n69 112",
"output": "BitAryo"
},
{
"input": "2\n180 111",
"output": "BitAryo"
},
{
"input": "2\n159 98",
"output": "BitAryo"
},
{
"input": "2\n183 113",
"output": "BitAryo"
},
{
"input": "2\n162 100",
"output": "BitAryo"
},
{
"input": "2\n230 142",
"output": "BitAryo"
},
{
"input": "2\n298 184",
"output": "BitAryo"
},
{
"input": "2\n144 233",
"output": "BitAryo"
},
{
"input": "2\n0 0",
"output": "BitAryo"
},
{
"input": "2\n173 280",
"output": "BitAryo"
},
{
"input": "2\n180 111",
"output": "BitAryo"
},
{
"input": "2\n251 155",
"output": "BitAryo"
},
{
"input": "2\n114 185",
"output": "BitAryo"
},
{
"input": "2\n156 253",
"output": "BitAryo"
},
{
"input": "2\n144 233",
"output": "BitAryo"
},
{
"input": "2\n0 0",
"output": "BitAryo"
},
{
"input": "2\n14 23",
"output": "BitAryo"
},
{
"input": "2\n2 1",
"output": "BitAryo"
},
{
"input": "2\n70 43",
"output": "BitAryo"
},
{
"input": "2\n49 30",
"output": "BitAryo"
},
{
"input": "2\n150 243",
"output": "BitAryo"
},
{
"input": "2\n6 10",
"output": "BitAryo"
},
{
"input": "2\n152 246",
"output": "BitAryo"
},
{
"input": "2\n13 8",
"output": "BitAryo"
},
{
"input": "2\n293 181",
"output": "BitAryo"
},
{
"input": "2\n15 9",
"output": "BitAryo"
},
{
"input": "2\n295 182",
"output": "BitAryo"
},
{
"input": "2\n62 38",
"output": "BitAryo"
},
{
"input": "2\n80 130",
"output": "BitAryo"
},
{
"input": "2\n40 65",
"output": "BitAryo"
},
{
"input": "1\n248",
"output": "BitLGM"
},
{
"input": "1\n10",
"output": "BitLGM"
},
{
"input": "2\n216 91",
"output": "BitLGM"
},
{
"input": "1\n234",
"output": "BitLGM"
},
{
"input": "2\n140 193",
"output": "BitLGM"
},
{
"input": "3\n151 97 120",
"output": "BitLGM"
},
{
"input": "1\n213",
"output": "BitLGM"
},
{
"input": "3\n119 251 222",
"output": "BitLGM"
},
{
"input": "3\n129 148 141",
"output": "BitLGM"
},
{
"input": "1\n147",
"output": "BitLGM"
},
{
"input": "2\n124 194",
"output": "BitLGM"
},
{
"input": "3\n184 222 102",
"output": "BitAryo"
},
{
"input": "3\n101 186 223",
"output": "BitAryo"
},
{
"input": "3\n0 87 87",
"output": "BitAryo"
},
{
"input": "3\n144 33 177",
"output": "BitAryo"
},
{
"input": "3\n49 252 205",
"output": "BitAryo"
},
{
"input": "3\n49 126 79",
"output": "BitAryo"
},
{
"input": "3\n152 66 218",
"output": "BitAryo"
},
{
"input": "3\n181 232 93",
"output": "BitAryo"
},
{
"input": "3\n15 150 153",
"output": "BitAryo"
},
{
"input": "3\n191 50 141",
"output": "BitAryo"
},
{
"input": "3\n162 230 68",
"output": "BitAryo"
},
{
"input": "3\n4 19 23",
"output": "BitAryo"
},
{
"input": "3\n222 129 95",
"output": "BitAryo"
},
{
"input": "3\n38 16 54",
"output": "BitAryo"
},
{
"input": "3\n254 227 29",
"output": "BitAryo"
},
{
"input": "3\n196 45 233",
"output": "BitAryo"
},
{
"input": "3\n70 45 107",
"output": "BitAryo"
},
{
"input": "3\n190 61 131",
"output": "BitAryo"
},
{
"input": "3\n0 173 173",
"output": "BitAryo"
},
{
"input": "3\n50 69 119",
"output": "BitAryo"
},
{
"input": "1\n108",
"output": "BitLGM"
},
{
"input": "1\n15",
"output": "BitLGM"
},
{
"input": "1\n85",
"output": "BitLGM"
},
{
"input": "1\n291",
"output": "BitLGM"
},
{
"input": "1\n1",
"output": "BitLGM"
},
{
"input": "2\n11 222",
"output": "BitLGM"
},
{
"input": "2\n218 127",
"output": "BitLGM"
},
{
"input": "2\n280 24",
"output": "BitLGM"
},
{
"input": "2\n298 281",
"output": "BitLGM"
},
{
"input": "3\n275 70 60",
"output": "BitLGM"
},
{
"input": "3\n299 299 298",
"output": "BitLGM"
},
{
"input": "3\n299 299 299",
"output": "BitLGM"
},
{
"input": "3\n299 299 299",
"output": "BitLGM"
},
{
"input": "2\n298 299",
"output": "BitLGM"
},
{
"input": "2\n299 299",
"output": "BitLGM"
},
{
"input": "1\n299",
"output": "BitLGM"
},
{
"input": "3\n299 290 288",
"output": "BitLGM"
}
] | 1,058 | 3,993,600 | 3 | 579,295 |
|
730 | Award Ceremony | [
"greedy",
"implementation"
] | null | null | All-Berland programming contest comes to an end. In total, *n* teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team the value *a**i* is given — the number of points the *i*-th team has earned before the last hour of the contest. Besides that, the Jury has evaluated all submissions sent during the last hour and knows values *d**i* — the number of points earned by the *i*-th team during the last hour (these values can be negative, which means that a team can lose points).
Before the contest, each team got unique id from 1 to *n*. According to the contest rules, a team with more points takes a higher place. If two or more teams have equal number of points, the team with lower id will take the higher place. So no two teams can share the same place.
The Award Ceremony proceeds in the following way. At the beginning of the ceremony, a large screen shows the results for the time moment "one hour before the end", which means that the *i*-th team has *a**i* points. Then the Jury unfreezes results of the teams one by one in some order. When result of the *j*-th team is unfrozen, its score changes from *a**j* to *a**j*<=+<=*d**j*. At this time the table of results is modified and the place of the team can change. The unfreezing of the *j*-th team is followed by the applause from the audience with duration of |*x**j*<=-<=*y**j*| seconds, where *x**j* is the place of the *j*-th team before unfreezing and *y**j* is the place right after the unfreezing. For example, if the team does not change the place, there is no applause from the audience. As you can see, during the Award Ceremony, each team will be unfrozen exactly once.
Your task is to find such an order to unfreeze all the teams that the total duration of applause is maximum possible. | The first line of the input file contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of teams.
Each of the next *n* lines contains two integers *a**i* and *d**i* (1<=≤<=*a**i*<=≤<=100, <=-<=100<=≤<=*d**i*<=≤<=100) — the number of points the *i*-th team has earned before the last hour of the contest and the number of points earned by this team during the last hour. It is possible that after unfreezing a team will have a negative score. | Print the only integer — maximal total applause duration in seconds if the Jury can choose any order of the teams to unfreeze. | [
"4\n17 -14\n52 -5\n1 52\n6 0\n",
"5\n4 5\n3 2\n5 -3\n6 -2\n4 3\n"
] | [
"4\n",
"14\n"
] | In the first example the initial standings are:
1. Team 2, 52 points 1. Team 1, 17 points 1. Team 4, 6 points 1. Team 3, 1 point
Here any order of unfreezing the teams leads to 4 seconds of applause in total. For example, let's unfreeze teams in their order from the Team 1 to the Team 4.
After the Team 1 became unfrozen the standings are:
1. Team 2, 52 points 1. Team 4, 6 points 1. Team 1, 3 points 1. Team 3, 1 point
So there is 1 second of applause, because the difference between old and new places |2 - 3| = 1.
After the Team 2 became unfrozen the standings are:
1. Team 2, 47 points 1. Team 4, 6 points 1. Team 1, 3 points 1. Team 3, 1 point
The place of the Team 2 has not changed, so no applause during unfreezing.
After the Team 3 became unfrozen the standings are:
1. Team 3, 53 point 1. Team 2, 47 points 1. Team 4, 6 points 1. Team 1, 3 points
The place of the Team 3 has changed from 4 to 1, so the duration of applause is |4 - 1| = 3.
The unfreezing of the Team 4 has not changed any place because *d*<sub class="lower-index">4</sub> = 0.
Therefore, the total duration of applause is 1 + 0 + 3 + 0 = 4 seconds. | [
{
"input": "4\n17 -14\n52 -5\n1 52\n6 0",
"output": "4"
},
{
"input": "5\n4 5\n3 2\n5 -3\n6 -2\n4 3",
"output": "14"
},
{
"input": "3\n2 1\n1 -1\n1 2",
"output": "3"
},
{
"input": "5\n4 1\n5 4\n3 5\n4 5\n5 2",
"output": "16"
},
{
"input": "10\n3 3\n1 1\n1 2\n2 2\n3 4\n3 2\n4 3\n2 2\n2 2\n1 2",
"output": "62"
},
{
"input": "20\n5 4\n1 5\n5 4\n4 5\n4 5\n1 1\n5 3\n3 3\n4 5\n1 4\n5 2\n4 2\n4 4\n5 1\n1 1\n5 3\n2 4\n2 4\n1 2\n2 3",
"output": "259"
},
{
"input": "40\n5 4\n1 4\n5 1\n3 4\n1 4\n5 4\n5 1\n2 2\n4 1\n5 3\n3 1\n4 4\n4 5\n1 1\n2 1\n5 2\n2 1\n3 1\n3 3\n3 2\n1 3\n3 5\n4 5\n5 5\n3 2\n3 1\n4 5\n4 1\n3 3\n3 5\n3 2\n5 1\n1 2\n1 5\n5 1\n5 4\n5 2\n3 2\n3 4\n1 1",
"output": "891"
},
{
"input": "60\n4 3\n4 4\n4 5\n2 2\n5 3\n3 5\n2 1\n1 1\n4 1\n4 4\n3 1\n1 3\n5 3\n4 3\n4 3\n3 2\n2 2\n3 2\n1 5\n1 4\n5 2\n3 5\n1 2\n3 2\n2 2\n2 3\n5 4\n5 1\n1 1\n1 5\n2 4\n3 4\n5 1\n4 3\n4 5\n2 4\n4 3\n3 4\n1 5\n2 2\n4 5\n1 3\n1 2\n5 2\n1 2\n3 4\n3 4\n2 1\n3 1\n2 2\n1 4\n2 4\n4 4\n3 1\n4 3\n5 5\n3 5\n1 2\n1 4\n5 1",
"output": "2216"
},
{
"input": "80\n3 3\n5 3\n2 5\n2 1\n3 4\n2 4\n4 2\n4 5\n3 1\n1 4\n5 2\n4 3\n5 2\n3 5\n2 3\n1 3\n3 3\n5 3\n4 2\n2 1\n2 2\n2 2\n4 1\n3 2\n1 4\n1 3\n3 1\n4 1\n1 1\n1 4\n3 1\n5 4\n2 3\n4 3\n3 4\n1 5\n1 5\n1 5\n3 3\n1 4\n1 2\n4 1\n1 1\n3 1\n5 3\n2 2\n1 1\n5 3\n3 5\n4 3\n2 5\n1 2\n1 5\n1 3\n1 5\n3 2\n1 1\n4 1\n3 5\n3 1\n2 1\n3 1\n2 4\n1 2\n2 1\n2 3\n3 2\n2 1\n1 3\n2 5\n2 4\n4 2\n5 5\n4 2\n3 1\n5 2\n3 2\n3 3\n4 1\n2 4",
"output": "3879"
},
{
"input": "100\n5 4\n2 5\n3 1\n3 3\n3 3\n2 5\n2 5\n5 2\n2 3\n3 3\n4 1\n2 4\n2 2\n4 5\n2 5\n3 3\n5 3\n5 3\n3 2\n1 1\n3 1\n4 5\n2 1\n5 5\n4 1\n3 1\n4 5\n3 3\n1 2\n3 1\n4 4\n2 3\n5 5\n1 4\n4 3\n1 5\n1 5\n3 5\n5 4\n5 3\n1 5\n1 5\n4 3\n3 1\n3 2\n3 1\n3 5\n2 3\n4 5\n2 4\n4 3\n3 4\n2 5\n3 4\n5 3\n5 2\n5 1\n1 2\n3 5\n2 2\n1 4\n2 4\n4 5\n5 5\n3 4\n1 2\n1 2\n2 1\n1 1\n3 4\n2 2\n2 1\n1 5\n1 3\n2 3\n2 2\n3 2\n5 3\n3 5\n1 5\n2 3\n1 4\n2 1\n5 1\n2 4\n2 4\n1 4\n1 3\n3 4\n4 3\n3 4\n5 2\n3 3\n1 3\n5 4\n5 1\n2 2\n5 2\n1 1\n5 3",
"output": "6539"
},
{
"input": "100\n5 5\n5 3\n3 4\n2 3\n4 3\n3 5\n2 1\n1 4\n1 1\n5 5\n2 5\n2 4\n4 2\n5 5\n3 2\n4 4\n1 2\n1 2\n2 5\n2 2\n1 3\n5 4\n4 3\n5 3\n5 1\n1 3\n3 1\n4 5\n5 4\n4 5\n4 4\n3 2\n5 3\n4 1\n5 4\n2 2\n1 2\n4 3\n2 4\n1 5\n4 2\n3 5\n1 2\n3 2\n5 1\n1 2\n1 1\n5 4\n1 2\n2 2\n2 3\n4 4\n3 4\n1 2\n5 1\n2 2\n4 5\n3 3\n4 2\n4 2\n4 1\n3 5\n2 4\n5 2\n4 3\n2 1\n3 3\n5 1\n1 4\n5 5\n2 4\n3 1\n2 1\n4 5\n3 3\n4 3\n5 2\n2 3\n4 5\n1 4\n2 2\n2 4\n5 3\n2 3\n1 2\n2 3\n3 5\n3 2\n3 3\n1 5\n1 5\n3 4\n1 4\n5 1\n1 5\n1 4\n2 5\n1 4\n1 2\n4 1",
"output": "6463"
},
{
"input": "5\n4 -5\n5 -2\n3 -1\n4 -1\n5 -4",
"output": "14"
},
{
"input": "10\n3 -3\n1 -5\n1 -4\n2 -4\n3 -2\n3 -4\n4 -3\n2 -4\n2 -4\n1 -4",
"output": "82"
},
{
"input": "20\n5 -2\n1 -1\n5 -2\n4 -1\n4 -1\n1 -5\n5 -3\n3 -3\n4 -1\n1 -2\n5 -4\n4 -4\n4 -2\n5 -5\n1 -5\n5 -3\n2 -2\n2 -2\n1 -4\n2 -3",
"output": "209"
},
{
"input": "40\n5 -2\n1 -2\n5 -5\n3 -2\n1 -2\n5 -2\n5 -5\n2 -4\n4 -5\n5 -3\n3 -5\n4 -2\n4 -1\n1 -5\n2 -5\n5 -4\n2 -5\n3 -5\n3 -3\n3 -4\n1 -3\n3 -1\n4 -1\n5 -1\n3 -4\n3 -5\n4 -1\n4 -5\n3 -3\n3 -1\n3 -4\n5 -5\n1 -4\n1 -1\n5 -5\n5 -2\n5 -4\n3 -4\n3 -2\n1 -5",
"output": "1015"
},
{
"input": "60\n4 -3\n4 -2\n4 -1\n2 -4\n5 -3\n3 -1\n2 -5\n1 -5\n4 -5\n4 -2\n3 -5\n1 -3\n5 -3\n4 -3\n4 -3\n3 -4\n2 -4\n3 -4\n1 -1\n1 -2\n5 -4\n3 -1\n1 -4\n3 -4\n2 -4\n2 -3\n5 -2\n5 -5\n1 -5\n1 -1\n2 -2\n3 -2\n5 -5\n4 -3\n4 -1\n2 -2\n4 -3\n3 -2\n1 -1\n2 -4\n4 -1\n1 -3\n1 -4\n5 -4\n1 -4\n3 -2\n3 -2\n2 -5\n3 -5\n2 -4\n1 -2\n2 -2\n4 -2\n3 -5\n4 -3\n5 -1\n3 -1\n1 -4\n1 -2\n5 -5",
"output": "2272"
},
{
"input": "80\n3 -3\n5 -3\n2 -1\n2 -5\n3 -2\n2 -2\n4 -4\n4 -1\n3 -5\n1 -2\n5 -4\n4 -3\n5 -4\n3 -1\n2 -3\n1 -3\n3 -3\n5 -3\n4 -4\n2 -5\n2 -4\n2 -4\n4 -5\n3 -4\n1 -2\n1 -3\n3 -5\n4 -5\n1 -5\n1 -2\n3 -5\n5 -2\n2 -3\n4 -3\n3 -2\n1 -1\n1 -1\n1 -1\n3 -3\n1 -2\n1 -4\n4 -5\n1 -5\n3 -5\n5 -3\n2 -4\n1 -5\n5 -3\n3 -1\n4 -3\n2 -1\n1 -4\n1 -1\n1 -3\n1 -1\n3 -4\n1 -5\n4 -5\n3 -1\n3 -5\n2 -5\n3 -5\n2 -2\n1 -4\n2 -5\n2 -3\n3 -4\n2 -5\n1 -3\n2 -1\n2 -2\n4 -4\n5 -1\n4 -4\n3 -5\n5 -4\n3 -4\n3 -3\n4 -5\n2 -2",
"output": "4377"
},
{
"input": "5\n4 1\n5 -2\n3 -1\n4 4\n5 5",
"output": "8"
},
{
"input": "10\n3 -3\n1 -2\n1 4\n2 -5\n3 -2\n3 -4\n4 1\n2 1\n2 -4\n1 -5",
"output": "47"
},
{
"input": "20\n5 1\n1 -3\n5 2\n4 -5\n4 -2\n1 -2\n5 3\n3 2\n4 -2\n1 3\n5 1\n4 -3\n4 3\n5 -1\n1 4\n5 2\n2 -5\n2 -2\n1 -5\n2 -1",
"output": "131"
},
{
"input": "40\n5 4\n1 0\n5 4\n3 -1\n1 -1\n5 -1\n5 3\n2 -5\n4 1\n5 1\n3 -4\n4 1\n4 1\n1 3\n2 2\n5 4\n2 2\n3 2\n3 4\n3 5\n1 2\n3 2\n4 0\n5 1\n3 -3\n3 0\n4 -1\n4 -4\n3 -2\n3 -4\n3 5\n5 4\n1 -4\n1 -5\n5 0\n5 -3\n5 -2\n3 3\n3 -1\n1 1",
"output": "501"
},
{
"input": "60\n4 4\n4 4\n4 -3\n2 2\n5 3\n3 -1\n2 -4\n1 -1\n4 3\n4 4\n3 -5\n1 1\n5 4\n4 -1\n4 4\n3 -4\n2 -4\n3 5\n1 3\n1 -2\n5 1\n3 0\n1 3\n3 -2\n2 2\n2 -3\n5 1\n5 -4\n1 -4\n1 -3\n2 2\n3 2\n5 -4\n4 -1\n4 4\n2 5\n4 -5\n3 5\n1 -1\n2 -2\n4 1\n1 0\n1 0\n5 0\n1 -2\n3 5\n3 -5\n2 5\n3 -3\n2 3\n1 2\n2 -3\n4 3\n3 -4\n4 -4\n5 5\n3 -2\n1 3\n1 -2\n5 -2",
"output": "1347"
},
{
"input": "80\n3 -4\n5 4\n2 5\n2 -5\n3 -4\n2 4\n4 1\n4 3\n3 5\n1 3\n5 -3\n4 2\n5 -5\n3 -5\n2 2\n1 1\n3 -1\n5 5\n4 2\n2 2\n2 4\n2 2\n4 -1\n3 -5\n1 1\n1 0\n3 -1\n4 5\n1 -2\n1 5\n3 2\n5 -5\n2 2\n4 -5\n3 0\n1 3\n1 -1\n1 3\n3 -5\n1 -1\n1 -3\n4 -2\n1 2\n3 4\n5 1\n2 5\n1 5\n5 3\n3 -1\n4 -4\n2 -2\n1 -5\n1 -3\n1 -2\n1 -3\n3 1\n1 -5\n4 -3\n3 2\n3 3\n2 -4\n3 -3\n2 4\n1 1\n2 0\n2 4\n3 0\n2 -2\n1 -1\n2 -4\n2 -3\n4 5\n5 1\n4 -5\n3 2\n5 4\n3 3\n3 0\n4 5\n2 2",
"output": "2580"
},
{
"input": "10\n10 1\n9 2\n8 3\n7 4\n6 5\n5 6\n4 7\n3 8\n2 9\n1 10",
"output": "90"
},
{
"input": "50\n50 1\n49 2\n48 3\n47 4\n46 5\n45 6\n44 7\n43 8\n42 9\n41 10\n40 11\n39 12\n38 13\n37 14\n36 15\n35 16\n34 17\n33 18\n32 19\n31 20\n30 21\n29 22\n28 23\n27 24\n26 25\n25 26\n24 27\n23 28\n22 29\n21 30\n20 31\n19 32\n18 33\n17 34\n16 35\n15 36\n14 37\n13 38\n12 39\n11 40\n10 41\n9 42\n8 43\n7 44\n6 45\n5 46\n4 47\n3 48\n2 49\n1 50",
"output": "2450"
},
{
"input": "10\n70 -20\n70 -20\n30 20\n30 20\n70 -20\n30 20\n70 -20\n30 20\n70 -20\n30 20",
"output": "49"
},
{
"input": "50\n30 30\n30 30\n30 30\n90 -30\n90 -30\n90 -30\n90 -30\n30 30\n90 -30\n90 -30\n90 -30\n30 30\n90 -30\n30 30\n30 30\n90 -30\n90 -30\n30 30\n30 30\n30 30\n90 -30\n30 30\n90 -30\n30 30\n90 -30\n30 30\n90 -30\n90 -30\n30 30\n90 -30\n90 -30\n90 -30\n90 -30\n30 30\n90 -30\n90 -30\n30 30\n90 -30\n90 -30\n90 -30\n30 30\n90 -30\n30 30\n30 30\n30 30\n90 -30\n30 30\n30 30\n30 30\n90 -30",
"output": "1504"
},
{
"input": "50\n86 -1\n80 1\n56 1\n64 -1\n100 -1\n58 1\n90 1\n98 -1\n4 0\n10 -1\n46 1\n14 0\n62 0\n70 -1\n76 1\n8 -1\n32 0\n16 0\n40 0\n66 1\n26 1\n78 0\n18 0\n34 1\n36 1\n74 0\n84 -1\n50 1\n28 1\n82 1\n20 1\n54 0\n6 0\n96 0\n52 -1\n38 1\n94 0\n48 -1\n42 -1\n12 -1\n22 1\n68 1\n60 -1\n44 0\n88 0\n92 -1\n2 1\n24 -1\n72 1\n30 1",
"output": "5"
},
{
"input": "49\n8 1\n86 1\n24 0\n56 -1\n80 1\n44 -1\n30 1\n4 -1\n70 1\n88 1\n14 1\n72 1\n28 -1\n74 1\n32 -1\n38 0\n54 0\n62 0\n60 -1\n6 -1\n78 0\n10 0\n18 1\n52 -1\n58 1\n22 1\n2 0\n20 1\n68 0\n16 -1\n46 -1\n82 -1\n12 0\n84 -1\n48 -1\n76 1\n98 -1\n42 -1\n92 -1\n96 -1\n40 0\n94 -1\n34 -1\n50 1\n36 0\n66 0\n64 -1\n26 0\n90 1",
"output": "3"
},
{
"input": "4\n4 -1\n3 1\n2 0\n1 3",
"output": "5"
},
{
"input": "8\n8 -1\n7 -1\n6 -1\n5 -1\n4 1\n3 1\n2 1\n1 1",
"output": "1"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "1\n100 -100",
"output": "0"
},
{
"input": "1\n1 100",
"output": "0"
},
{
"input": "1\n1 -100",
"output": "0"
},
{
"input": "20\n2 1\n12 0\n30 0\n18 0\n36 2\n34 -1\n14 -2\n16 0\n6 -1\n38 -1\n4 0\n26 -1\n22 -1\n24 2\n28 -2\n8 2\n10 -2\n40 -2\n32 -1\n20 2",
"output": "11"
},
{
"input": "47\n56 2\n94 -1\n8 -1\n26 -2\n30 0\n34 0\n58 0\n82 0\n6 2\n74 1\n88 0\n10 -2\n42 2\n50 -2\n72 -1\n64 2\n38 1\n16 -1\n92 -2\n44 -1\n32 -1\n90 -1\n68 2\n76 -2\n62 1\n18 0\n2 0\n60 -1\n28 1\n40 -1\n48 -2\n84 -2\n36 -1\n4 -2\n46 1\n78 2\n14 1\n54 -2\n86 1\n52 -1\n80 0\n22 -1\n12 2\n66 0\n70 -1\n20 1\n24 0",
"output": "14"
},
{
"input": "30\n3 94\n7 90\n6 90\n3 93\n6 91\n7 89\n2 92\n8 85\n96 -90\n98 -93\n98 -94\n93 -87\n92 -89\n94 -92\n98 -90\n94 -91\n48 -3\n47 -2\n53 3\n52 0\n49 1\n49 2\n50 3\n52 -3\n53 -2\n51 -1\n51 -2\n48 0\n50 1\n52 -1",
"output": "420"
},
{
"input": "43\n15 57\n20 52\n19 46\n15 54\n18 57\n24 50\n18 50\n15 54\n24 42\n15 57\n23 45\n17 56\n17 56\n20 45\n47 -56\n54 -65\n53 -66\n51 -64\n49 -57\n48 -58\n54 -66\n53 -61\n54 -62\n47 -53\n45 -53\n46 -61\n52 -58\n52 -64\n47 -61\n50 -62\n47 -55\n52 -63\n50 -56\n51 -56\n49 -61\n45 -58\n51 -64\n49 -61\n51 -64\n53 -66\n50 -57\n45 -57\n55 -60",
"output": "1178"
}
] | 108 | 4,608,000 | 3 | 582,353 |
|
176 | Hyper String | [
"dp"
] | null | null | Paul Erdős's prediction came true. Finally an alien force landed on the Earth. In contrary to our expectation they didn't asked the humans to compute the value of a Ramsey number (maybe they had solved it themselves). They asked another question which seemed as hard as calculating Ramsey numbers. Aliens threatened that if humans don't solve this problem in less than 2 hours they will destroy the Earth.
Before telling the problem they introduced the concept of Hyper Strings. A Hyper String is made by concatenation of some base strings. Suppose you are given a list of base strings *b*1,<=*b*2,<=...,<=*b**n*. Now the Hyper String made from indices list *i*1,<=*i*2,<=...,<=*i**m* is concatenation of base strings *b**i*1,<=*b**i*2,<=...,<=*b**i**m*. A Hyper String can be very large and doing operations on it is very costly for computers.
The aliens asked humans to compute the length of the longest common sub-sequence of a Hyper String *t* with a string *s*. | The first line of input contains the single integer *n* (1<=≤<=*n*<=≤<=2000) — the number of base strings.
The next *n* lines contains values of base strings. Each base string is made of lowercase Latin letters. A base string cannot be empty string and the sum of lengths of all *n* base strings doesn't exceed 106.
The next line contains the single integer *m* (1<=≤<=*m*<=≤<=2000) — the number of base strings in the given Hyper String *t*.
The next line contains *m* space-separated integer numbers *i*1,<=*i*2,<=...,<=*i**m* (1<=≤<=*i**j*<=≤<=*n*) — the indices of base strings in the Hyper String *t*.
The last line contains a non-empty string *s*. String *s* is made of lowercase Latin letters and its length is no more than 2000 characters. | Print the length of longest common sub-sequence of Hyper String *t* and string *s*. If there is no common sub-sequence print 0. | [
"2\ncba\ndgh\n2\n1 2\naedfhr\n",
"2\nb\na\n5\n1 2 1 2 1\naaa\n"
] | [
"3\n",
"2\n"
] | The length of string *s* is the number of characters in it. If the length of string *s* is marked as |*s*|, then string *s* can be represented as *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub>.
A non-empty string *y* = *s*[*p*<sub class="lower-index">1</sub>*p*<sub class="lower-index">2</sub>... *p*<sub class="lower-index">|*y*|</sub>] = *s*<sub class="lower-index">*p*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*p*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*p*<sub class="lower-index">|*y*|</sub></sub> (1 ≤ *p*<sub class="lower-index">1</sub> < *p*<sub class="lower-index">2</sub> < ... < *p*<sub class="lower-index">|*y*|</sub> ≤ |*s*|) is a subsequence of string *s*. For example, "coders" is a subsequence of "codeforces". | [] | 92 | 0 | 0 | 583,163 |
|
850 | Random Elections | [
"bitmasks",
"brute force",
"divide and conquer",
"fft",
"math"
] | null | null | The presidential election is coming in Bearland next year! Everybody is so excited about this!
So far, there are three candidates, Alice, Bob, and Charlie.
There are *n* citizens in Bearland. The election result will determine the life of all citizens of Bearland for many years. Because of this great responsibility, each of *n* citizens will choose one of six orders of preference between Alice, Bob and Charlie uniformly at random, independently from other voters.
The government of Bearland has devised a function to help determine the outcome of the election given the voters preferences. More specifically, the function is (takes *n* boolean numbers and returns a boolean number). The function also obeys the following property: *f*(1<=-<=*x*1,<=1<=-<=*x*2,<=...,<=1<=-<=*x**n*)<==<=1<=-<=*f*(*x*1,<=*x*2,<=...,<=*x**n*).
Three rounds will be run between each pair of candidates: Alice and Bob, Bob and Charlie, Charlie and Alice. In each round, *x**i* will be equal to 1, if *i*-th citizen prefers the first candidate to second in this round, and 0 otherwise. After this, *y*<==<=*f*(*x*1,<=*x*2,<=...,<=*x**n*) will be calculated. If *y*<==<=1, the first candidate will be declared as winner in this round. If *y*<==<=0, the second will be the winner, respectively.
Define the probability that there is a candidate who won two rounds as *p*. *p*·6*n* is always an integer. Print the value of this integer modulo 109<=+<=7<==<=1 000 000 007. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=20).
The next line contains a string of length 2*n* of zeros and ones, representing function *f*. Let *b**k*(*x*) the *k*-th bit in binary representation of *x*, *i*-th (0-based) digit of this string shows the return value of *f*(*b*1(*i*),<=*b*2(*i*),<=...,<=*b**n*(*i*)).
It is guaranteed that *f*(1<=-<=*x*1,<=1<=-<=*x*2,<=...,<=1<=-<=*x**n*)<==<=1<=-<=*f*(*x*1,<=*x*2,<=...,<=*x**n*) for any values of *x*1,<=*x*2,<=*ldots*,<=*x**n*. | Output one integer — answer to the problem. | [
"3\n01010101\n",
"3\n01101001\n"
] | [
"216\n",
"168\n"
] | In first sample, result is always fully determined by the first voter. In other words, *f*(*x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">3</sub>) = *x*<sub class="lower-index">1</sub>. Thus, any no matter what happens, there will be a candidate who won two rounds (more specifically, the candidate who is at the top of voter 1's preference list), so *p* = 1, and we print 1·6<sup class="upper-index">3</sup> = 216. | [] | 46 | 0 | 0 | 583,648 |
|
0 | none | [
"none"
] | null | null | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of *n* bullet slots able to contain exactly *k* bullets, now the boys have a chance to resolve the problem once and for all.
Sasha selects any *k* out of *n* slots he wishes and puts bullets there. Roma spins the cylinder so that every of *n* possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner.
Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one.
More formally, the cylinder of *n* bullet slots able to contain *k* bullets can be represented as a string of *n* characters. Exactly *k* of them are "X" (charged slots) and the others are "." (uncharged slots).
Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string.
Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each *x**i* query must be answered: is there a bullet in the positions *x**i*? | The first line contains three integers *n*, *k* and *p* (1<=≤<=*n*<=≤<=1018,<=0<=≤<=*k*<=≤<=*n*,<=1<=≤<=*p*<=≤<=1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow *p* lines; they are the queries. Each line contains one integer *x**i* (1<=≤<=*x**i*<=≤<=*n*) the number of slot to describe.
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | For each query print "." if the slot should be empty and "X" if the slot should be charged. | [
"3 1 3\n1\n2\n3\n",
"6 3 6\n1\n2\n3\n4\n5\n6\n",
"5 2 5\n1\n2\n3\n4\n5\n"
] | [
"..X",
".X.X.X",
"...XX"
] | The lexicographical comparison of is performed by the < operator in modern programming languages. The *a* string is lexicographically less that the *b* string, if there exists such *i* (1 ≤ *i* ≤ *n*), that *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, and for any *j* (1 ≤ *j* < *i*) *a*<sub class="lower-index">*j*</sub> = *b*<sub class="lower-index">*j*</sub>. | [
{
"input": "3 1 3\n1\n2\n3",
"output": "..X"
},
{
"input": "6 3 6\n1\n2\n3\n4\n5\n6",
"output": ".X.X.X"
},
{
"input": "5 2 5\n1\n2\n3\n4\n5",
"output": "...XX"
},
{
"input": "4 2 8\n1\n3\n4\n2\n3\n4\n1\n2",
"output": "..XX.X.X"
},
{
"input": "4 0 4\n1\n2\n3\n4",
"output": "...."
},
{
"input": "10 2 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": ".......X.X"
},
{
"input": "12 2 12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12",
"output": ".........X.X"
},
{
"input": "9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9",
"output": "...X.X.XX"
},
{
"input": "15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15",
"output": ".X.X.X.X.XXXXXX"
},
{
"input": "7 3 7\n1\n2\n3\n4\n5\n6\n7",
"output": "...X.XX"
},
{
"input": "7 4 7\n1\n2\n3\n4\n5\n6\n7",
"output": ".X.X.XX"
},
{
"input": "7 5 7\n1\n2\n3\n4\n5\n6\n7",
"output": ".X.XXXX"
},
{
"input": "7 7 7\n1\n2\n3\n4\n5\n6\n7",
"output": "XXXXXXX"
}
] | 60 | 0 | 0 | 585,387 |
|
958 | Death Stars (hard) | [] | null | null | The stardate is 2015, and Death Stars are bigger than ever! This time, two rebel spies have yet again given Heidi two maps with the possible locations of the Death Stars.
Heidi has now received two maps with possible locations of *N* Death Stars. She knows that each of the maps is possibly corrupted, and may contain some stars that are not Death Stars. Furthermore, each of the maps was created from a different point of view. Hence, stars that are shown in one of the maps are rotated and translated with respect to the other map. Now Heidi wants to find out which of the stars shown in both maps are actually Death Stars, and the correspondence between the Death Stars on the two maps. | The first line of the input contains an integer *N* (1000<=≤<=*N*<=≤<=50000) – the number of Death Stars. The second line of the input contains an integer *N*1 (*N*<=≤<=*N*1<=≤<=1.5·*N*) – the number of stars in the first map. The next *N*1 lines specify the coordinates of the stars in the first map. The *i*-th line contains two space-separated floating-point numbers *x**i* and *y**i* with two decimal digits of precision each, representing the coordinates of the *i*-th star in the first map.
The next line of the input contains an integer *N*2 (*N*<=≤<=*N*2<=≤<=1.5·*N*) – the number of stars in the second map. The next *N*2 lines contain locations of the stars in the second map, given in the same format as for the first map. | You should output exactly *N* lines, each containing a space-separated pair of integers *i*1 and *i*2. Each such line should indicate that the star numbered *i*1 in the first map corresponds to the star numbered *i*2 in the second map. Your answer will be considered correct if over 90% of the distinct pairs listed in your output are indeed correct. | [] | [] | The tests are generated in the following way:
- The number of Death Stars *N* is pre-selected in some way. - The numbers of stars on the first and on the second map, *N*<sub class="lower-index">1</sub> and *N*<sub class="lower-index">2</sub>, are selected uniformly at random between 1.0 × *N* and 1.5 × *N*. - *N* Death Stars are generated at random, with coordinates between - 10000 and 10000. - Additional *N*<sub class="lower-index">1</sub> - *N* and *N*2 - *N* stars for the first and for the second map respectively are generated in the same way. - A translation vector (*dx*, *dy*) is generated, with *dx* and *dy* selected uniformly at random between - 10000 and 10000. Each point in the first map is translated by (*dx*, *dy*). - A rotation angle θ is generated, with θ selected uniformly at random between 0 and 2π. Each point in the first map is rotated by an angle of θ around the origin. - Translations and rotations for the second map are generated and applied in the same way. - The order of points is randomly permuted for both maps. - The test case is saved, with each point written with two decimal digits of precision. | [] | 1,279 | 512,000 | 0 | 585,668 |
|
626 | Raffles | [
"data structures",
"dp",
"greedy",
"math"
] | null | null | Johnny is at a carnival which has *n* raffles. Raffle *i* has a prize with value *p**i*. Each participant can put tickets in whichever raffles they choose (they may have more than one ticket in a single raffle). At the end of the carnival, one ticket is selected at random from each raffle, and the owner of the ticket wins the associated prize. A single person can win multiple prizes from different raffles.
However, county rules prevent any one participant from owning more than half the tickets in a single raffle, i.e. putting more tickets in the raffle than all the other participants combined. To help combat this (and possibly win some prizes), the organizers started by placing a single ticket in each raffle, which they will never remove.
Johnny bought *t* tickets and is wondering where to place them. Currently, there are a total of *l**i* tickets in the *i*-th raffle. He watches as other participants place tickets and modify their decisions and, at every moment in time, wants to know how much he can possibly earn. Find the maximum possible expected value of Johnny's winnings at each moment if he distributes his tickets optimally. Johnny may redistribute all of his tickets arbitrarily between each update, but he may not place more than *t* tickets total or have more tickets in a single raffle than all other participants combined. | The first line contains two integers *n*, *t*, and *q* (1<=≤<=*n*,<=*t*,<=*q*<=≤<=200 000) — the number of raffles, the number of tickets Johnny has, and the total number of updates, respectively.
The second line contains *n* space-separated integers *p**i* (1<=≤<=*p**i*<=≤<=1000) — the value of the *i*-th prize.
The third line contains *n* space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=1000) — the number of tickets initially in the *i*-th raffle.
The last *q* lines contain the descriptions of the updates. Each description contains two integers *t**k*, *r**k* (1<=≤<=*t**k*<=≤<=2, 1<=≤<=*r**k*<=≤<=*n*) — the type of the update and the raffle number. An update of type 1 represents another participant adding a ticket to raffle *r**k*. An update of type 2 represents another participant removing a ticket from raffle *r**k*.
It is guaranteed that, after each update, each raffle has at least 1 ticket (not including Johnny's) in it. | Print *q* lines, each containing a single real number — the maximum expected value of Johnny's winnings after the *k*-th update. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2 1 3\n4 5\n1 2\n1 1\n1 2\n2 1\n",
"3 20 5\n6 8 10\n6 6 6\n1 1\n1 2\n1 3\n2 3\n2 3\n"
] | [
"1.666666667\n1.333333333\n2.000000000\n",
"12.000000000\n12.000000000\n11.769230769\n12.000000000\n12.000000000\n"
] | In the first case, Johnny only has one ticket to distribute. The prizes are worth 4 and 5, and the raffles initially have 1 and 2 tickets, respectively. After the first update, each raffle has 2 tickets, so Johnny has expected value <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/436bcf2181eea8fe79cdb015a5567ca1b8d69652.png" style="max-width: 100.0%;max-height: 100.0%;"/> of winning by placing his ticket into the second raffle. The second update adds a ticket to the second raffle, so Johnny can win <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6ed6e0db65395a75b021f54fa4289733d0399cee.png" style="max-width: 100.0%;max-height: 100.0%;"/> in the first raffle. After the final update, Johnny keeps his ticket in the first raffle and wins <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/83dfd107e988fb3278df4f4561bd77ba068cc202.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second case, Johnny has more tickets than he is allowed to spend. In particular, after the first update, there are 7, 6, and 6 tickets in each raffle, respectively, so Johnny can only put in 19 tickets, winning each prize with probability <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Also, note that after the last two updates, Johnny must remove a ticket from the last raffle in order to stay under <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb946338365d9781f7d2e9ec692c26702d0ae3a7.png" style="max-width: 100.0%;max-height: 100.0%;"/> the tickets in the third raffle. | [] | 30 | 0 | 0 | 594,361 |
|
286 | Tourists | [
"data structures",
"sortings"
] | null | null | A double tourist path, located at a park in Ultima Thule, is working by the following principle:
- We introduce the Cartesian coordinate system. - At some points of time there are two tourists going (for a walk) from points (<=-<=1,<=0) and (1,<=0) simultaneously. The first one is walking from (<=-<=1,<=0), the second one is walking from (1,<=0). - Both tourists in a pair move at the same speed 1 (distance unit per second), the first one moves along line *x*<==<=<=-<=1, the second one moves along line *x*<==<=1, both of them are moving in the positive direction of the *Oy* axis. - At some points of time walls appear. Wall (*l**i*,<=*r**i*) is a segment between points (0,<=*l**i*) and (0,<=*r**i*). Each wall appears immediately.
The Ultima Thule government wants to learn this for each pair of tourists that walk simultaneously: for how long (in seconds) will they not see each other? Two tourists don't see each other if the segment that connects their positions on the plane intersects at least one wall. Two segments intersect if they share at least one point. We assume that the segments' ends belong to the segments.
Help the government count the required time. Note that the walls can intersect (in any way) or coincide. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of pairs of tourists and the number of built walls. The next *m* lines contain three space-separated integers *l**i*, *r**i* and *t**i* each (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109, 0<=≤<=*t**i*<=≤<=109) — the wall ends and the time it appeared. The last line contains *n* distinct space-separated strictly increasing integers *q*1,<=*q*2,<=...,<=*q**n* (0<=≤<=*q**i*<=≤<=109) — the points of time when pairs of tourists walk.
All points of time are given in seconds. | For each pair of tourists print on a single line a single integer — the time in seconds when the two tourists from the corresponding pair won't see each other. Print the numbers in the order in which the they go in the input. | [
"2 2\n1 4 3\n3 6 5\n0 1\n",
"3 3\n0 3 4\n0 1 2\n2 4 0\n1 3 4\n"
] | [
"2\n4\n",
"2\n4\n4\n"
] | none | [] | 46 | 0 | 0 | 594,586 |
|
154 | Martian Colony | [
"geometry"
] | null | null | The first ship with the Earth settlers landed on Mars. The colonists managed to build *n* necessary structures on the surface of the planet (which can be regarded as a plane, and the construction can be regarded as points on it). But one day the scanners recorded suspicious activity on the outskirts of the colony. It was decided to use the protective force field generating system to protect the colony against possible trouble.
The system works as follows: the surface contains a number of generators of the field (they can also be considered as points). The active range of each generator is a circle of radius *r* centered at the location of the generator (the boundary of the circle is also included in the range). After the system is activated, it stretches the protective force field only over the part of the surface, which is within the area of all generators' activity. That is, the protected part is the intersection of the generators' active ranges.
The number of generators available to the colonists is not limited, but the system of field generation consumes a lot of energy. More precisely, the energy consumption does not depend on the number of generators, but it is directly proportional to the area, which is protected by the field. Also, it is necessary that all the existing buildings are located within the protected area.
Determine the smallest possible area of the protected part of the surface containing all the buildings. | The first line contains two integers *n* and *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*r*<=≤<=50000) — the number of buildings and the active ranges of the generators, correspondingly.
Next *n* lines contains the buildings' coordinates. The *i*<=+<=1-th (1<=≤<=*i*<=≤<=*n*) line contains two real numbers with at most three digits after the decimal point *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=50000) — coordinates of the *i*-th building. It is guaranteed that no two buildings are located at the same point, and no two different buildings are located closer than 1.
It is guaranteed that there exists a circle with radius *r* that contains all the buildings. | Print the single real number — the minimum area of the protected part containing all the buildings. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"3 5\n0.00 0.000\n0.0 8.00\n6 8.00\n",
"4 1000\n0.0 0.0\n0 2.00\n2.00 2\n2.0 0.00\n",
"4 5\n3.00 0.0\n-3 0.00\n0.000 1\n0.0 -1.00\n"
] | [
"78.5398163397\n",
"4.0026666140\n",
"8.1750554397\n"
] | In the first sample the given radius equals the radius of the circle circumscribed around the given points. That's why the circle that corresponds to it is the sought area. The answer is 25π.
In the second sample the area nearly coincides with the square which has vertexes in the given points.
The area for the third sample is shown on the picture below. | [] | 92 | 0 | 0 | 602,696 |
|
418 | Big Problems for Organizers | [
"data structures",
"graphs",
"trees"
] | null | null | The Finals of the "Russian Code Cup" 2214 will be held in *n* hotels. Two hotels (let's assume that they are the main hotels), will host all sorts of events, and the remaining hotels will accommodate the participants. The hotels are connected by *n*<=-<=1 roads, you can get from any hotel to any other one.
The organizers wonder what is the minimum time all the participants need to get to the main hotels, if each participant goes to the main hotel that is nearest to him and moving between two hotels connected by a road takes one unit of time.
The hosts consider various options for the location of the main hotels. For each option help the organizers to find minimal time. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100000) — the number of hotels. The next *n*<=-<=1 lines contain two integers each — the numbers of the hotels that have a road between them. Consider hotels are numbered from 1 to *n*.
The next line contains an integer *m* (1<=≤<=*m*<=≤<=100000) — the number of queries. The following *m* lines contains two distinct integers each — the numbers of the hotels we assume to be the main. | For each request of the organizers print a single integer — the time that all participants need to reach the main hotels. | [
"3\n2 3\n3 1\n3\n2 1\n2 3\n3 1\n",
"4\n1 4\n1 2\n2 3\n3\n1 4\n1 3\n2 3\n"
] | [
"1\n1\n1\n",
"2\n1\n2\n"
] | none | [] | 30 | 0 | 0 | 609,800 |
|
0 | none | [
"none"
] | null | null | A new bus route is opened in the city . The route is a closed polygon line in the place, with all segments parallel to one of the axes. *m* buses will operate on the route. All buses move in a loop along the route in the same direction with equal constant velocities (stopping times are negligible in this problem).
Buses start their movement in the first vertex of the route with equal interval. Suppose that *T* is the total time for a single bus to travel the whole loop of the route. Then, the bus 1 starts moving at time 0, the bus 2 starts at time *T*<=/<=*m*, the bus 3 starts at time 2*T*<=/<=*m*, and so on; finally, the bus *m* starts moving at time (*m*<=-<=1)*T*<=/<=*m*. Thus, all intervals between pairs of consecutive buses (including the interval between the last and the first bus) are equal.
Buses can communicate with each other via wireless transmitters of equal power. If the transmitters have power *D*, then only buses within distance *D* of each other can communicate.
The buses are also equipped with a distributed system of schedule tracking. For all buses to stick to the schedule, the system has to synchronize the necessary data between all buses from time to time. At the moment of synchronization, the bus 1 communicates with the bus 2, the bus 2 — with bus 3, and so on; also, the bus *m* communicates with the bus 1.
As a research employee, you are tasked with finding the smallest value of *D* such that it is possible to find a time moment to perform synchronization once all buses have started moving. | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=105) — the number of vertices of the polygonal line, and the number of buses respectively.
Next *n* lines describe the vertices of the route in the traversing order. Each of these lines contains two integers *x**i*, *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) — coordinates of respective vertex.
It is guaranteed that each leg of the route (including the leg between the last and the first vertex) is paralles to one of the coordinate axes. Moreover, no two subsequent vertices of the route coincide. The route is allowed to have self-intersections, and travel along the same segment multiple times. | Print one real number — the answer to the problem. Your answer will be accepted if the relative or the absolute error doesn't exceed 10<=-<=6. | [
"4 2\n0 0\n0 1\n1 1\n1 0\n",
"2 2\n0 0\n1 0\n"
] | [
"1.000000000\n",
"0.000000000"
] | Suppose that each bus travel 1 distance unit per second.
In the first sample case, in 0.5 seconds buses will be at distance 1, hence we can choose *D* = 1.
In the second sample case, in 0.5 seconds both buses will be at (0.5, 0), hence we can choose *D* = 0. | [] | 46 | 0 | 0 | 610,863 |
|
741 | Arpa’s abnormal DNA and Mehrdad’s deep interest | [
"data structures",
"string suffix structures"
] | null | null | All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D
Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.
Sipa put Arpa under the DNA editor. DNA editor showed Arpa's DNA as a string *S* consisting of *n* lowercase English letters. Also Sipa has another DNA *T* consisting of lowercase English letters that belongs to a normal man.
Now there are (*n*<=+<=1) options to change Arpa's DNA, numbered from 0 to *n*. *i*-th of them is to put *T* between *i*-th and (*i*<=+<=1)-th characters of *S* (0<=≤<=*i*<=≤<=*n*). If *i*<==<=0, *T* will be put before *S*, and if *i*<==<=*n*, it will be put after *S*.
Mehrdad wants to choose the most interesting option for Arpa's DNA among these *n*<=+<=1 options. DNA *A* is more interesting than *B* if *A* is lexicographically smaller than *B*. Mehrdad asked Sipa *q* questions:
Given integers *l*,<=*r*,<=*k*,<=*x*,<=*y*, what is the most interesting option if we only consider such options *i* that *l*<=≤<=*i*<=≤<=*r* and ? If there are several most interesting options, Mehrdad wants to know one with the smallest number *i*.
Since Sipa is a biology scientist but not a programmer, you should help him. | The first line contains strings *S*, *T* and integer *q* (1<=≤<=|*S*|,<=|*T*|,<=*q*<=≤<=105) — Arpa's DNA, the DNA of a normal man, and the number of Mehrdad's questions. The strings *S* and *T* consist only of small English letters.
Next *q* lines describe the Mehrdad's questions. Each of these lines contain five integers *l*,<=*r*,<=*k*,<=*x*,<=*y* (0<=≤<=*l*<=≤<=*r*<=≤<=*n*, 1<=≤<=*k*<=≤<=*n*, 0<=≤<=*x*<=≤<=*y*<=<<=*k*). | Print *q* integers. The *j*-th of them should be the number *i* of the most interesting option among those that satisfy the conditions of the *j*-th question. If there is no option *i* satisfying the conditions in some question, print -1. | [
"abc d 4\n0 3 2 0 0\n0 3 1 0 0\n1 2 1 0 0\n0 1 3 2 2\n",
"abbbbbbaaa baababaaab 10\n1 2 1 0 0\n2 7 8 4 7\n2 3 9 2 8\n3 4 6 1 1\n0 8 5 2 4\n2 8 10 4 7\n7 10 1 0 0\n1 4 6 0 2\n0 9 8 0 6\n4 8 5 0 1\n"
] | [
"2 3 2 -1 \n",
"1 4 2 -1 2 4 10 1 1 5 \n"
] | Explanation of first sample case:
In the first question Sipa has two options: dabc (*i* = 0) and abdc (*i* = 2). The latter (abcd) is better than abdc, so answer is 2.
In the last question there is no *i* such that 0 ≤ *i* ≤ 1 and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7cc85c61d920b3b180f2ce094f0077871cd4c4d7.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [] | 46 | 0 | 0 | 614,284 |
|
580 | Kefa and Watch | [
"data structures",
"hashing",
"strings"
] | null | null | One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money.
The pawnbroker said that each watch contains a serial number represented by a string of digits from 0 to 9, and the more quality checks this number passes, the higher is the value of the watch. The check is defined by three positive integers *l*, *r* and *d*. The watches pass a check if a substring of the serial number from *l* to *r* has period *d*. Sometimes the pawnbroker gets distracted and Kefa changes in some substring of the serial number all digits to *c* in order to increase profit from the watch.
The seller has a lot of things to do to begin with and with Kefa messing about, he gave you a task: to write a program that determines the value of the watch.
Let us remind you that number *x* is called a period of string *s* (1<=≤<=*x*<=≤<=|*s*|), if *s**i*<=<==<=<=*s**i*<=+<=*x* for all *i* from 1 to |*s*|<=<=-<=<=*x*. | The first line of the input contains three positive integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=+<=*k*<=≤<=105) — the length of the serial number, the number of change made by Kefa and the number of quality checks.
The second line contains a serial number consisting of *n* digits.
Then *m*<=+<=*k* lines follow, containing either checks or changes.
The changes are given as 1 *l* *r* *c* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, 0<=≤<=*c*<=≤<=9). That means that Kefa changed all the digits from the *l*-th to the *r*-th to be *c*.
The checks are given as 2 *l* *r* *d* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, 1<=≤<=*d*<=≤<=*r*<=-<=*l*<=+<=1). | For each check on a single line print "YES" if the watch passed it, otherwise print "NO". | [
"3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1\n",
"6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1\n"
] | [
"NO\nYES\n",
"NO\nYES\nNO\n"
] | In the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES".
In the second statement test three checks will be made. The first check processes substring "3493", which doesn't have period 2. Before the second check the string looks as "334334", so the answer to it is "YES". And finally, the third check processes substring "8334", which does not have period 1. | [
{
"input": "3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1",
"output": "NO\nYES"
},
{
"input": "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1",
"output": "NO\nYES\nNO"
},
{
"input": "1 0 1\n5\n2 1 1 1",
"output": "YES"
},
{
"input": "20 1 2\n34075930750342906718\n2 1 20 20\n1 1 20 6\n2 1 20 1",
"output": "YES\nYES"
},
{
"input": "10 1 4\n4545454545\n2 1 10 2\n2 2 4 2\n2 2 9 4\n1 2 9 6\n2 3 8 3",
"output": "YES\nYES\nYES\nYES"
},
{
"input": "15 1 5\n234072305423089\n2 1 15 1\n2 5 6 1\n2 8 11 2\n2 2 13 6\n1 5 12 4\n2 5 13 3",
"output": "NO\nNO\nNO\nNO\nNO"
},
{
"input": "9 7 5\n622851212\n2 1 9 3\n1 1 4 2\n1 6 9 7\n2 2 8 1\n1 2 3 9\n1 7 8 5\n2 1 9 9\n1 2 3 7\n1 7 7 2\n2 4 9 3\n1 2 2 5\n2 1 9 3",
"output": "NO\nNO\nYES\nYES\nYES"
},
{
"input": "18 0 6\n000000000000000000\n2 1 18 1\n2 1 18 18\n2 1 18 6\n2 1 18 3\n2 1 18 9\n2 1 18 2",
"output": "YES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "8 3 4\n90925761\n2 5 8 2\n1 2 4 5\n2 2 5 2\n1 6 7 5\n2 2 7 3\n1 3 4 9\n2 1 4 2",
"output": "NO\nYES\nYES\nNO"
},
{
"input": "10 10 7\n8888888888\n1 1 1 4\n1 2 2 5\n1 3 3 7\n1 4 4 7\n1 5 5 7\n1 6 6 7\n1 7 7 5\n1 8 8 6\n1 9 9 3\n1 10 10 7\n2 5 6 1\n2 8 8 1\n2 5 6 1\n2 7 9 3\n2 5 6 1\n2 4 4 1\n2 9 10 1",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nNO"
},
{
"input": "20 5 5\n23655146364900318111\n1 5 19 9\n2 1 3 3\n2 4 5 1\n1 2 17 9\n2 4 5 1\n1 8 9 0\n2 4 5 1\n1 4 15 2\n2 1 3 3\n1 20 20 6",
"output": "YES\nNO\nYES\nYES\nYES"
},
{
"input": "20 10 15\n00137794455431057085\n2 1 20 1\n2 8 10 3\n2 1 20 1\n1 2 2 6\n1 11 13 0\n2 1 20 1\n2 1 2 1\n1 14 16 0\n1 5 9 0\n1 5 8 3\n1 10 11 7\n1 17 19 5\n2 1 20 1\n2 8 10 3\n2 1 20 1\n1 17 20 0\n1 7 10 7\n1 7 12 7\n2 1 20 1\n2 1 2 1\n2 8 10 3\n2 1 2 1\n2 8 10 3\n2 8 10 3\n2 8 10 3",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nYES\nYES\nYES"
},
{
"input": "50 10 9\n78117811831783178317831700000000000000000000117773\n1 5 22 4\n1 11 24 0\n1 35 37 5\n2 45 46 1\n2 45 46 1\n1 41 41 3\n1 24 27 1\n2 9 24 4\n1 2 21 5\n2 45 46 1\n1 3 9 1\n1 11 23 5\n1 25 32 1\n2 47 49 1\n2 9 24 4\n1 34 45 0\n2 9 24 4\n2 1 8 4\n2 9 24 4",
"output": "YES\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nNO"
},
{
"input": "52 5 30\n0073971598462524060181848948785829847120611111998011\n2 43 46 1\n1 25 28 2\n1 1 30 4\n2 1 52 1\n2 1 3 3\n2 1 3 3\n1 11 15 2\n2 1 52 1\n2 43 46 1\n1 3 7 9\n2 1 3 3\n1 26 49 3\n2 1 3 3\n2 1 52 1\n2 43 46 1\n2 1 3 3\n2 1 52 1\n2 1 52 1\n2 1 3 3\n2 1 52 1\n2 1 3 3\n2 1 3 3\n2 1 52 1\n2 1 3 3\n2 1 52 1\n2 43 46 1\n2 1 52 1\n2 43 46 1\n2 1 3 3\n2 43 46 1\n2 43 46 1\n2 43 46 1\n2 1 3 3\n2 1 52 1\n2 43 46 1",
"output": "YES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES"
},
{
"input": "314 0 1\n12121112111122221121111111212111122212111111112211111111111211121121212112222211222222112222121112121112211211111211111221211112111122212121112221111112111111121122122111111211121112111111121112121222222111211212221212111221112121111112111111112111121121121222112211212212121111112112122111112121212111222221111111\n2 1 314 157",
"output": "NO"
},
{
"input": "153 0 16\n000000000961748941961748947961748951961748969961748987961748993961749023961749037961749043961749067961749079961749091961749097961749101961749121961749157\n2 1 18 9\n2 1 27 18\n2 1 36 27\n2 1 45 36\n2 1 54 45\n2 1 63 54\n2 1 72 63\n2 1 81 72\n2 1 90 81\n2 1 99 90\n2 1 108 99\n2 1 117 108\n2 1 126 117\n2 1 135 126\n2 1 144 135\n2 1 153 144",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "20 1 1\n52018731676138902386\n2 1 20 10\n1 1 20 8",
"output": "NO"
}
] | 763 | 23,449,600 | 3 | 618,245 |
|
933 | A Preponderant Reunion | [
"constructive algorithms",
"dp"
] | null | null | East or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position.
After the reunion dinner, Little Tommy plays a game with the family. Here is a concise introduction to this game:
1. There is a sequence of *n* non-negative integers *p*1,<=*p*2,<=...,<=*p**n* in the beginning. It is ruled that each integer in this sequence should be non-negative at any time. 1. You can select two consecutive positive integers in this sequence, *p**i* and *p**i*<=+<=1 (1<=≤<=*i*<=<<=*n*), and then decrease them by their minimum (i. e. *min*(*p**i*,<=*p**i*<=+<=1)), the cost of this operation is equal to *min*(*p**i*,<=*p**i*<=+<=1). We call such operation as a descension. 1. The game immediately ends when there are no two consecutive positive integers. Your task is to end the game so that the total cost of your operations is as small as possible.
Obviously, every game ends after at most *n*<=-<=1 descensions. Please share your solution of this game with the lowest cost. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105).
The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109,<=*i*<==<=1,<=2,<=...,<=*n*). | In the first line print one integer as the number of descensions *m* (0<=≤<=*m*<=≤<=*n*<=-<=1).
In the next *m* lines print the descensions chronologically. More precisely, in each line of the next *m* lines print one integer *i* (1<=≤<=*i*<=<<=*n*) representing a descension would operate on *p**i* and *p**i*<=+<=1 such that all the descensions could be utilized from top to bottom.
If there are many possible solutions to reach the minimal cost, print any of them. | [
"4\n2 1 3 1\n",
"5\n2 2 1 3 1\n"
] | [
"2\n1\n3\n",
"3\n2\n1\n4\n"
] | In the first sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9248227dd2a5fa16d275273b9219a6e5a3560846.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 = 2.
In the second sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8f91058897d4137e5df572ebfbf65e2a7d88692a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 + 1 = 3. | [] | 46 | 0 | 0 | 618,390 |
|
837 | Functions On The Segments | [
"data structures"
] | null | null | You have an array *f* of *n* functions.The function *f**i*(*x*) (1<=≤<=*i*<=≤<=*n*) is characterized by parameters: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 and take values:
- *y*1, if *x*<=≤<=*x*1. - *a*·*x*<=+<=*b*, if *x*1<=<<=*x*<=≤<=*x*2. - *y*2, if *x*<=><=*x*2.
There are *m* queries. Each query is determined by numbers *l*, *r* and *x*. For a query with number *i* (1<=≤<=*i*<=≤<=*m*), you need to calculate the sum of all *f**j*(*x**i*) where *l*<=≤<=*j*<=≤<=*r*. The value of *x**i* is calculated as follows: *x**i*<==<=(*x*<=+<=*last*) mod 109, where *last* is the answer to the query with number *i*<=-<=1. The value of *last* equals 0 if *i*<==<=1. | First line contains one integer number *n* (1<=≤<=*n*<=≤<=75000).
Each of the next *n* lines contains six integer numbers: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 (0<=≤<=*x*1<=<<=*x*2<=≤<=2·105, 0<=≤<=*y*1,<=*y*2<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=104).
Next line contains one integer number *m* (1<=≤<=*m*<=≤<=500000).
Each of the next *m* lines contains three integer numbers: *l*, *r* and *x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, 0<=≤<=*x*<=≤<=109). | none | [
"1\n1 2 1 4 5 10\n1\n1 1 2\n",
"3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5\n"
] | [
"13\n",
"19\n17\n11\n"
] | none | [
{
"input": "1\n1 2 1 4 5 10\n1\n1 1 2",
"output": "13"
},
{
"input": "3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5",
"output": "19\n17\n11"
},
{
"input": "7\n4 8 562244866 6 8 140807945\n5 7 415374420 7 6 596093578\n3 4 766370993 3 7 973128805\n4 6 841321398 3 2 893107667\n4 9 968214628 5 8 329310838\n0 10 64315145 9 4 716996081\n1 6 568407659 3 0 22184171\n15\n4 7 647898558\n6 7 972924557\n7 7 222835064\n4 7 605696049\n3 3 549028549\n7 7 716270684\n2 4 716558406\n3 3 681131761\n2 2 177328926\n3 6 298280462\n6 7 256719966\n3 3 554401527\n5 6 136725488\n5 6 457040333\n7 7 176796906",
"output": "1961598757\n739180252\n22184171\n1961598757\n973128805\n22184171\n2462330050\n973128805\n596093578\n2912543391\n739180252\n973128805\n1046306919\n1046306919\n22184171"
},
{
"input": "8\n1 10 753310968 2 4 688105437\n1 6 193355966 4 7 598962222\n0 8 600395827 5 8 840898713\n0 3 421099093 10 3 239232128\n7 8 984393026 4 0 820591274\n2 3 99820619 1 4 750632847\n8 10 582155129 0 6 387245981\n5 6 667916797 0 4 3445518\n15\n5 5 361972828\n7 8 705501679\n8 8 890961558\n6 6 865121916\n7 7 595820781\n6 7 782831246\n6 6 295277930\n2 5 251627063\n2 6 439397863\n7 7 104400662\n6 8 219241770\n3 4 429934639\n5 6 858415301\n2 4 36071843\n4 7 976548276",
"output": "820591274\n390691499\n3445518\n750632847\n387245981\n1137878828\n750632847\n2499684337\n3250317184\n387245981\n1141324346\n1080130841\n1571224121\n1679093063\n2197702230"
},
{
"input": "9\n3 10 280813558 6 3 193933732\n3 9 971337514 8 4 896798158\n3 7 803016882 1 6 413701329\n2 10 74505717 6 8 658985518\n2 10 571422 8 3 680467929\n9 10 766729875 4 9 415673394\n5 6 669531526 3 0 752307791\n4 7 98000452 6 5 681772410\n8 10 722448957 9 3 55646997\n15\n3 5 232894565\n6 6 13973148\n9 9 401454228\n4 5 253126950\n6 7 708194225\n1 2 868537175\n2 3 32141176\n7 9 949367089\n1 9 596725344\n7 7 624167310\n1 1 835000987\n9 9 526102998\n4 7 50218935\n1 7 695691438\n5 6 878938576",
"output": "1753154776\n415673394\n55646997\n1339453447\n1167981185\n1090731890\n1310499487\n1489727198\n4749287258\n752307791\n193933732\n55646997\n2507434632\n4011867851\n1096141323"
}
] | 46 | 0 | 0 | 620,486 |
|
856 | Satellites | [] | null | null | Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.
The planet is at the very edge of the universe, so its form is half of a circle. Its radius is *r*, the ends of its diameter are points *A* and *B*. The line *AB* is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of *AB* segment, *OX* axis coincides with line *AB*, the planet is completely in *y*<=><=0 half-plane.
The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate *y*<=><=0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points *A* and *B*. Let us call this area the satellite coverage area.
The picture below shows coordinate system and coverage area of a satellite.
When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types:
1. 1 x y — launch the new satellite and put it to the point (*x*,<=*y*). Satellites never move and stay at the point they were launched. Let us assign the number *i* to the *i*-th satellite in order of launching, starting from one. 1. 2 i — remove satellite number *i*. 1. 3 i j — make an attempt to create a communication channel between satellites *i* and *j*. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites *i* and *j*. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate *y*<=><=0.
For each attempt to create a communication channel you must find out whether it is possible.
Sample test has the following satellites locations: | The first line of input data contains integers *r* and *n* — radius of the planet and the number of events (1<=≤<=*r*<=≤<=109, 1<=≤<=*n*<=≤<=5·105).
Each of the following *n* lines describe events in the specified format.
Satellite coordinates are integer, the satisfy the following constraints |*x*|<=≤<=109, 0<=<<=*y*<=≤<=109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than *r*.
It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality *i*<=≠<=*j* is satisfied. | For each event of type 3 print «YES» on a separate line, if it is possible to create a communication channel, or «NO» if it is impossible. | [
"5 8\n1 -5 8\n1 -4 8\n1 -3 8\n1 2 7\n3 1 3\n2 2\n3 1 3\n3 3 4\n"
] | [
"NO\nYES\nYES\n"
] | none | [] | 30 | 0 | 0 | 620,554 |
|
736 | Chess Championship | [
"constructive algorithms",
"flows",
"greedy",
"math"
] | null | null | Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were *m* players participating and each pair of players played exactly one game. The victory gives 2 points, draw — 1 points, lose — 0 points.
Ostap is lazy, so he never tries to remember the outcome of each game. Instead, he computes the total number of points earned by each of the players (the sum of his points in all games which he took part in), sort these value in non-ascending order and then remembers first *n* integers in this list.
Now the Great Strategist Ostap wonders whether he remembers everything correct. He considers that he is correct if there exists at least one tournament results table such that it will produce the given integers. That means, if we count the sum of points for each player, sort them and take first *n* elements, the result will coincide with what Ostap remembers. Can you check if such table exists? | The first line of the input contains two integers *m* and *n* (1<=≤<=*n*<=≤<=*m*<=≤<=3000) — the number of participants of the tournament and the number of top results Ostap remembers.
The second line contains *n* integers, provided in non-ascending order — the number of points earned by top participants as Ostap remembers them. It's guaranteed that this integers are non-negative and do not exceed 2·*m*. | If there is no tournament such that Ostap can obtain the given set of integers using the procedure described in the statement, then print "no" in the only line of the output. Otherwise, the first line of the output should contain the word "yes". Next *m* lines should provide the description of any valid tournament. Each of these lines must contain *m* characters 'X', 'W', 'D' and 'L'. Character 'X' should always be located on the main diagonal (and only there), that is on the *i*-th position of the *i*-th string. Character 'W' on the *j*-th position of the *i*-th string means that the *i*-th player won the game against the *j*-th. In the same way character 'L' means loose and 'D' means draw.
The table you print must be consistent and the points earned by best *n* participants should match the memory of Ostap. If there are many possible answers, print any of them. | [
"5 5\n8 6 4 2 0\n",
"5 1\n9\n"
] | [
"yes\nXWWWW\nLXWWW\nLLXWW\nLLLXW\nLLLLX\n",
"no\n"
] | none | [] | 31 | 0 | 0 | 621,337 |