contestId
int64 0
1.01k
| name
stringlengths 2
58
| tags
sequencelengths 0
11
| title
stringclasses 523
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| test_cases
listlengths 0
402
| timeConsumedMillis
int64 0
8k
| memoryConsumedBytes
int64 0
537M
| score
float64 -1
3.99
| __index_level_0__
int64 0
621k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | [
"none"
] | null | null | A subsequence of length |*x*| of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is a string *x*<==<=*s**k*1*s**k*2... *s**k*|*x*| (1<=β€<=*k*1<=<<=*k*2<=<<=...<=<<=*k*|*x*|<=β€<=|*s*|).
You've got two stringsΒ β *s* and *t*. Let's consider all subsequences of string *s*, coinciding with string *t*. Is it true that each character of string *s* occurs in at least one of these subsequences? In other words, is it true that for all *i* (1<=β€<=*i*<=β€<=|*s*|), there is such subsequence *x*<==<=*s**k*1*s**k*2... *s**k*|*x*| of string *s*, that *x*<==<=*t* and for some *j* (1<=β€<=*j*<=β€<=|*x*|) *k**j*<==<=*i*. | The first line contains string *s*, the second line contains string *t*. Each line consists only of lowercase English letters. The given strings are non-empty, the length of each string does not exceed 2Β·105. | Print "Yes" (without the quotes), if each character of the string *s* occurs in at least one of the described subsequences, or "No" (without the quotes) otherwise. | [
"abab\nab\n",
"abacaba\naba\n",
"abc\nba\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In the first sample string *t* can occur in the string *s* as a subsequence in three ways: abab, abab and abab. In these occurrences each character of string *s* occurs at least once.
In the second sample the 4-th character of the string *s* doesn't occur in any occurrence of string *t*.
In the third sample there is no occurrence of string *t* in string *s*. | [
{
"input": "abab\nab",
"output": "Yes"
},
{
"input": "abacaba\naba",
"output": "No"
},
{
"input": "abc\nba",
"output": "No"
},
{
"input": "babbbbbaba\nab",
"output": "No"
},
{
"input": "accbacabaa\nbada",
"output": "No"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "Yes"
},
{
"input": "hqxibotrjfqrgwrydtlpkzeqrkfgzdylfokmaguwafdgwltgvqobnouttrrfuavfkqcoqxkfwsuseomraigoljzzbjukwaxcftvlhfzdypuinnxbluzfxajkabirvyawtxzcrxpoghucjypwinspnnbptsuamkbjqgttooxwcsqxrukwwtgrkxdujioqywqlugkjngfxrybvxjmlwszszljfgyouvgdilzseekxlsiujhod\nnghetuvcotztgttmr",
"output": "No"
},
{
"input": "bacbbcbcacaacbabacbcbacaaaabbabaaccccacbcbbbabcacbacacabaabacacbaaacacbbccbcccbabccaacccccbbcabacbaacabaccccccacbbaccbabaaabaaccabcaaabcccccbbabccccccabacbaaababcbbbccbbabcabbbbaaabbccccbacbaacbcacbbaaccbaabcaaacbccccbcbababccbcccabbbabbba\nbacbbcbcacaacbabacbcbacaaaabbabaaccccacbcbbbabcacbacacabaabacacbaaacacbbccbcccbabccaacccccbbcabacbaacabaccccccacbbaccbabaaabaaccabcaaabcccccbbabccccccabacbaaababcbbbccbbabcabbbbaaabbccccbacbaacbcacbbaaccbaabcaaacbccccbcbababccbcccabbbabbba",
"output": "Yes"
},
{
"input": "adbecbeaddbbebdaa\nadbecbeaddbbebdaa",
"output": "Yes"
},
{
"input": "iiiiiiqqqqqqqqqqaaaaffffllllleeeeeeeekkkkkkkhhhhhhhhhhooooooddddddddlllllllliiiaaaaaaaaaaaaaaaaaooggggggggggllllllffffffcccccccpppppppdddddddddddccccbbbbbbbbbbkkkkfffffiiiiiiipppppppppccccnnnnnnnnnnnnnnkkkkkkkkkkqqqqppppppeeeeeeeeemmmmmmmmbbbbbbbaaaaaaffffllllljjjj\niqaflekhodliaaoglfcpdcbbkfipcnnkqpeembaflj",
"output": "Yes"
},
{
"input": "cccbbiiiiiqqvvgggwwwwxxxxxxxxoooondddkkkpvvvdddddooqqxxxxxqqqqllllkkkkkkggggfwwwwwkkkfffeeeemmmmmmmqwwwwwwxxxxxxxdddddqqqqqqq\ncbiqvgwxxondkpvdoqxqlkgfwkfemqwxdq",
"output": "Yes"
},
{
"input": "babaabaabb\nbbccb",
"output": "No"
},
{
"input": "ctkhagrifaztmnxhmqztzibnmzzkojiztvrkfeoqegvwtbxlvvjhebshqaicsovtkcdovytimjggglyxlvglgunbohnkxargymbqvzgsnvjzgxivdgnaesgxqcruaopjuqsyyorrobnelehjnxcetveehlbmeskptivsuhuqupbieumycwczxyqjtwfofehfkpqmjngygwxkaviuyouiippgvlxjgtkxmhcwtzacbllsybgiujyryngapfwjkkyapfgxtcdpc\nctkhagrifaztmnxhmqztzibnmzzkojiztvrkfeoqegvwtbxlvvjhebshqaicsovtkcdovytimjggglyxlvglgunbohnkxargymbqvzgsnvjzgxivdgnaesgxcetveehlbmeskptivsuhuqupbieumycwczxyqjtwfofehfkpqmjngygwxkaviuyouiippgvlxjgtkxmhcwtzacbllsybgiujyryngapfwjkkyapfgxtcdpc",
"output": "No"
},
{
"input": "adedadcababceeeaddadedddaeaccccbcccdaeeecaaeaebccebddddeedabbddeaaccdacebaeeccdeeddbecbdecddebe\nadedcceecebdccdbe",
"output": "No"
},
{
"input": "cctckkhatkgrhktihcgififfgfctctkrgiakrifazzggfzczfkkahhafhcfgacccfakkarcatkfiktczkficahgiriakccfiztkhkgrfkrimgamighhtamrhxftaadwxgfggytwjccgkdpyyatctfdygxggkyycpjyfxyfdwtgytcacawjddjdctyfgddkfkypyxftxxtaddcxxpgfgxgdfggfdggdcddtgpxpctpddcdcpc\nctkhagrifaztmnxhmqztzibnmzzkojiztvrkfeoqegvwtbxlvvjhebshqaicsovtkcdovytimjggglyxlvglgunbohnkxargymbqvzgsnvjzgxivdgnaesgxcetveehlbmeskptivsuhuqupbieumycwczxyqjtwfofehfkpqmjngygwxkaviuyouiippgvlxjgtkxmhcwtzacbllsybgiujyryngapfwjkkyapfgxtcdpc",
"output": "No"
},
{
"input": "iqqiaiiffiqlqfaaflfieflfillkkhqfolhehedqdqqfddlheifeoqeohhoadqkfiqeleeqdekhhahkaqqqiaqliiqlelkhdfodeafqfhogihlgoqafdiffkaekhqhgqfkcqiaaoodkkfeqkciqfeihkifeodhahdhddghaihkhahghlkcckicehechocfhfcdfeldelgaqhqfepipegklqiafhqglcdfgkfpoggldgfcglfbbpkkkfipipcnnkqpeembaflj\niqaflekhodliaaoglfcpdcbbkfipcnnkqpeembaflj",
"output": "No"
},
{
"input": "iqqiaiiffiqlqfaaflfieflfillkkhqfolhehedqdqqfddlheifeoqeohhoadqkfiqeleeqdekhhahkaqqqiaqliiqlelkhdfodeafqfhogihlgoqafdiffkaekhqhgqfkcqiaaoodkkfeqkciqfeihkifeodhahdhddghaihkhahghlkcckicehechocfhfcdfeldelgaqhqfepipegklqiafhqglcdfaflekhodliaaoglfcpdcbbkfipcnnkqpeembaflj\niqaflekhodliaaoglfcpdcbbkfipcnnkqpeembaflj",
"output": "Yes"
},
{
"input": "abaaaba\nabba",
"output": "No"
},
{
"input": "abaca\nabca",
"output": "No"
},
{
"input": "aaa\naaaa",
"output": "No"
},
{
"input": "aa\naaa",
"output": "No"
},
{
"input": "aaaa\naaa",
"output": "Yes"
},
{
"input": "aa\naaaaaaaa",
"output": "No"
},
{
"input": "aaaaaa\naaaaaaa",
"output": "No"
},
{
"input": "aaaaaaaa\naaaaa",
"output": "Yes"
},
{
"input": "abebea\nabeba",
"output": "No"
},
{
"input": "ab\nabcd",
"output": "No"
},
{
"input": "abcdad\nabcd",
"output": "No"
},
{
"input": "abaaaaba\nabba",
"output": "No"
},
{
"input": "ababa\nab",
"output": "No"
},
{
"input": "cabcbac\ncabac",
"output": "No"
},
{
"input": "ababcab\nabbcab",
"output": "No"
},
{
"input": "abaaaaaaba\nabba",
"output": "No"
},
{
"input": "abcbab\nabcab",
"output": "No"
},
{
"input": "abc\nbac",
"output": "No"
},
{
"input": "abcdadbcd\nabcd",
"output": "Yes"
}
] | 30 | 0 | 0 | 52,058 |
|
594 | Max and Bike | [
"binary search",
"geometry"
] | null | null | For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year *n* competitions will take place. During the *i*-th competition the participant must as quickly as possible complete a ride along a straight line from point *s**i* to point *f**i* (*s**i*<=<<=*f**i*).
Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius *r*. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius *r*. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle.
At the beginning each participant can choose any point *b**i*, such that his bike is fully behind the starting line, that is, *b**i*<=<<=*s**i*<=-<=*r*. After that, he starts the movement, instantly accelerates to his maximum speed and at time *ts**i*, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time *tf**i*), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time *tf**i*<=-<=*ts**i*.
Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed *v*, but also on his choice of the initial point *b**i*. Now Maxim is asking you to calculate for each of *n* competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to *r*. | The first line contains three integers *n*, *r* and *v* (1<=β€<=*n*<=β€<=100<=000,<=1<=β€<=*r*,<=*v*<=β€<=109)Β β the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively.
Next *n* lines contain the descriptions of the contests. The *i*-th line contains two integers *s**i* and *f**i* (1<=β€<=*s**i*<=<<=*f**i*<=β€<=109)Β β the coordinate of the start and the coordinate of the finish on the *i*-th competition. | Print *n* real numbers, the *i*-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=6.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"2 1 2\n1 10\n5 9\n"
] | [
"3.849644710502\n1.106060157705\n"
] | none | [
{
"input": "2 1 2\n1 10\n5 9",
"output": "3.849644710502\n1.106060157705"
},
{
"input": "1 9 2\n8 11",
"output": "0.750434631667"
},
{
"input": "5 9 2\n15 18\n13 15\n9 16\n5 21\n10 11",
"output": "0.750434631667\n0.500128680269\n1.755555861769\n4.068584337764\n0.250016077584"
},
{
"input": "3 1 1000000000\n1 2\n1 1000000000\n999999999 1000000000",
"output": "0.000000000503\n0.999999997213\n0.000000000503"
},
{
"input": "3 1000000000 1000000000\n1 2\n1 1000000000\n999999999 1000000000",
"output": "0.000000000500\n0.502637248540\n0.000000000500"
},
{
"input": "3 1000000000 1\n1 2\n1 1000000000\n999999999 1000000000",
"output": "0.499999999998\n502637248.540215130000\n0.499999999998"
},
{
"input": "3 1 1\n1 2\n1 1000000000\n999999999 1000000000",
"output": "0.502637249046\n999999997.213452700000\n0.502637249046"
}
] | 2,000 | 16,486,400 | 0 | 52,113 |
|
69 | Bets | [
"greedy",
"implementation"
] | B. Bets | 2 | 256 | In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are *n* sections of equal length and *m* participants. The participants numbered from 1 to *m*. About each participant the following is known:
- *l**i* β the number of the starting section, - *r**i* β the number of the finishing section (*l**i*<=β€<=*r**i*),- *t**i* β the time a biathlete needs to complete an section of the path,- *c**i* β the profit in roubles. If the *i*-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The *i*-th biathlete passes the sections from *l**i* to *r**i* inclusive. The competitor runs the whole way in (*r**i*<=-<=*l**i*<=+<=1)Β·*t**i* time units. It takes him exactly *t**i* time units to pass each section. In case of the athlete's victory on *k* sections the man who has betted on him receives *k*Β·*c**i* roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit. | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100). Then follow *m* lines, each containing 4 integers *l**i*, *r**i*, *t**i*, *c**i* (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*, 1<=β€<=*t**i*,<=*c**i*<=β€<=1000). | Print a single integer, the maximal profit in roubles that the friends can get. In each of *n* sections it is not allowed to place bets on more than one sportsman. | [
"4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20\n",
"8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20\n"
] | [
"60",
"105"
] | In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | [
{
"input": "4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20",
"output": "60"
},
{
"input": "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20",
"output": "105"
},
{
"input": "2 2\n1 2 3 1\n2 2 3 10",
"output": "2"
},
{
"input": "20 30\n15 17 54 46\n4 18 26 18\n18 20 49 94\n12 12 83 12\n11 13 88 47\n8 8 8 12\n18 18 94 2\n14 17 88 96\n19 19 62 97\n1 12 81 67\n10 12 78 26\n19 20 63 93\n9 20 38 32\n7 9 90 17\n9 10 19 60\n16 16 47 29\n1 6 62 29\n12 18 74 89\n5 5 97 92\n5 17 16 25\n11 19 2 76\n3 15 61 29\n5 7 73 54\n19 20 91 91\n4 17 28 61\n9 13 56 81\n10 11 82 80\n10 11 82 70\n5 10 66 38\n10 19 22 61",
"output": "958"
},
{
"input": "20 30\n4 13 78 11\n13 19 56 41\n15 15 46 83\n4 9 74 72\n17 20 97 7\n15 20 29 48\n8 17 44 85\n4 18 26 46\n16 17 9 90\n16 16 39 89\n13 14 46 63\n14 18 67 18\n12 20 84 48\n10 20 49 32\n10 14 14 11\n6 18 80 84\n3 20 13 97\n12 20 62 42\n12 14 64 71\n5 19 38 17\n17 18 99 18\n11 15 83 22\n4 11 65 99\n8 16 89 45\n11 20 15 39\n8 13 85 26\n5 19 84 3\n10 16 26 45\n13 16 81 37\n3 5 100 42",
"output": "1732"
},
{
"input": "20 30\n4 12 30 83\n3 3 91 46\n5 11 82 84\n20 20 29 36\n3 13 89 29\n11 14 40 80\n9 20 90 21\n14 19 23 74\n8 9 13 88\n12 18 13 95\n13 18 48 29\n8 17 13 15\n7 15 18 51\n9 20 87 51\n12 20 40 32\n4 11 34 11\n3 19 22 20\n19 19 53 5\n16 18 52 30\n5 19 52 71\n19 19 99 95\n14 18 15 28\n20 20 91 64\n15 16 55 47\n1 9 40 40\n9 17 93 82\n7 16 10 75\n1 15 100 24\n10 10 35 84\n1 2 4 7",
"output": "1090"
},
{
"input": "20 30\n20 20 43 41\n5 13 99 35\n9 15 79 12\n4 20 75 16\n20 20 4 94\n14 14 1 1\n5 5 4 92\n14 19 52 30\n19 20 61 14\n10 12 34 89\n11 15 27 12\n14 18 64 25\n11 14 37 14\n19 19 56 20\n19 20 61 11\n13 16 48 36\n14 16 82 73\n16 17 82 26\n1 5 55 91\n10 13 24 33\n3 19 91 70\n10 15 87 53\n3 5 92 80\n10 10 13 24\n9 9 38 20\n13 20 80 38\n5 10 71 23\n6 19 43 90\n13 20 10 55\n11 14 29 62",
"output": "1261"
},
{
"input": "20 30\n15 15 14 51\n17 20 3 20\n14 16 59 66\n14 15 48 22\n18 19 72 26\n13 14 60 72\n8 13 69 57\n4 12 3 82\n1 8 80 37\n18 19 40 33\n9 9 32 55\n13 15 67 5\n10 13 37 1\n19 19 39 11\n17 19 28 88\n8 19 88 87\n16 20 26 2\n18 18 11 46\n14 14 14 20\n15 15 78 100\n18 19 53 32\n12 13 59 66\n11 18 38 36\n5 8 14 97\n8 18 80 97\n6 19 81 17\n13 19 65 93\n8 10 77 3\n20 20 70 60\n17 17 28 35",
"output": "1003"
},
{
"input": "20 30\n5 10 38 50\n17 18 86 42\n4 13 91 90\n20 20 45 31\n3 3 16 11\n16 16 80 66\n19 19 96 26\n15 20 7 84\n9 18 45 36\n5 19 89 6\n9 9 4 58\n9 14 97 31\n6 12 74 90\n4 5 84 2\n12 19 92 48\n16 16 92 55\n9 15 88 38\n6 14 8 66\n14 17 71 91\n20 20 58 20\n8 18 5 47\n7 19 67 43\n19 19 88 80\n9 12 35 86\n4 4 82 22\n7 8 72 82\n8 10 61 92\n20 20 77 93\n15 19 66 20\n20 20 8 10",
"output": "911"
},
{
"input": "20 30\n1 20 49 91\n15 15 60 37\n14 14 3 79\n11 12 81 66\n8 12 71 31\n3 13 8 14\n2 10 11 35\n19 20 40 28\n12 14 6 75\n16 18 100 100\n20 20 89 74\n16 16 27 98\n18 18 21 24\n1 18 69 98\n7 13 70 57\n9 20 41 79\n17 17 75 75\n11 16 19 14\n1 15 62 59\n12 15 33 91\n3 17 10 79\n15 16 100 80\n10 16 5 5\n9 19 53 100\n9 18 65 42\n5 13 34 13\n6 13 61 47\n17 19 68 25\n5 5 42 59\n6 8 48 92",
"output": "492"
},
{
"input": "100 1\n22 59 287 173",
"output": "6574"
},
{
"input": "100 1\n8 31 93 267",
"output": "6408"
},
{
"input": "100 1\n72 82 727 390",
"output": "4290"
},
{
"input": "100 1\n14 25 343 50",
"output": "600"
},
{
"input": "100 1\n73 75 59 176",
"output": "528"
},
{
"input": "21 2\n19 20 253 233\n3 17 23 150",
"output": "2716"
},
{
"input": "47 18\n14 38 376 96\n21 34 749 32\n7 20 409 146\n41 41 740 9\n14 16 526 128\n38 47 518 147\n3 26 7 16\n25 31 155 75\n32 36 164 12\n5 33 436 150\n22 41 477 52\n4 13 166 6\n38 44 664 133\n2 33 452 16\n30 40 623 48\n37 37 250 122\n25 34 506 109\n36 38 716 78",
"output": "2091"
},
{
"input": "1 1\n1 1 1 1",
"output": "1"
},
{
"input": "1 1\n1 1 1000 1000",
"output": "1000"
}
] | 154 | 5,632,000 | 3.95101 | 52,168 |
103 | Russian Roulette | [
"constructive algorithms",
"greedy"
] | C. Russian Roulette | 2 | 256 | 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"
}
] | 186 | 307,200 | 0 | 52,289 |
723 | Lakes in Berland | [
"dfs and similar",
"dsu",
"graphs",
"greedy",
"implementation"
] | null | null | The map of Berland is a rectangle of the size *n*<=Γ<=*m*, which consists of cells of size 1<=Γ<=1. Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly *k* lakes in Berland. Note that the initial number of lakes on the map is not less than *k*. | The first line of the input contains three integers *n*, *m* and *k* (1<=β€<=*n*,<=*m*<=β€<=50, 0<=β€<=*k*<=β€<=50)Β β the sizes of the map and the number of lakes which should be left on the map.
The next *n* lines contain *m* characters each β the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least *k* lakes. | In the first line print the minimum number of cells which should be transformed from water to land.
In the next *n* lines print *m* symbols β the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data. | [
"5 4 1\n****\n*..*\n****\n**.*\n..**\n",
"3 3 0\n***\n*.*\n***\n"
] | [
"1\n****\n*..*\n****\n****\n..**\n",
"1\n***\n***\n***\n"
] | In the first example there are only two lakes β the first consists of the cells (2,β2) and (2,β3), the second consists of the cell (4,β3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean. | [
{
"input": "5 4 1\n****\n*..*\n****\n**.*\n..**",
"output": "1\n****\n*..*\n****\n****\n..**"
},
{
"input": "3 3 0\n***\n*.*\n***",
"output": "1\n***\n***\n***"
},
{
"input": "3 5 1\n.**.*\n*.*.*\n***..",
"output": "0\n.**.*\n*.*.*\n***.."
},
{
"input": "3 5 0\n.**.*\n*.*.*\n***..",
"output": "1\n.**.*\n***.*\n***.."
},
{
"input": "3 50 7\n***.********.*********************.**********.****\n*...**..*.**.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*..*\n****************.*.********.**********************",
"output": "8\n***.********.*********************.**********.****\n*...**..****.***.*.*******..*******.*.*.*.*.*.*..*\n****************.*.********.**********************"
},
{
"input": "50 3 4\n***\n*.*\n*.*\n*.*\n***\n***\n*.*\n***\n.**\n***\n..*\n***\n***\n*.*\n***\n*.*\n***\n***\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n*.*\n***\n***\n***\n*.*\n***\n***\n***\n*.*\n*.*\n*.*\n***\n***\n***\n***",
"output": "8\n***\n***\n***\n***\n***\n***\n***\n***\n.**\n***\n..*\n***\n***\n***\n***\n***\n***\n***\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n*.*\n***\n***\n***\n***\n***\n***\n***\n*.*\n*.*\n*.*\n***\n***\n***\n***"
},
{
"input": "1 1 0\n.",
"output": "0\n."
},
{
"input": "1 1 0\n*",
"output": "0\n*"
}
] | 31 | 0 | 0 | 52,471 |
|
0 | none | [
"none"
] | null | null | Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people.
But wait, something is still known, because that day a record was achieved β *M* simultaneous users online! In addition, Polycarpus believes that if a user made a request at second *s*, then he was online for *T* seconds after that, that is, at seconds *s*, *s*<=+<=1, *s*<=+<=2, ..., *s*<=+<=*T*<=-<=1. So, the user's time online can be calculated as the union of time intervals of the form [*s*,<=*s*<=+<=*T*<=-<=1] over all times *s* of requests from him.
Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that:
- the number of different users online did not exceed *M* at any moment, - at some second the number of distinct users online reached value *M*, - the total number of users (the number of distinct identifiers) was as much as possible.
Help Polycarpus cope with the test. | The first line contains three integers *n*, *M* and *T* (1<=β€<=*n*,<=*M*<=β€<=20<=000, 1<=β€<=*T*<=β€<=86400) β the number of queries, the record number of online users and the time when the user was online after a query was sent. Next *n* lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [*s*,<=*s*<=+<=*T*<=-<=1] are within one 24-hour range (from 00:00:00 to 23:59:59). | In the first line print number *R* β the largest possible number of distinct users. The following *n* lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to *R*. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes). | [
"4 2 10\n17:05:53\n17:05:58\n17:06:01\n22:39:47\n",
"1 2 86400\n00:00:00\n"
] | [
"3\n1\n2\n2\n3\n",
"No solution\n"
] | Consider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because *M*β=β2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 β from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 β from 22:39:47 to 22:39:56.
In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.) | [] | 31 | 0 | 0 | 52,505 |
|
439 | Devu and Partitioning of the Array | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?
Given an array consisting of distinct integers. Is it possible to partition the whole array into *k* disjoint non-empty parts such that *p* of the parts have even sum (each of them must have even sum) and remaining *k* - *p* have odd sum? (note that parts need not to be continuous).
If it is possible to partition the array, also give any possible way of valid partitioning. | The first line will contain three space separated integers *n*, *k*, *p* (1<=β€<=*k*<=β€<=*n*<=β€<=105;Β 0<=β€<=*p*<=β€<=*k*). The next line will contain *n* space-separated distinct integers representing the content of array *a*: *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109). | In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).
If the required partition exists, print *k* lines after the first line. The *i**th* of them should contain the content of the *i**th* part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly *p* parts with even sum, each of the remaining *k* - *p* parts must have odd sum.
As there can be multiple partitions, you are allowed to print any valid partition. | [
"5 5 3\n2 6 10 5 9\n",
"5 5 3\n7 14 2 9 5\n",
"5 3 1\n1 2 3 7 5\n"
] | [
"YES\n1 9\n1 5\n1 10\n1 6\n1 2\n",
"NO\n",
"YES\n3 5 1 3\n1 7\n1 2\n"
] | none | [
{
"input": "5 5 3\n2 6 10 5 9",
"output": "YES\n1 9\n1 5\n1 10\n1 6\n1 2"
},
{
"input": "5 5 3\n7 14 2 9 5",
"output": "NO"
},
{
"input": "5 3 1\n1 2 3 7 5",
"output": "YES\n3 5 1 3\n1 7\n1 2"
},
{
"input": "10 5 3\n194757070 828985446 11164 80016 84729 117765558 111730436 164044532 419732980 48834",
"output": "NO"
},
{
"input": "10 6 3\n861947514 34945 190135645 68731 44833 387988147 84308862 878151920 458358978 809653252",
"output": "YES\n5 387988147 861947514 84308862 34945 190135645\n1 44833\n1 68731\n1 809653252\n1 458358978\n1 878151920"
},
{
"input": "10 8 3\n677037706 41099140 89128206 168458947 367939060 940344093 191391519 981938946 31319 34929915",
"output": "YES\n3 34929915 677037706 41099140\n1 31319\n1 191391519\n1 940344093\n1 168458947\n1 981938946\n1 367939060\n1 89128206"
},
{
"input": "10 8 4\n214605891 246349108 626595204 63889 794527783 83684156 5535 865709352 262484651 157889982",
"output": "NO"
},
{
"input": "10 6 3\n223143676 316703192 5286 408323576 61758 566101388 9871840 93989 91890 99264208",
"output": "NO"
},
{
"input": "2 2 1\n409447178 258805801",
"output": "YES\n1 258805801\n1 409447178"
},
{
"input": "2 1 1\n29161 15829",
"output": "YES\n2 15829 29161"
},
{
"input": "3 3 1\n357071129 476170324 503481367",
"output": "YES\n1 503481367\n1 357071129\n1 476170324"
},
{
"input": "3 3 1\n357071129 476170324 503481367",
"output": "YES\n1 503481367\n1 357071129\n1 476170324"
},
{
"input": "2 1 1\n29161 15829",
"output": "YES\n2 15829 29161"
},
{
"input": "23 22 3\n777717359 54451 123871650 211256633 193354035 935466677 800874233 532974165 62256 6511 3229 757421727 371493777 268999168 82355 22967 678259053 886134047 207070129 122416584 79851 35753 730872007",
"output": "YES\n2 730872007 123871650\n1 35753\n1 79851\n1 207070129\n1 886134047\n1 678259053\n1 22967\n1 82355\n1 371493777\n1 757421727\n1 3229\n1 6511\n1 532974165\n1 800874233\n1 935466677\n1 193354035\n1 211256633\n1 54451\n1 777717359\n1 122416584\n1 268999168\n1 62256"
},
{
"input": "16 9 9\n826588597 70843 528358243 60844 636968393 862405463 58232 69241 617006886 903909155 973050249 9381 49031 40100022 62141 43805",
"output": "YES\n3 40100022 826588597 70843\n1 617006886\n1 58232\n1 60844\n2 43805 62141\n2 49031 9381\n2 973050249 903909155\n2 69241 862405463\n2 636968393 528358243"
},
{
"input": "5 2 2\n316313049 24390603 595539594 514135024 39108",
"output": "YES\n4 39108 595539594 316313049 24390603\n1 514135024"
},
{
"input": "5 2 1\n12474 117513621 32958 767146609 20843",
"output": "YES\n4 20843 12474 117513621 767146609\n1 32958"
},
{
"input": "5 4 1\n387119493 716009972 88510 375210205 910834347",
"output": "YES\n2 910834347 716009972\n1 375210205\n1 387119493\n1 88510"
},
{
"input": "5 4 3\n674318396 881407702 882396010 208141498 53145",
"output": "YES\n2 53145 674318396\n1 208141498\n1 882396010\n1 881407702"
},
{
"input": "3 2 1\n976825506 613159225 249024714",
"output": "YES\n2 613159225 976825506\n1 249024714"
},
{
"input": "4 1 1\n173508914 11188 90766233 20363",
"output": "YES\n4 11188 173508914 90766233 20363"
},
{
"input": "30 24 12\n459253071 24156 64054 270713791 734796619 379920883 429646748 332144982 20929 27685 53253 82047732 172442017 34241 880121331 890223629 974692 954036632 68638567 972921811 421106382 64615 819330514 179630214 608594496 802986133 231010377 184513476 73143 93045",
"output": "YES\n7 93045 459253071 270713791 734796619 379920883 20929 27685\n1 73143\n1 231010377\n1 802986133\n1 64615\n1 972921811\n1 68638567\n1 890223629\n1 880121331\n1 34241\n1 172442017\n1 53253\n1 184513476\n1 608594496\n1 179630214\n1 819330514\n1 421106382\n1 954036632\n1 974692\n1 82047732\n1 332144982\n1 429646748\n1 64054\n1 24156"
},
{
"input": "9 5 1\n91623 466261329 311727429 18189 42557 22943 66177 473271749 62622",
"output": "YES\n5 473271749 91623 466261329 311727429 18189\n1 66177\n1 22943\n1 42557\n1 62622"
},
{
"input": "4 1 1\n266639563 36517 172287193 166673809",
"output": "YES\n4 166673809 172287193 266639563 36517"
},
{
"input": "5 2 2\n19571 180100775 421217758 284511211 49475",
"output": "YES\n3 421217758 19571 180100775\n2 49475 284511211"
},
{
"input": "4 2 2\n736788713 82230 66800 37791827",
"output": "YES\n3 66800 736788713 37791827\n1 82230"
},
{
"input": "5 1 1\n33889 469945850 40673 939970023 776172319",
"output": "YES\n5 469945850 33889 40673 939970023 776172319"
},
{
"input": "1 1 0\n2",
"output": "NO"
},
{
"input": "1 1 0\n3",
"output": "YES\n1 3"
},
{
"input": "1 1 1\n2",
"output": "YES\n1 2"
},
{
"input": "1 1 1\n3",
"output": "NO"
},
{
"input": "2 2 2\n2 3",
"output": "NO"
},
{
"input": "2 2 2\n2 4",
"output": "YES\n1 4\n1 2"
},
{
"input": "2 2 1\n3 2",
"output": "YES\n1 3\n1 2"
},
{
"input": "4 2 0\n3 5 7 9",
"output": "YES\n3 9 3 5\n1 7"
},
{
"input": "3 2 0\n1 3 2",
"output": "YES\n2 3 2\n1 1"
},
{
"input": "2 1 1\n2 4",
"output": "YES\n2 4 2"
},
{
"input": "7 3 0\n1 3 5 7 9 11 13",
"output": "YES\n5 13 1 3 5 7\n1 11\n1 9"
},
{
"input": "8 4 4\n1 3 5 7 9 11 13 15",
"output": "YES\n2 15 13\n2 11 9\n2 7 5\n2 3 1"
},
{
"input": "2 1 1\n1 3",
"output": "YES\n2 3 1"
}
] | 482 | 16,076,800 | 3 | 52,519 |
|
756 | Byteland coins | [
"combinatorics",
"dp",
"math"
] | null | null | There are *n* types of coins in Byteland. Conveniently, the denomination of the coin type *k* divides the denomination of the coin type *k*<=+<=1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types *k*<=+<=1 and *k* equals *a**k*. It is known that for each *x* there are at most 20 coin types of denomination *x*.
Byteasar has *b**k* coins of type *k* with him, and he needs to pay exactly *m* tugricks. It is known that Byteasar never has more than 3Β·105 coins with him. Byteasar want to know how many ways there are to pay exactly *m* tugricks. Two ways are different if there is an integer *k* such that the amount of coins of type *k* differs in these two ways. As all Byteland citizens, Byteasar wants to know the number of ways modulo 109<=+<=7. | The first line contains single integer *n* (1<=β€<=*n*<=β€<=3Β·105)Β β the number of coin types.
The second line contains *n*<=-<=1 integers *a*1, *a*2, ..., *a**n*<=-<=1 (1<=β€<=*a**k*<=β€<=109)Β β the ratios between the coin types denominations. It is guaranteed that for each *x* there are at most 20 coin types of denomination *x*.
The third line contains *n* non-negative integers *b*1, *b*2, ..., *b**n*Β β the number of coins of each type Byteasar has. It is guaranteed that the sum of these integers doesn't exceed 3Β·105.
The fourth line contains single integer *m* (0<=β€<=*m*<=<<=1010000)Β β the amount in tugricks Byteasar needs to pay. | Print single integerΒ β the number of ways to pay exactly *m* tugricks modulo 109<=+<=7. | [
"1\n\n4\n2\n",
"2\n1\n4 4\n2\n",
"3\n3 3\n10 10 10\n17\n"
] | [
"1\n",
"3\n",
"6\n"
] | In the first example Byteasar has 4 coins of denomination 1, and he has to pay 2 tugricks. There is only one way.
In the second example Byteasar has 4 coins of each of two different types of denomination 1, he has to pay 2 tugricks. There are 3 ways: pay one coin of the first type and one coin of the other, pay two coins of the first type, and pay two coins of the second type.
In the third example the denominations are equal to 1, 3, 9. | [] | 46 | 4,608,000 | 0 | 52,647 |
|
758 | Geometrical Progression | [
"brute force",
"math",
"number theory"
] | null | null | For given *n*, *l* and *r* find the number of distinct geometrical progression, each of which contains *n* distinct integers not less than *l* and not greater than *r*. In other words, for each progression the following must hold: *l*<=β€<=*a**i*<=β€<=*r* and *a**i*<=β <=*a**j* , where *a*1,<=*a*2,<=...,<=*a**n* is the geometrical progression, 1<=β€<=*i*,<=*j*<=β€<=*n* and *i*<=β <=*j*.
Geometrical progression is a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* where each term after first is found by multiplying the previous one by a fixed non-zero number *d* called the common ratio. Note that in our task *d* may be non-integer. For example in progression 4,<=6,<=9, common ratio is .
Two progressions *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* are considered different, if there is such *i* (1<=β€<=*i*<=β€<=*n*) that *a**i*<=β <=*b**i*. | The first and the only line cotains three integers *n*, *l* and *r* (1<=β€<=*n*<=β€<=107,<=1<=β€<=*l*<=β€<=*r*<=β€<=107). | Print the integer *K*Β β is the answer to the problem. | [
"1 1 10\n",
"2 6 9\n",
"3 1 10\n",
"3 3 10\n"
] | [
"10",
"12",
"8",
"2"
] | These are possible progressions for the first test of examples:
- 1; - 2; - 3; - 4; - 5; - 6; - 7; - 8; - 9; - 10.
These are possible progressions for the second test of examples:
- 6,β7; - 6,β8; - 6,β9; - 7,β6; - 7,β8; - 7,β9; - 8,β6; - 8,β7; - 8,β9; - 9,β6; - 9,β7; - 9,β8.
These are possible progressions for the third test of examples:
- 1,β2,β4; - 1,β3,β9; - 2,β4,β8; - 4,β2,β1; - 4,β6,β9; - 8,β4,β2; - 9,β3,β1; - 9,β6,β4.
These are possible progressions for the fourth test of examples:
- 4,β6,β9; - 9,β6,β4. | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 6 9",
"output": "12"
},
{
"input": "3 1 10",
"output": "8"
},
{
"input": "3 3 10",
"output": "2"
},
{
"input": "1 25 845",
"output": "821"
},
{
"input": "2 25 845",
"output": "673220"
},
{
"input": "3 25 845",
"output": "2150"
},
{
"input": "4 25 845",
"output": "324"
},
{
"input": "5 25 845",
"output": "84"
},
{
"input": "6 25 845",
"output": "10"
},
{
"input": "7 25 845",
"output": "2"
},
{
"input": "8 25 845",
"output": "0"
},
{
"input": "1 1 10000000",
"output": "10000000"
},
{
"input": "2 1 10000000",
"output": "99999990000000"
},
{
"input": "3 1 10000000",
"output": "89371160"
},
{
"input": "4 1 10000000",
"output": "7299492"
},
{
"input": "5 1 10000000",
"output": "2209708"
},
{
"input": "6 1 10000000",
"output": "875204"
},
{
"input": "7 1 10000000",
"output": "384900"
},
{
"input": "8 1 10000000",
"output": "178350"
},
{
"input": "9 1 10000000",
"output": "85060"
},
{
"input": "10 1 10000000",
"output": "41286"
},
{
"input": "11 1 10000000",
"output": "20250"
},
{
"input": "12 1 10000000",
"output": "9996"
},
{
"input": "13 1 10000000",
"output": "4954"
},
{
"input": "14 1 10000000",
"output": "2464"
},
{
"input": "15 1 10000000",
"output": "1228"
},
{
"input": "16 1 10000000",
"output": "610"
},
{
"input": "17 1 10000000",
"output": "304"
},
{
"input": "18 1 10000000",
"output": "152"
},
{
"input": "19 1 10000000",
"output": "76"
},
{
"input": "20 1 10000000",
"output": "38"
},
{
"input": "21 1 10000000",
"output": "18"
},
{
"input": "22 1 10000000",
"output": "8"
},
{
"input": "23 1 10000000",
"output": "4"
},
{
"input": "24 1 10000000",
"output": "2"
},
{
"input": "25 1 10000000",
"output": "0"
},
{
"input": "123456 1 10000000",
"output": "0"
},
{
"input": "10000000 1 10000000",
"output": "0"
},
{
"input": "1 10000000 10000000",
"output": "1"
},
{
"input": "2 10000000 10000000",
"output": "0"
},
{
"input": "10000000 10000000 10000000",
"output": "0"
},
{
"input": "1 5000000 10000000",
"output": "5000001"
},
{
"input": "2 5000000 10000000",
"output": "25000005000000"
},
{
"input": "3 5000000 10000000",
"output": "7065044"
},
{
"input": "4 5000000 10000000",
"output": "117250"
},
{
"input": "5 5000000 10000000",
"output": "4674"
},
{
"input": "6 5000000 10000000",
"output": "194"
},
{
"input": "7 5000000 10000000",
"output": "8"
},
{
"input": "8 5000000 10000000",
"output": "0"
},
{
"input": "1000 5000000 10000000",
"output": "0"
},
{
"input": "1 100 1000000",
"output": "999901"
},
{
"input": "2 100 1000000",
"output": "999801009900"
},
{
"input": "3 100 1000000",
"output": "7474368"
},
{
"input": "4 100 1000000",
"output": "715006"
},
{
"input": "5 100 1000000",
"output": "217914"
},
{
"input": "6 100 1000000",
"output": "86100"
},
{
"input": "7 100 1000000",
"output": "37648"
},
{
"input": "8 100 1000000",
"output": "17266"
},
{
"input": "9 100 1000000",
"output": "8066"
},
{
"input": "10 100 1000000",
"output": "3814"
},
{
"input": "11 100 1000000",
"output": "1786"
},
{
"input": "12 100 1000000",
"output": "788"
},
{
"input": "13 100 1000000",
"output": "292"
},
{
"input": "14 100 1000000",
"output": "46"
},
{
"input": "15 100 1000000",
"output": "0"
},
{
"input": "16 100 1000000",
"output": "0"
},
{
"input": "17 100 1000000",
"output": "0"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10000000 1 1",
"output": "0"
},
{
"input": "1 123 456789",
"output": "456667"
},
{
"input": "2 123 456789",
"output": "208544292222"
},
{
"input": "3 123 456789",
"output": "3172916"
},
{
"input": "4 123 456789",
"output": "321710"
},
{
"input": "5 123 456789",
"output": "98144"
},
{
"input": "6 123 456789",
"output": "38632"
},
{
"input": "7 123 456789",
"output": "16734"
},
{
"input": "8 123 456789",
"output": "7566"
},
{
"input": "9 123 456789",
"output": "3480"
},
{
"input": "10 123 456789",
"output": "1588"
},
{
"input": "11 123 456789",
"output": "662"
},
{
"input": "12 123 456789",
"output": "206"
},
{
"input": "13 123 456789",
"output": "0"
},
{
"input": "1 1 5000000",
"output": "5000000"
},
{
"input": "2 1 5000000",
"output": "24999995000000"
},
{
"input": "3 1 5000000",
"output": "42582108"
},
{
"input": "4 1 5000000",
"output": "3640680"
},
{
"input": "5 1 5000000",
"output": "1104328"
},
{
"input": "6 1 5000000",
"output": "437484"
},
{
"input": "7 1 5000000",
"output": "192426"
},
{
"input": "8 1 5000000",
"output": "89168"
},
{
"input": "9 1 5000000",
"output": "42518"
},
{
"input": "10 1 5000000",
"output": "20638"
},
{
"input": "11 1 5000000",
"output": "10116"
},
{
"input": "12 1 5000000",
"output": "4998"
},
{
"input": "13 1 5000000",
"output": "2476"
},
{
"input": "14 1 5000000",
"output": "1232"
},
{
"input": "15 1 5000000",
"output": "614"
},
{
"input": "16 1 5000000",
"output": "304"
},
{
"input": "17 1 5000000",
"output": "152"
},
{
"input": "18 1 5000000",
"output": "76"
},
{
"input": "19 1 5000000",
"output": "38"
},
{
"input": "20 1 5000000",
"output": "18"
},
{
"input": "21 1 5000000",
"output": "8"
},
{
"input": "22 1 5000000",
"output": "4"
},
{
"input": "23 1 5000000",
"output": "2"
},
{
"input": "24 1 5000000",
"output": "0"
},
{
"input": "25 1 5000000",
"output": "0"
},
{
"input": "2 1 1",
"output": "0"
}
] | 30 | 0 | 0 | 52,712 |
|
116 | Little Pigs and Wolves | [
"greedy",
"implementation"
] | null | null | Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=Γ<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf.
A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs.
They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf.
What is the maximum number of little pigs that may be eaten by the wolves? | The first line contains integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=10) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow *n* lines containing *m* characters each β that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf.
It is guaranteed that there will be at most one wolf adjacent to any little pig. | Print a single number β the maximal number of little pigs that may be eaten by the wolves. | [
"2 3\nPPW\nW.P\n",
"3 3\nP.W\n.P.\nW.P\n"
] | [
"2\n",
"0\n"
] | In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows. | [
{
"input": "2 3\nPPW\nW.P",
"output": "2"
},
{
"input": "3 3\nP.W\n.P.\nW.P",
"output": "0"
},
{
"input": "1 1\nP",
"output": "0"
},
{
"input": "2 6\nWW..WW\n.PPPP.",
"output": "2"
},
{
"input": "6 2\n.W\n.W\n.P\nWP\n.P\nPW",
"output": "3"
},
{
"input": "2 10\nW..WWP.P.P\nW..PP.WWP.",
"output": "3"
},
{
"input": "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP",
"output": "2"
},
{
"input": "3 4\nWPPW\n.P..\nPWW.",
"output": "3"
},
{
"input": "4 3\n.WW\n..P\nP.P\nPWW",
"output": "3"
},
{
"input": "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW",
"output": "6"
},
{
"input": "10 3\n...\nPWW\n..P\n..P\nP.P\nWP.\nPPW\n..W\nW..\nWPP",
"output": "5"
},
{
"input": "4 8\n..PW..WW\nWWPP.PP.\nP...PW.P\nP.WW...P",
"output": "5"
},
{
"input": "8 4\nP.WW\nW..P\nP..P\nP.WW\n..P.\nW.P.\nWP.W\nP..P",
"output": "6"
},
{
"input": "1 1\nW",
"output": "0"
},
{
"input": "4 10\n..P.PW.P.P\nP.WP.W..WP\nW..P.P..WP\nW.PWW.P.P.",
"output": "7"
},
{
"input": "10 4\nWPPP\nP.PW\n...W\nW..P\n..W.\n.PP.\nW..P\nW.PW\n..P.\nPPW.",
"output": "6"
},
{
"input": "5 1\n.\nP\n.\n.\nW",
"output": "0"
},
{
"input": "5 10\nP.PPWWP.PP\n.W....P.PP\nPWPP..WW..\n...W..P.P.\nWP.W...PWW",
"output": "7"
},
{
"input": "10 5\n..PWW\nWWP.P\n.PP..\nP..WW\nPW...\n.W..P\n..P.W\nP.PP.\nW..WP\nWPPP.",
"output": "8"
},
{
"input": "6 5\n..WP.\nWP..W\nW.PP.\n.PWW.\nP.PPP\nWP..W",
"output": "6"
},
{
"input": "5 6\nP...PW\n.WWP.W\n.P...P\nWP..W.\nWPPPWP",
"output": "7"
},
{
"input": "6 10\nPPP.WW..PW\n.W.....WP.\n.W.PP..WP.\n.PP..WPP.P\nW.PW.P.PWW\nWP.P..P.P.",
"output": "10"
},
{
"input": "10 6\n.WW.PW\n......\nWP..W.\nPPWP.P\n.PW.PW\nPP.P.W\nP.PWPP\nW..W.P\nWPP..W\n.PWP.W",
"output": "11"
},
{
"input": "7 3\nWPP\nW.P\n...\nPWP\nPW.\n..P\n..W",
"output": "4"
},
{
"input": "3 7\nWP...PW\n.PW.P..\nPPW.PW.",
"output": "5"
},
{
"input": "7 10\nW..W.PWW.P\nW.P.P.PP.W\nP...W.....\nPWPPW..WW.\n....PPP..P\nWP.WPP.P.P\nPP..PWP.WW",
"output": "11"
},
{
"input": "10 7\n.PW..WP\nW...PW.\n..PW...\nPW..PP.\n.W.P.WW\n.P.P...\nP.PPW..\n.PW...P\nW.P.PPP\nW.PPWPP",
"output": "10"
},
{
"input": "8 8\nWP.W...P\nW.P..WW.\nP.W.P.P.\nPPPPPPPP\nWW..WP.W\nP.P.PP..\n..WW..W.\nPP....W.",
"output": "9"
},
{
"input": "8 10\nPWW..P..W.\nPP.PP...W.\nWP..PWW.P.\nP.P.....P.\nPPW.P.P.WW\nPPP.WW.PP.\nW.P....P.P\n..WWPPW..W",
"output": "12"
},
{
"input": "10 8\n.PPW.PWW\nW.PWP.P.\nWP..PP..\n..WP.PPP\n..PP.WW.\n.WP...P.\n..PWW..W\nW.P..PPW\n...P...P\nPWP.WWP.",
"output": "12"
},
{
"input": "9 8\nPP..W..W\n.PP.W..W\n..W...PP\nWP.P.WW.\nW..W.P..\nP.PP..P.\n...PW.PP\n.WPPW..W\nPWP.PPPP",
"output": "12"
},
{
"input": "8 9\nPWWPPW..W\nP.P..WP.P\nW..WPP.PP\nP.PP....W\n.....WWP.\nP.WWP.P..\nW......WW\nPP.PWPP.P",
"output": "13"
},
{
"input": "10 10\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP",
"output": "0"
},
{
"input": "9 10\nW.PPWW..P.\nW.P.....WP\nP..W......\n..P.PP.W.P\n.PW.P..W..\n..P...PPPP\nPPP.W..PPP\nWW.PW...PP\n.PPP..WW.P",
"output": "8"
},
{
"input": "10 9\nWWP.P.WPP\n..PWP.P.W\n....PWP..\nWW...P.WP\n.P.WP..W.\nPP...W.P.\nP.W..WP.W\n.PWPP..P.\n.PPPPPWW.\nPW..W..PP",
"output": "15"
},
{
"input": "10 1\n.\nW\nW\nP\nP\n.\n.\n.\nW\nP",
"output": "2"
},
{
"input": "1 10\nP.PW.PW..W",
"output": "2"
},
{
"input": "10 10\nPWPP...PPW\n.P.W...W..\nW.P.PW....\nP.P.PW..WP\nPP.W.PP.P.\n.P.P..WP.W\n.WW.PPP..P\n..P...PPP.\nP.P..WW..W\n.WWP...PPW",
"output": "16"
},
{
"input": "10 10\n.PW...P.PW\n....W..PPW\nWWP.W..P.P\n.P..PP.P..\n...W...WW.\nPWP..W....\nPW...W..PW\n.P..P.PP.P\nPPPPWP..W.\nPPPPP.W.PP",
"output": "11"
},
{
"input": "10 10\nPP..PPWPPW\nPPPPPPPP..\n.PPPPPPP.P\nPPPPPPPPPP\nPWP.PPP.PP\nPW.PP.PPPP\nPPPPPP.PPW\n..PPWPPP.P\nWPPPPPPPPP\nWP.WPPPWPP",
"output": "10"
},
{
"input": "10 10\nPPPPPPPPPP\nPPPPPPPWPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP",
"output": "1"
},
{
"input": "10 10\nPPPPPPPPWP\nPPPWPPPPPP\nPPPPPPPPPP\nPWWPPWPPPP\nPPPPPPPPPP\nPPPPWPPPPP\nPPPPPPPPPP\nPPPPPPWPPW\nPPPPPPPPPP\nPPWPPPPPWP",
"output": "10"
},
{
"input": "10 10\n.PWWP..W..\n.....W...W\nWP........\nW...WP....\nP.W..P..WW\n..W...WP.P\nW...W.....\n....WP..P.\n.W....W..W\n.W....W..W",
"output": "8"
},
{
"input": "10 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW",
"output": "0"
},
{
"input": "10 10\nW..W..W...\nW..P..W...\n..W.....WW\n....WW....\nWW.....W..\n.........W\n..WW......\n.......WW.\nW.........\nW..WW....W",
"output": "1"
},
{
"input": "10 10\n..P..WWP.W\nPP.WPPPPPP\nWWPP.PPWPP\nPPPPW..PPW\nPP.PW.P.PW\nWW..PPWWP.\n..PW...PP.\n.PPPP.PPPW\nPP.PWP..P.\nPWPPP..WWP",
"output": "20"
},
{
"input": "10 10\n......W...\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n........P.",
"output": "0"
},
{
"input": "10 10\n.P.PPPP..W\nPWW.PPWPPW\n...PPP.P..\nW..P...WP.\n.PPWPP.W..\n...PPWPPPP\nWP..PW..W.\nPPW.....P.\nP.P...PP.W\nWPPWW.PPPW",
"output": "14"
},
{
"input": "10 10\nW...W.....\n..W...WW..\n.........W\n...WW....W\nWW.....W..\n.....W....\n..W.....W.\nW...W.....\nW.....W..W\n..WW..W..W",
"output": "0"
},
{
"input": "10 10\nWW..W...WW\n....W.....\n......WW..\n.W.....P..\n.W...W..WW\n...W......\nW..W......\nW....WW..P\nP.........\n...WW...WW",
"output": "2"
},
{
"input": "10 10\nP.PPP.PP.P\nPPP.PPP.P.\nP.PPPP..PW\nP.PPP.PP.P\nPPPPPP.P.P\nPPPP.PP.P.\n.PPWPPPPP.\nPPP...PPPP\nPPP.PPPP.P\n.WPPPP.P.P",
"output": "3"
},
{
"input": "1 4\nW..P",
"output": "0"
},
{
"input": "10 10\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W",
"output": "0"
},
{
"input": "10 10\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP",
"output": "9"
},
{
"input": "10 10\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW",
"output": "50"
},
{
"input": "4 1\n.\nW\nP\n.",
"output": "1"
},
{
"input": "1 10\nP..W.PPWW.",
"output": "1"
},
{
"input": "10 1\nP\nP\nW\nW\n.\nP\n.\n.\n.\nW",
"output": "1"
},
{
"input": "1 1\n.",
"output": "0"
},
{
"input": "10 10\nPPPWPPPWPP\nPWPPPWPPPP\nPPPPPPPPPP\nWPPWPPWPPW\nPPPPPPPPPP\nPWPPWPPWPP\nPPPPPPPPPP\nPPWPPWPPWP\nPPPPPPPPPP\nWPPWPPWPPW",
"output": "18"
},
{
"input": "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP",
"output": "18"
},
{
"input": "4 4\n.P..\n.W..\n.P..\n..W.",
"output": "1"
},
{
"input": "4 1\n.\n.\nW\nP",
"output": "1"
},
{
"input": "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP",
"output": "18"
},
{
"input": "3 3\nPWP\n...\nW..",
"output": "1"
},
{
"input": "2 3\nWWP\nPPP",
"output": "2"
}
] | 0 | 0 | -1 | 52,741 |
|
721 | Maxim and Array | [
"constructive algorithms",
"data structures",
"greedy",
"math"
] | null | null | Recently Maxim has found an array of *n* integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer *x* and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer *i* (1<=β€<=*i*<=β€<=*n*) and replaces the *i*-th element of array *a**i* either with *a**i*<=+<=*x* or with *a**i*<=-<=*x*. Please note that the operation may be applied more than once to the same position.
Maxim is a curious minimalis, thus he wants to know what is the minimum value that the product of all array elements (i.e. ) can reach, if Maxim would apply no more than *k* operations to it. Please help him in that. | The first line of the input contains three integers *n*,<=*k* and *x* (1<=β€<=*n*,<=*k*<=β€<=200<=000,<=1<=β€<=*x*<=β€<=109)Β β the number of elements in the array, the maximum number of operations and the number invented by Maxim, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* ()Β β the elements of the array found by Maxim. | Print *n* integers *b*1,<=*b*2,<=...,<=*b**n* in the only lineΒ β the array elements after applying no more than *k* operations to the array. In particular, should stay true for every 1<=β€<=*i*<=β€<=*n*, but the product of all array elements should be minimum possible.
If there are multiple answers, print any of them. | [
"5 3 1\n5 4 3 5 2\n",
"5 3 1\n5 4 3 5 5\n",
"5 3 1\n5 4 4 5 5\n",
"3 2 7\n5 4 2\n"
] | [
"5 4 3 5 -1 \n",
"5 4 0 5 5 \n",
"5 1 4 5 5 \n",
"5 11 -5 \n"
] | none | [
{
"input": "5 3 1\n5 4 3 5 2",
"output": "5 4 3 5 -1 "
},
{
"input": "5 3 1\n5 4 3 5 5",
"output": "5 4 0 5 5 "
},
{
"input": "5 3 1\n5 4 4 5 5",
"output": "5 1 4 5 5 "
},
{
"input": "3 2 7\n5 4 2",
"output": "5 11 -5 "
},
{
"input": "100 1 1\n-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2",
"output": "-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2 "
},
{
"input": "100 5 100\n-45 -36 -55 -96 -49 8 -88 -87 -82 51 27 -33 -65 0 -1 -42 -58 -19 -11 77 -54 14 -49 -90 -35 -9 -2 -48 0 -21 44 22 37 -32 -81 64 28 85 -77 44 18 -74 -50 62 8 -74 41 -15 -91 -93 -2 57 -12 2 -2 -90 84 6 -62 -14 72 85 86 -71 -59 57 -89 -4 78 56 56 24 -15 -78 27 -30 -31 -52 -92 50 43 85 -79 -14 -96 -1 -40 -7 16 18 99 -9 27 6 -96 -36 51 68 -17 55",
"output": "-45 -36 -55 -96 -49 8 -88 -87 -82 51 27 -33 -65 -100 -101 -42 -58 -19 -11 77 -54 14 -49 -90 -35 -9 -102 -48 100 -21 44 22 37 -32 -81 64 28 85 -77 44 18 -74 -50 62 8 -74 41 -15 -91 -93 -2 57 -12 2 -2 -90 84 6 -62 -14 72 85 86 -71 -59 57 -89 -4 78 56 56 24 -15 -78 27 -30 -31 -52 -92 50 43 85 -79 -14 -96 -101 -40 -7 16 18 99 -9 27 6 -96 -36 51 68 -17 55 "
},
{
"input": "4 35529 390662471\n7178385 -402086 21850337 -1012896",
"output": "3469871245807 3470254327807 3469885917759 -3469865080318 "
},
{
"input": "2 176474 610141845\n-1063752 -6637683",
"output": "53837084913513 -53837092614948 "
},
{
"input": "1 157330 640126408\n-1723747",
"output": "-100711089494387 "
},
{
"input": "100 21063 1\n-2 -1 -1 -2 -1 -2 -1 0 0 -2 0 0 0 0 0 0 0 -1 -1 -2 2 2 0 2 2 2 2 0 1 1 2 1 2 1 0 1 2 2 0 2 0 2 1 1 2 1 0 1 1 0 1 0 0 0 0 0 0 2 1 0 2 2 0 2 0 1 1 2 1 2 2 1 1 1 1 1 0 2 2 2 2 2 2 0 0 0 0 0 2 1 0 1 0 0 2 1 0 2 0 0",
"output": "-212 -212 -212 -212 -212 -212 -212 212 212 -212 212 212 212 212 212 212 212 -212 -212 -212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 "
},
{
"input": "1 2 1000000000\n-1000000000",
"output": "-3000000000 "
},
{
"input": "2 1 1000\n-1000000000 1000000000",
"output": "-1000001000 1000000000 "
},
{
"input": "5 200000 1000000000\n1 2 3 4 5",
"output": "-39999999999999 40000000000002 40000000000003 40000000000004 40000000000005 "
},
{
"input": "10 200000 1000000000\n1 5 2 6890 321 6 8 -123 9 10",
"output": "20000000000001 20000000000005 20000000000002 20000000006890 20000000000321 20000000000006 20000000000008 -20000000000123 20000000000009 20000000000010 "
},
{
"input": "4 1 1\n-2 -2 1 1",
"output": "-2 -2 0 1 "
}
] | 826 | 24,576,000 | 3 | 52,830 |
|
370 | Berland Bingo | [
"implementation"
] | null | null | Lately, a national version of a bingo game has become very popular in Berland. There are *n* players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the *i*-th player contains *m**i* numbers.
During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.
You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not. | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of the players. Then follow *n* lines, each line describes a player's card. The line that describes a card starts from integer *m**i* (1<=β€<=*m**i*<=β€<=100) that shows how many numbers the *i*-th player's card has. Then follows a sequence of integers *a**i*,<=1,<=*a**i*,<=2,<=...,<=*a**i*,<=*m**i* (1<=β€<=*a**i*,<=*k*<=β€<=100) β the numbers on the *i*-th player's card. The numbers in the lines are separated by single spaces.
It is guaranteed that all the numbers on each card are distinct. | Print *n* lines, the *i*-th line must contain word "YES" (without the quotes), if the *i*-th player can win, and "NO" (without the quotes) otherwise. | [
"3\n1 1\n3 2 4 1\n2 10 11\n",
"2\n1 1\n1 1\n"
] | [
"YES\nNO\nYES\n",
"NO\nNO\n"
] | none | [
{
"input": "3\n1 1\n3 2 4 1\n2 10 11",
"output": "YES\nNO\nYES"
},
{
"input": "2\n1 1\n1 1",
"output": "NO\nNO"
},
{
"input": "1\n1 1",
"output": "YES"
},
{
"input": "2\n1 2\n1 3",
"output": "YES\nYES"
},
{
"input": "2\n1 1\n2 1 2",
"output": "YES\nNO"
},
{
"input": "2\n2 1 2\n1 1",
"output": "NO\nYES"
},
{
"input": "2\n3 5 21 7\n6 15 5 100 21 7 17",
"output": "YES\nNO"
},
{
"input": "2\n6 15 5 100 21 7 17\n3 5 21 7",
"output": "NO\nYES"
},
{
"input": "10\n1 4\n1 2\n1 3\n1 5\n1 1\n1 4\n1 3\n1 5\n1 2\n1 1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1 1\n1 2\n1 1",
"output": "NO\nYES\nNO"
},
{
"input": "10\n3 2 3 4\n1 1\n1 1\n1 2\n1 3\n1 4\n1 1\n1 3\n2 4 5\n2 1 2",
"output": "NO\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO"
},
{
"input": "10\n1 4\n4 3 2 4 1\n1 4\n2 4 5\n4 4 3 5 1\n1 4\n1 2\n2 3 5\n2 5 3\n3 5 2 4",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "20\n2 9 16\n3 1 15 2\n1 9\n3 7 12 3\n1 18\n1 14\n4 11 13 4 6\n4 7 19 9 3\n3 9 16 5\n1 9\n1 18\n4 4 15 7 19\n2 16 2\n3 7 3 15\n2 2 20\n1 1\n1 15\n5 5 2 13 4 1\n2 9 14\n2 17 8",
"output": "NO\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "40\n2 12 19\n4 10 7 1 3\n2 15 17\n1 6\n3 17 8 20\n4 8 16 11 18\n2 2 7\n4 12 13 8 7\n3 6 1 15\n3 19 11 13\n1 2\n2 16 14\n5 1 17 8 9 5\n1 2\n3 15 17 12\n4 20 4 19 18\n1 10\n4 12 1 17 16\n4 5 10 8 11\n1 10\n1 13\n1 17\n2 19 18\n1 3\n2 6 20\n1 8\n2 3 14\n3 17 3 1\n2 4 3\n1 12\n1 15\n1 2\n2 13 9\n2 1 14\n1 1\n5 14 9 3 1 7\n2 20 16\n2 19 17\n2 4 20\n1 7",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nYES"
}
] | 46 | 0 | 0 | 52,929 |
|
601 | Lipshitz Sequence | [
"data structures",
"math"
] | null | null | A function is called Lipschitz continuous if there is a real constant *K* such that the inequality |*f*(*x*)<=-<=*f*(*y*)|<=β€<=*K*Β·|*x*<=-<=*y*| holds for all . We'll deal with a more... discrete version of this term.
For an array , we define it's Lipschitz constant as follows:
- if *n*<=<<=2, - if *n*<=β₯<=2, over all 1<=β€<=*i*<=<<=*j*<=β€<=*n*
In other words, is the smallest non-negative integer such that |*h*[*i*]<=-<=*h*[*j*]|<=β€<=*L*Β·|*i*<=-<=*j*| holds for all 1<=β€<=*i*,<=*j*<=β€<=*n*.
You are given an array of size *n* and *q* queries of the form [*l*,<=*r*]. For each query, consider the subarray ; determine the sum of Lipschitz constants of all subarrays of . | The first line of the input contains two space-separated integers *n* and *q* (2<=β€<=*n*<=β€<=100<=000 and 1<=β€<=*q*<=β€<=100)Β β the number of elements in array and the number of queries respectively.
The second line contains *n* space-separated integers ().
The following *q* lines describe queries. The *i*-th of those lines contains two space-separated integers *l**i* and *r**i* (1<=β€<=*l**i*<=<<=*r**i*<=β€<=*n*). | Print the answers to all queries in the order in which they are given in the input. For the *i*-th query, print one line containing a single integerΒ β the sum of Lipschitz constants of all subarrays of . | [
"10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n",
"7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n"
] | [
"17\n82\n23\n210\n",
"2\n0\n22\n59\n16\n8\n"
] | In the first query of the first sample, the Lipschitz constants of subarrays of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ddadffaf9e222576b1abb771dcd83dbad588d7fe.png" style="max-width: 100.0%;max-height: 100.0%;"/> with length at least 2 are:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/887651f76ac57b8f2b2dbd46c6ac2335ac2a270a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e9eed4a49028e9bd234162d9da74fd4f86481378.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16eff35d7bd22d3e34c55fc95cc6c59212d5b1c8.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The answer to the query is their sum. | [
{
"input": "10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9",
"output": "17\n82\n23\n210"
},
{
"input": "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5",
"output": "2\n0\n22\n59\n16\n8"
},
{
"input": "2 2\n0 0\n1 2\n1 2",
"output": "0\n0"
},
{
"input": "2 2\n0 100000000\n1 2\n1 2",
"output": "100000000\n100000000"
},
{
"input": "4 6\n1 2 3 2\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "1\n3\n6\n1\n3\n1"
},
{
"input": "3 6\n10 20 30\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3",
"output": "10\n30\n10\n10\n10\n30"
},
{
"input": "3 6\n48261735 26888803 75904937\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3",
"output": "21372932\n119405200\n49016134\n21372932\n49016134\n119405200"
},
{
"input": "3 6\n100000000 99999999 0\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3",
"output": "1\n199999999\n99999999\n1\n99999999\n199999999"
},
{
"input": "2 2\n100000000 0\n1 2\n1 2",
"output": "100000000\n100000000"
}
] | 46 | 0 | 0 | 53,040 |
|
0 | none | [
"none"
] | null | null | Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.
Let's assume that strings *s* and *t* have the same length *n*, then the function *h*(*s*,<=*t*) is defined as the number of positions in which the respective symbols of *s* and *t* are the same. Function *h*(*s*,<=*t*) can be used to define the function of Vasya distance Ο(*s*,<=*t*):
Vasya found a string *s* of length *n* on the Internet. Now he wants to count how many strings *t* there are such that the Vasya distance from the string *s* attains maximum possible value. Formally speaking, *t* must satisfy the equation: .
Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109<=+<=7. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=105).
The second line of the input contains a single string of length *n*, consisting of characters "ACGT". | Print a single numberΒ β the answer modulo 109<=+<=7. | [
"1\nC\n",
"2\nAG\n",
"3\nTTT\n"
] | [
"1\n",
"4\n",
"1\n"
] | Please note that if for two distinct strings *t*<sub class="lower-index">1</sub> and *t*<sub class="lower-index">2</sub> values Ο(*s*,β*t*<sub class="lower-index">1</sub>) ΠΈ Ο(*s*,β*t*<sub class="lower-index">2</sub>) are maximum among all possible *t*, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.
In the first sample, there is Ο("*C*",β"*C*")β=β1, for the remaining strings *t* of length 1 the value of Ο(*s*,β*t*) is 0.
In the second sample, Ο("*AG*",β"*AG*")β=βΟ("*AG*",β"*GA*")β=βΟ("*AG*",β"*AA*")β=βΟ("*AG*",β"*GG*")β=β4.
In the third sample, Ο("*TTT*",β"*TTT*")β=β27 | [
{
"input": "1\nC",
"output": "1"
},
{
"input": "2\nAG",
"output": "4"
},
{
"input": "3\nTTT",
"output": "1"
},
{
"input": "4\nGACT",
"output": "256"
},
{
"input": "1\nT",
"output": "1"
},
{
"input": "2\nAG",
"output": "4"
},
{
"input": "3\nGCA",
"output": "27"
},
{
"input": "5\nACGTC",
"output": "1"
},
{
"input": "15\nAGCGAATCCCATTGT",
"output": "14348907"
},
{
"input": "20\nTAAGCGACCAGGTGCTTTAC",
"output": "511620083"
},
{
"input": "30\nCCTTTCGGGGCGCGTTGGCCTTTGTCCTGC",
"output": "130653412"
},
{
"input": "318\nTATCAATCGGTACGTGCGCATCATTGTCAATCGGGCTTCATGGCTTGCGGGCGCTACCCGAGGGGAAGCTGCGGACAGGTAGGTAAGATACACACGAACCAAACGGAGTTATGTTGGATAAATTGGCTGGAAGGGCGTAGGTATATCGAGTCGCGGACCTGGCATAGACTATCAGGGGCAGCGGTACAAGGCAACCGTGAGCGGGGTCTGCCCACCATTAGACCGATGCGCCGGCTCGTATATGTGATTCTGGTGAAAAGTATCATGCCGGGACGCGTAATGACCCGGCTGGCTAATCCACCGTGGCAGCAAAATAAC",
"output": "1"
}
] | 62 | 204,800 | 3 | 53,043 |
|
932 | Palindrome Partition | [
"dp",
"string suffix structures",
"strings"
] | null | null | Given a string *s*, find the number of ways to split *s* to substrings such that if there are *k* substrings (*p*1,<=*p*2,<=*p*3,<=...,<=*p**k*) in partition, then *p**i*<==<=*p**k*<=-<=*i*<=+<=1 for all *i* (1<=β€<=*i*<=β€<=*k*) and *k* is even.
Since the number of ways can be large, print it modulo 109<=+<=7. | The only line of input contains a string *s* (2<=β€<=|*s*|<=β€<=106) of even length consisting of lowercase Latin letters. | Print one integer, the number of ways of partitioning the string modulo 109<=+<=7. | [
"abcdcdab\n",
"abbababababbab\n"
] | [
"1",
"3"
] | In the first case, the only way to partition the string is *ab*|*cd*|*cd*|*ab*.
In the second case, the string can be partitioned as *ab*|*b*|*ab*|*ab*|*ab*|*ab*|*b*|*ab* or *ab*|*b*|*abab*|*abab*|*b*|*ab* or *abbab*|*ab*|*ab*|*abbab*. | [] | 46 | 0 | 0 | 53,053 |
|
1,005 | Berland and the Shortest Paths | [
"brute force",
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | There are $n$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $1$ to $n$.
It is known that, from the capital (the city with the number $1$), you can reach any other city by moving along the roads.
The President of Berland plans to improve the country's road network. The budget is enough to repair exactly $n-1$ roads. The President plans to choose a set of $n-1$ roads such that:
- it is possible to travel from the capital to any other city along the $n-1$ chosen roads, - if $d_i$ is the number of roads needed to travel from the capital to city $i$, moving only along the $n-1$ chosen roads, then $d_1 + d_2 + \dots + d_n$ is minimized (i.e. as minimal as possible).
In other words, the set of $n-1$ roads should preserve the connectivity of the country, and the sum of distances from city $1$ to all cities should be minimized (where you can only use the $n-1$ chosen roads).
The president instructed the ministry to prepare $k$ possible options to choose $n-1$ roads so that both conditions above are met.
Write a program that will find $k$ possible ways to choose roads for repair. If there are fewer than $k$ ways, then the program should output all possible valid ways to choose roads. | The first line of the input contains integers $n$, $m$ and $k$ ($2 \le n \le 2\cdot10^5, n-1 \le m \le 2\cdot10^5, 1 \le k \le 2\cdot10^5$), where $n$ is the number of cities in the country, $m$ is the number of roads and $k$ is the number of options to choose a set of roads for repair. It is guaranteed that $m \cdot k \le 10^6$.
The following $m$ lines describe the roads, one road per line. Each line contains two integers $a_i$, $b_i$ ($1 \le a_i, b_i \le n$, $a_i \ne b_i$) β the numbers of the cities that the $i$-th road connects. There is at most one road between a pair of cities. The given set of roads is such that you can reach any city from the capital. | Print $t$ ($1 \le t \le k$) β the number of ways to choose a set of roads for repair. Recall that you need to find $k$ different options; if there are fewer than $k$ of them, then you need to find all possible different valid options.
In the following $t$ lines, print the options, one per line. Print an option as a string of $m$ characters where the $j$-th character is equal to '1' if the $j$-th road is included in the option, and is equal to '0' if the road is not included. The roads should be numbered according to their order in the input. The options can be printed in any order. All the $t$ lines should be different.
Since it is guaranteed that $m \cdot k \le 10^6$, the total length of all the $t$ lines will not exceed $10^6$.
If there are several answers, output any of them. | [
"4 4 3\n1 2\n2 3\n1 4\n4 3\n",
"4 6 3\n1 2\n2 3\n1 4\n4 3\n2 4\n1 3\n",
"5 6 2\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n"
] | [
"2\n1110\n1011\n",
"1\n101001\n",
"2\n111100\n110110\n"
] | none | [
{
"input": "4 4 3\n1 2\n2 3\n1 4\n4 3",
"output": "2\n1110\n1011"
},
{
"input": "4 6 3\n1 2\n2 3\n1 4\n4 3\n2 4\n1 3",
"output": "1\n101001"
},
{
"input": "5 6 2\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5",
"output": "2\n111100\n110110"
},
{
"input": "2 1 200000\n2 1",
"output": "1\n1"
},
{
"input": "3 2 100000\n1 2\n2 3",
"output": "1\n11"
},
{
"input": "3 2 100000\n1 2\n1 3",
"output": "1\n11"
},
{
"input": "3 3 1000\n1 2\n2 3\n3 1",
"output": "1\n101"
},
{
"input": "5 6 166666\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5",
"output": "4\n111100\n110110\n111001\n110011"
},
{
"input": "5 6 10\n4 5\n3 2\n3 5\n1 3\n5 1\n1 2",
"output": "1\n100111"
},
{
"input": "6 9 10\n3 5\n3 2\n1 3\n2 1\n6 3\n1 6\n4 2\n1 5\n6 5",
"output": "1\n001101110"
},
{
"input": "10 14 100\n2 8\n4 7\n1 4\n9 1\n6 9\n8 6\n10 2\n8 4\n1 7\n6 5\n10 9\n3 10\n6 2\n1 3",
"output": "6\n10111001111001\n00111011111001\n00111001111011\n10111001110101\n00111011110101\n00111001110111"
},
{
"input": "15 20 100\n6 7\n15 11\n2 15\n9 5\n9 1\n8 2\n2 10\n2 12\n3 11\n5 12\n14 9\n4 11\n11 2\n13 5\n12 7\n6 1\n13 3\n8 6\n10 8\n3 7",
"output": "4\n10111100111101010111\n10111100011111010111\n10111100101101110111\n10111100001111110111"
},
{
"input": "16 20 100\n9 12\n7 1\n9 6\n1 5\n5 14\n9 11\n6 1\n3 1\n1 16\n5 6\n11 3\n9 5\n10 7\n13 1\n4 3\n5 16\n9 8\n15 13\n9 2\n14 3",
"output": "4\n11111011101011101110\n11011011101111101110\n11110011101011101111\n11010011101111101111"
},
{
"input": "16 20 100\n8 4\n2 16\n8 7\n6 11\n8 9\n10 4\n1 4\n3 9\n5 8\n3 14\n5 6\n11 4\n10 15\n1 16\n9 5\n13 10\n5 14\n3 1\n12 16\n6 1",
"output": "2\n11110111011011010111\n11100111011111010111"
},
{
"input": "16 20 100\n7 8\n6 5\n15 1\n7 2\n2 12\n1 7\n7 9\n13 15\n11 14\n3 10\n8 3\n2 14\n3 4\n1 5\n4 15\n10 12\n11 4\n4 8\n7 16\n14 13",
"output": "8\n11111111011101101010\n11111111010111101010\n11111111001101111010\n11111111000111111010\n11111111011001101011\n11111111010011101011\n11111111001001111011\n11111111000011111011"
},
{
"input": "16 20 100\n6 3\n15 16\n14 2\n15 5\n6 12\n13 16\n9 12\n16 3\n5 11\n16 14\n10 8\n4 3\n2 7\n8 14\n2 3\n1 3\n13 15\n14 3\n3 5\n8 2",
"output": "4\n11001111101111110110\n11001111101110110111\n10011111101111110110\n10011111101110110111"
},
{
"input": "16 20 100\n4 6\n7 15\n10 5\n8 6\n9 11\n12 15\n14 1\n13 7\n12 2\n4 12\n14 16\n3 16\n9 15\n4 5\n8 15\n6 3\n2 11\n9 12\n5 15\n3 11",
"output": "6\n11111011101111011001\n11111011011111011001\n11111011001111011101\n11111011101101111001\n11111011011101111001\n11111011001101111101"
},
{
"input": "18 23 100\n5 13\n10 2\n6 3\n8 2\n1 16\n18 10\n12 1\n2 1\n18 2\n6 2\n4 1\n16 7\n15 18\n17 11\n9 17\n17 3\n16 15\n12 14\n14 17\n5 9\n9 2\n17 13\n7 10",
"output": "4\n11111011111101101101100\n01111011111101101101110\n11111011111101001111100\n01111011111101001111110"
},
{
"input": "18 23 100\n12 14\n2 11\n1 13\n2 7\n18 17\n16 13\n9 13\n15 1\n9 12\n3 4\n10 11\n18 4\n2 18\n13 8\n5 6\n9 2\n9 4\n13 5\n5 15\n15 4\n18 1\n10 9\n16 5",
"output": "4\n11111111110111100100110\n11111111110011100101110\n11111111110111100010110\n11111111110011100011110"
},
{
"input": "18 23 100\n14 1\n4 3\n2 9\n16 10\n10 12\n10 1\n6 15\n1 8\n3 12\n11 14\n9 8\n15 1\n15 9\n7 10\n1 5\n18 16\n3 1\n8 14\n4 9\n11 13\n13 6\n10 17\n13 15",
"output": "4\n11111111011101111000011\n11111111010111111000011\n11110111111101111000011\n11110111110111111000011"
},
{
"input": "18 23 100\n5 13\n6 7\n8 2\n13 7\n18 12\n11 18\n9 5\n5 4\n17 15\n11 4\n6 13\n13 15\n18 16\n14 15\n4 8\n7 2\n12 14\n12 1\n2 10\n13 4\n8 5\n3 18\n1 10",
"output": "4\n01111110110011011110111\n01111110100011111110111\n01101110110111011110111\n01101110100111111110111"
},
{
"input": "18 23 100\n4 16\n12 17\n2 12\n16 13\n5 8\n2 18\n5 15\n11 5\n15 11\n13 9\n10 4\n15 10\n13 7\n14 15\n4 9\n5 1\n6 13\n3 17\n18 11\n15 3\n9 5\n1 9\n3 5",
"output": "4\n11001111011011111110011\n11001111010111111110011\n01011111011011111110011\n01011111010111111110011"
},
{
"input": "50 70 10000\n1 12\n43 48\n39 50\n2 9\n3 10\n2 26\n38 8\n38 39\n12 17\n6 19\n31 21\n17 23\n39 25\n25 9\n42 1\n32 18\n1 18\n32 19\n19 41\n26 32\n4 28\n12 15\n49 5\n16 11\n4 30\n34 16\n26 23\n44 30\n37 4\n25 36\n15 6\n29 27\n48 11\n29 21\n30 20\n32 20\n21 30\n17 7\n33 2\n22 19\n25 34\n49 38\n38 24\n20 46\n14 30\n33 47\n38 45\n18 40\n44 43\n36 40\n7 33\n11 27\n49 35\n25 30\n37 34\n46 28\n42 18\n37 50\n21 47\n40 21\n29 50\n27 49\n16 6\n49 44\n20 6\n37 26\n9 13\n27 19\n1 29\n19 10",
"output": "1536\n1111111110111011111111111001001111011101001111110101101001101100001011\n1111111110111011111111110001101111011101001111110101101001101100001011\n1110111110111111111111111001001111011101001111110101101001101100001011\n1110111110111111111111110001101111011101001111110101101001101100001011\n1111111110111011111111101001001111011101001111110101101001101110001011\n1111111110111011111111100001101111011101001111110101101001101110001011\n1110111110111111111111101001001111011101001111110101101001101110001011\n1..."
},
{
"input": "11 18 55555\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 8\n6 9\n7 8\n7 9\n8 10\n8 11\n9 10\n9 11",
"output": "256\n111100110011001100\n110110110011001100\n111001110011001100\n110011110011001100\n111100011011001100\n110110011011001100\n111001011011001100\n110011011011001100\n111100100111001100\n110110100111001100\n111001100111001100\n110011100111001100\n111100001111001100\n110110001111001100\n111001001111001100\n110011001111001100\n111100110001101100\n110110110001101100\n111001110001101100\n110011110001101100\n111100011001101100\n110110011001101100\n111001011001101100\n110011011001101100\n111100100101101100\n110110..."
},
{
"input": "17 30 33333\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 8\n6 9\n7 8\n7 9\n8 10\n8 11\n9 10\n9 11\n10 12\n10 13\n11 12\n11 13\n12 14\n12 15\n13 14\n13 15\n14 16\n14 17\n15 16\n15 17",
"output": "16384\n111100110011001100110011001100\n110110110011001100110011001100\n111001110011001100110011001100\n110011110011001100110011001100\n111100011011001100110011001100\n110110011011001100110011001100\n111001011011001100110011001100\n110011011011001100110011001100\n111100100111001100110011001100\n110110100111001100110011001100\n111001100111001100110011001100\n110011100111001100110011001100\n111100001111001100110011001100\n110110001111001100110011001100\n111001001111001100110011001100\n110011001111001100110011..."
},
{
"input": "21 38 26315\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 8\n6 9\n7 8\n7 9\n8 10\n8 11\n9 10\n9 11\n10 12\n10 13\n11 12\n11 13\n12 14\n12 15\n13 14\n13 15\n14 16\n14 17\n15 16\n15 17\n16 18\n16 19\n17 18\n17 19\n18 20\n18 21\n19 20\n19 21",
"output": "26315\n11110011001100110011001100110011001100\n11011011001100110011001100110011001100\n11100111001100110011001100110011001100\n11001111001100110011001100110011001100\n11110001101100110011001100110011001100\n11011001101100110011001100110011001100\n11100101101100110011001100110011001100\n11001101101100110011001100110011001100\n11110010011100110011001100110011001100\n11011010011100110011001100110011001100\n11100110011100110011001100110011001100\n11001110011100110011001100110011001100\n111100001111001100110011..."
}
] | 0 | 0 | -1 | 53,157 |
|
855 | Salazar Slytherin's Locket | [
"bitmasks",
"dp"
] | null | null | Harry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from there and is now present in the Ministry of Magic in the office of Dolorous Umbridge, Harry's former Defense Against the Dark Arts teacher.
Harry, Ron and Hermione are infiltrating the Ministry. Upon reaching Umbridge's office, they observed a code lock with a puzzle asking them to calculate count of magic numbers between two integers *l* and *r* (both inclusive).
Harry remembered from his detention time with Umbridge that she defined a magic number as a number which when converted to a given base *b*, all the digits from 0 to *b*<=-<=1 appear even number of times in its representation without any leading zeros.
You have to answer *q* queries to unlock the office. Each query has three integers *b**i*, *l**i* and *r**i*, the base and the range for which you have to find the count of magic numbers. | First line of input contains *q* (1<=β€<=*q*<=β€<=105)Β β number of queries.
Each of the next *q* lines contain three space separated integers *b**i*, *l**i*, *r**i* (2<=β€<=*b**i*<=β€<=10, 1<=β€<=*l**i*<=β€<=*r**i*<=β€<=1018). | You have to output *q* lines, each containing a single integer, the answer to the corresponding query. | [
"2\n2 4 9\n3 1 10\n",
"2\n2 1 100\n5 1 100\n"
] | [
"1\n2\n",
"21\n4\n"
] | In sample test case 1, for first query, when we convert numbers 4 to 9 into base 2, we get:
- 4β=β100<sub class="lower-index">2</sub>, - 5β=β101<sub class="lower-index">2</sub>, - 6β=β110<sub class="lower-index">2</sub>, - 7β=β111<sub class="lower-index">2</sub>, - 8β=β1000<sub class="lower-index">2</sub>, - 9β=β1001<sub class="lower-index">2</sub>.
Out of these, only base 2 representation of 9 has even number of 1 and 0. Thus, the answer is 1. | [
{
"input": "2\n2 4 9\n3 1 10",
"output": "1\n2"
},
{
"input": "2\n2 1 100\n5 1 100",
"output": "21\n4"
},
{
"input": "10\n4 108 114\n5 30 155\n8 193 197\n9 71 169\n2 163 166\n8 120 144\n8 22 151\n4 21 166\n2 46 127\n8 38 51",
"output": "0\n3\n0\n1\n3\n0\n5\n16\n9\n1"
},
{
"input": "20\n9 142 172\n7 132 256\n8 245 315\n9 496 496\n3 345 362\n8 13 162\n5 342 470\n9 16 488\n9 467 482\n4 471 478\n10 92 224\n6 228 261\n9 54 167\n2 402 409\n5 9 10\n7 225 360\n3 438 483\n6 252 342\n3 491 493\n6 296 367",
"output": "0\n0\n0\n0\n4\n6\n13\n7\n0\n0\n1\n2\n3\n0\n0\n2\n12\n9\n1\n4"
},
{
"input": "1\n8 1234567890123 123456789012345",
"output": "774752389568"
}
] | 46 | 307,200 | 0 | 53,562 |
|
191 | Thwarting Demonstrations | [
"binary search",
"data structures",
"trees"
] | null | null | It is dark times in Berland. Berlyand opposition, funded from a neighboring state, has organized a demonstration in Berland capital Bertown. Through the work of intelligence we know that the demonstrations are planned to last for *k* days.
Fortunately, Berland has a special police unit, which can save the country. It has exactly *n* soldiers numbered from 1 to *n*. Berland general, the commander of the detachment, must schedule the detachment's work in these difficult *k* days. In each of these days, the general must send a certain number of police officers to disperse riots. Since the detachment is large and the general is not very smart, he can only select a set of all soldiers numbered from *l* to *r*, inclusive, where *l* and *r* are selected arbitrarily.
Now the general has exactly two problems. First, he cannot send the same group twice β then soldiers get bored and they rebel. Second, not all soldiers are equally reliable. Every soldier has a reliability of *a**i*. The reliability of the detachment is counted as the sum of reliabilities of soldiers in it. The reliability of a single soldier can be negative, then when you include him in the detachment, he will only spoil things. The general is distinguished by his great greed and shortsightedness, so each day he sends to the dissolution the most reliable group of soldiers possible (that is, of all the groups that have not been sent yet).
The Berland Government has decided to know what would be the minimum reliability of the detachment, sent to disperse the demonstrations during these *k* days. The general himself can not cope with such a difficult task. Help him to not embarrass himself in front of his superiors! | The first line contains two integers *n* and *k* β the number of soldiers in the detachment and the number of times somebody goes on duty.
The second line contains *n* space-separated integers *a**i*, their absolute value doesn't exceed 109 β the soldiers' reliabilities.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++, it is preferred to use cin, cout streams of the %I64d specifier. | Print a single number β the sought minimum reliability of the groups that go on duty during these *k* days. | [
"3 4\n1 4 2\n",
"4 6\n2 -1 2 -1\n",
"8 10\n1 -2 3 -4 5 -6 7 -8\n"
] | [
"4\n",
"1\n",
"2\n"
] | none | [
{
"input": "3 4\n1 4 2",
"output": "4"
},
{
"input": "4 6\n2 -1 2 -1",
"output": "1"
},
{
"input": "8 10\n1 -2 3 -4 5 -6 7 -8",
"output": "2"
},
{
"input": "10 13\n11 73 57 -34 61 38 -83 10 -88 -32",
"output": "99"
},
{
"input": "20 31\n19 38 -67 83 -83 79 98 -8 84 79 -67 -11 4 91 -49 39 100 41 57 20",
"output": "360"
},
{
"input": "100 4064\n-100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100 -100 100",
"output": "-100"
},
{
"input": "100 727\n9935 9968 9986 9934 9940 9920 9938 9980 9922 9909 9965 9999 9992 9986 9980 9947 9956 9901 9919 9944 9991 9908 9979 9932 9985 9929 9952 9926 9969 9911 9905 9975 9981 9957 9989 9917 9957 9961 9944 9991 9958 9962 9910 9934 9930 9970 9938 9943 9934 9923 9929 9960 9992 9901 9909 9906 9944 9981 9981 9938 9933 9919 9962 9983 9973 9970 9904 9928 9941 9990 9968 9957 9979 9969 9934 9903 9958 9991 9935 9958 9983 9925 9952 9975 9974 9971 9984 9994 9922 9915 9930 9930 9955 9996 9988 9903 9972 9943 9917 9986",
"output": "626803"
},
{
"input": "100 176\n73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73 73",
"output": "5986"
},
{
"input": "1 1\n-45446256",
"output": "-45446256"
},
{
"input": "2 3\n27177357 -94420028",
"output": "-94420028"
},
{
"input": "3 4\n-32235897 94055412 32974265",
"output": "61819515"
},
{
"input": "10 27\n502411 -83857 125370 -774975 -317753 -716429 -945455 -902721 -254853 -145773",
"output": "-1683787"
}
] | 6,000 | 334,438,400 | 0 | 53,652 |
|
325 | The Red Button | [
"combinatorics",
"dfs and similar",
"dsu",
"graphs",
"greedy"
] | null | null | Piegirl found the red button. You have one last chance to change the inevitable end.
The circuit under the button consists of *n* nodes, numbered from 0 to *n* - 1. In order to deactivate the button, the *n* nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node *i*, the next node to be disarmed must be either node (2Β·*i*) modulo *n* or node (2Β·*i*)<=+<=1 modulo *n*. The last node to be disarmed must be node 0. Node 0 must be disarmed twice, but all other nodes must be disarmed exactly once.
Your task is to find any such order and print it. If there is no such order, print -1. | Input consists of a single integer *n* (2<=β€<=*n*<=β€<=105). | Print an order in which you can to disarm all nodes. If it is impossible, print -1 instead. If there are multiple orders, print any one of them. | [
"2\n",
"3\n",
"4\n",
"16\n"
] | [
"0 1 0\n",
"-1",
"0 1 3 2 0\n",
"0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0\n"
] | none | [
{
"input": "2",
"output": "0 1 0"
},
{
"input": "3",
"output": "-1"
},
{
"input": "4",
"output": "0 1 3 2 0"
},
{
"input": "16",
"output": "0 1 2 4 9 3 6 13 10 5 11 7 15 14 12 8 0"
},
{
"input": "5",
"output": "-1"
},
{
"input": "7",
"output": "-1"
},
{
"input": "32",
"output": "0 1 2 4 8 17 3 6 12 25 18 5 10 20 9 19 7 14 29 26 21 11 22 13 27 23 15 31 30 28 24 16 0"
},
{
"input": "255",
"output": "-1"
},
{
"input": "65536",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32769 3 6 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49153 32770 5 10 20 40 80 160 320 640 1280 2560 5120 10240 20480 40960 16385 32771 7 14 28 56 112 224 448 896 1792 3584 7168 14336 28672 57345 49154 32772 9 18 36 72 144 288 576 1152 2304 4608 9216 18432 36864 8193 16386 32773 11 22 44 88 176 352 704 1408 2816 5632 11264 22528 45056 24577 49155 32774 13 26 52 104 208 416 832 1664 3328 6656 13312 26624 53248 40961 16387 32775 15 30 60 120 24..."
},
{
"input": "99999",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "6",
"output": "0 1 2 5 4 3 0"
},
{
"input": "8",
"output": "0 1 2 5 3 7 6 4 0"
},
{
"input": "10",
"output": "0 1 2 4 9 8 6 3 7 5 0"
},
{
"input": "12",
"output": "0 1 2 4 8 5 11 10 9 7 3 6 0"
},
{
"input": "20",
"output": "0 1 2 4 8 16 12 5 11 3 6 13 7 14 9 19 18 17 15 10 0"
},
{
"input": "25",
"output": "-1"
},
{
"input": "30",
"output": "0 1 2 4 8 16 3 6 12 24 19 9 18 7 14 29 28 26 23 17 5 10 21 13 27 25 20 11 22 15 0"
},
{
"input": "32",
"output": "0 1 2 4 8 17 3 6 12 25 18 5 10 20 9 19 7 14 29 26 21 11 22 13 27 23 15 31 30 28 24 16 0"
},
{
"input": "45",
"output": "-1"
},
{
"input": "50",
"output": "0 1 2 4 8 16 32 14 28 6 12 24 49 48 46 42 34 18 36 22 44 39 29 9 19 38 26 3 7 15 30 10 20 40 31 13 27 5 11 23 47 45 41 33 17 35 21 43 37 25 0"
},
{
"input": "100",
"output": "0 1 2 4 8 16 32 64 28 56 12 24 48 96 92 84 68 36 72 44 88 76 52 5 10 20 40 80 60 21 42 85 70 41 82 65 30 61 22 45 90 81 62 25 51 3 6 13 26 53 7 14 29 58 17 34 69 38 77 54 9 18 37 74 49 99 98 97 94 89 79 59 19 39 78 57 15 31 63 27 55 11 23 46 93 86 73 47 95 91 83 66 33 67 35 71 43 87 75 50 0"
},
{
"input": "126",
"output": "0 1 2 4 8 16 32 64 3 6 12 24 48 96 66 7 14 28 56 112 98 70 15 30 60 120 114 102 78 31 62 125 124 122 118 110 95 65 5 10 20 40 80 35 71 17 34 68 11 22 44 88 50 100 74 23 46 92 58 116 106 87 49 99 72 18 37 75 25 51 103 81 36 73 21 42 85 45 90 54 109 93 61 123 121 117 108 91 57 115 104 83 41 82 39 79 33 67 9 19 38 77 29 59 119 113 101 76 27 55 111 97 69 13 26 53 107 89 52 105 84 43 86 47 94 63 0"
},
{
"input": "513",
"output": "-1"
},
{
"input": "514",
"output": "0 1 2 4 8 16 32 64 128 256 513 512 510 506 498 482 450 386 258 3 6 12 24 48 96 192 384 254 508 502 490 466 418 322 130 260 7 14 28 56 112 224 448 382 250 500 486 458 402 290 66 132 264 15 30 60 120 240 480 446 378 242 484 454 394 274 34 68 136 272 31 62 124 248 496 478 442 370 226 452 390 266 18 36 72 144 288 63 126 252 504 494 474 434 354 194 388 262 10 20 40 80 160 321 129 259 5 11 22 44 88 176 352 190 380 246 492 470 426 338 162 324 134 268 23 46 92 184 368 222 444 374 234 468 422 330 146 292 70 140 280..."
},
{
"input": "800",
"output": "0 1 2 4 8 16 32 64 128 256 512 224 448 96 192 384 768 736 672 544 288 576 352 704 608 416 33 66 132 264 528 257 514 228 456 112 225 450 100 200 401 3 6 12 24 48 97 194 388 776 752 705 610 420 40 80 160 320 640 480 161 322 644 488 176 353 706 612 424 49 98 196 392 784 769 738 676 552 304 609 418 36 72 144 289 578 356 712 624 449 99 198 396 792 785 770 740 680 560 321 642 484 168 336 673 546 292 584 368 737 674 548 296 592 385 771 742 684 568 337 675 550 300 601 402 5 10 20 41 82 164 328 656 513 226 452 104 ..."
},
{
"input": "1000",
"output": "0 1 2 4 8 16 32 64 128 256 512 24 48 96 192 384 768 536 72 144 288 576 152 304 608 216 432 864 728 456 912 824 648 296 592 184 368 736 472 944 888 776 552 104 208 416 832 664 328 656 312 624 248 496 992 984 968 936 872 744 488 976 952 904 808 616 232 464 928 856 712 424 848 696 392 784 568 136 272 544 88 176 352 704 408 816 632 264 528 56 112 224 448 896 792 584 168 336 672 344 688 376 752 504 9 18 36 73 146 292 585 170 340 680 360 720 440 880 760 520 40 80 160 320 640 280 560 120 240 480 960 920 840 681 3..."
},
{
"input": "2500",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 1596 692 1384 268 536 1072 2144 1788 1076 2152 1804 1108 2216 1932 1364 228 456 912 1824 1148 2296 2092 1684 868 1736 972 1944 1388 276 552 1104 2208 1916 1332 164 328 656 1312 124 248 496 992 1984 1468 436 872 1744 988 1976 1452 404 808 1616 732 1464 428 856 1712 924 1848 1196 2392 2284 2068 1636 772 1544 588 1176 2352 2204 1908 1316 132 264 528 1056 2112 1724 948 1896 1292 84 168 336 672 1344 188 376 752 1504 508 1016 2032 1564 628 1256 12 24 48 96 192 384 768 153..."
},
{
"input": "6400",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 1792 3584 768 1536 3072 6144 5888 5376 4352 2304 4608 2816 5632 4864 3328 257 514 1028 2056 4112 1824 3648 896 1793 3586 772 1544 3088 6176 5952 5504 4609 2818 5636 4872 3344 288 576 1152 2305 4610 2820 5640 4880 3360 320 640 1280 2560 5120 3840 1281 2562 5124 3848 1296 2592 5184 3968 1537 3074 6148 5896 5392 4384 2368 4736 3073 6146 5892 5384 4368 2336 4672 2944 5889 5378 4356 2312 4624 2848 5696 4992 3585 770 1540 3080 6160 5920 5440 4480 2561 5122 3844 1288 ..."
},
{
"input": "23105",
"output": "-1"
},
{
"input": "24002",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 8766 17532 11062 22124 20246 16490 8978 17956 11910 23820 23638 23274 22546 21090 18178 12354 706 1412 2824 5648 11296 22592 21182 18362 12722 1442 2884 5768 11536 23072 22142 20282 16562 9122 18244 12486 970 1940 3880 7760 15520 7038 14076 4150 8300 16600 9198 18396 12790 1578 3156 6312 12624 1246 2492 4984 9968 19936 15870 7738 15476 6950 13900 3798 7596 15192 6382 12764 1526 3052 6104 12208 414 828 1656 3312 6624 13248 2494 4988 9976 19952 15902 7..."
},
{
"input": "29024",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 3744 7488 14976 928 1856 3712 7424 14848 672 1344 2688 5376 10752 21504 13984 27968 26912 24800 20576 12128 24256 19488 9952 19904 10784 21568 14112 28224 27424 25824 22624 16224 3424 6848 13696 27392 25760 22496 15968 2912 5824 11648 23296 17568 6112 12224 24448 19872 10720 21440 13856 27712 26400 23776 18528 8032 16064 3104 6208 12416 24832 20640 12256 24512 20000 10976 21952 14880 736 1472 2944 5888 11776 23552 18080 7136 14272 28544 28064 27104 2..."
},
{
"input": "36002",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 29534 23066 10130 20260 4518 9036 18072 142 284 568 1136 2272 4544 9088 18176 350 700 1400 2800 5600 11200 22400 8798 17596 35192 34382 32762 29522 23042 10082 20164 4326 8652 17304 34608 33214 30426 24850 13698 27396 18790 1578 3156 6312 12624 25248 14494 28988 21974 7946 15892 31784 27566 19130 2258 4516 9032 18064 126 252 504 1008 2016 4032 8064 16128 32256 28510 21018 6034 12068 24136 12270 24540 13078 26156 16310 32620 29238 22474 8946 178..."
},
{
"input": "55555",
"output": "-1"
},
{
"input": "65534",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 3 6 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49152 32770 7 14 28 56 112 224 448 896 1792 3584 7168 14336 28672 57344 49154 32774 15 30 60 120 240 480 960 1920 3840 7680 15360 30720 61440 57346 49158 32782 31 62 124 248 496 992 1984 3968 7936 15872 31744 63488 61442 57350 49166 32798 63 126 252 504 1008 2016 4032 8064 16128 32256 64512 63490 61446 57358 49182 32830 127 254 508 1016 2032 4064 8128 16256 32512 65024 64514 63494 61454 573..."
},
{
"input": "77776",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 53296 28816 57632 37488 74976 72176 66576 55376 32976 65952 54128 30480 60960 44144 10512 21024 42048 6320 12640 25280 50560 23344 46688 15600 31200 62400 47024 16272 32544 65088 52400 27024 54048 30320 60640 43504 9232 18464 36928 73856 69936 62096 46416 15056 30112 60224 42672 7568 15136 30272 60544 43312 8848 17696 35392 70784 63792 49808 21840 43680 9584 19168 38336 76672 75568 73360 68944 60112 42448 7120 14240 28480 56960 36144 7228..."
},
{
"input": "88888",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 42184 84368 79848 70808 52728 16568 33136 66272 43656 87312 85736 82584 76280 63672 38456 76912 64936 40984 81968 75048 61208 33528 67056 45224 1560 3120 6240 12480 24960 49920 10952 21904 43808 87616 86344 83800 78712 68536 48184 7480 14960 29920 59840 30792 61584 34280 68560 48232 7576 15152 30304 60608 32328 64656 40424 80848 72808 56728 24568 49136 9384 18768 37536 75072 61256 33624 67248 45608 2328 4656 9312 18624 37248 74496 60104 3..."
},
{
"input": "99494",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31578 63156 26818 53636 7778 15556 31112 62224 24954 49908 322 644 1288 2576 5152 10304 20608 41216 82432 65370 31246 62492 25490 50980 2466 4932 9864 19728 39456 78912 58330 17166 34332 68664 37834 75668 51842 4190 8380 16760 33520 67040 34586 69172 38850 77700 55906 12318 24636 49272 98544 97594 95694 91894 84294 69094 38694 77388 55282 11070 22140 44280 88560 77626 55758 12022 24044 48088 96176 92858 86222 72950 46406 92812 86130 72766..."
},
{
"input": "99998",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31074 62148 24298 48596 97192 94386 88774 77550 55102 10206 20412 40824 81648 63298 26598 53196 6394 12788 25576 51152 2306 4612 9224 18448 36896 73792 47586 95172 90346 80694 61390 22782 45564 91128 82258 64518 29038 58076 16154 32308 64616 29234 58468 16938 33876 67752 35506 71012 42026 84052 68106 36214 72428 44858 89716 79434 58870 17742 35484 70968 41938 83876 67754 35510 71020 42042 84084 68170 36342 72684 45370 90740 81482 62966 25..."
},
{
"input": "90248",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 40824 81648 73048 55848 21448 42896 85792 81336 72424 54600 18952 37904 75808 61368 32488 64976 39704 79408 68568 46888 3528 7056 14112 28224 56448 22648 45296 344 688 1376 2752 5504 11008 22016 44032 88064 85880 81512 72776 55304 20360 40720 81440 72632 55016 19784 39568 79136 68024 45800 1352 2704 5408 10816 21632 43264 86528 82808 75368 60488 30728 61456 32664 65328 40408 80816 71384 52520 14792 29584 59168 28088 56176 22104 44208 8841..."
},
{
"input": "99994",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31078 62156 24318 48636 97272 94550 89106 78218 56442 12890 25780 51560 3126 6252 12504 25008 50016 38 76 152 304 608 1216 2432 4864 9728 19456 38912 77824 55654 11314 22628 45256 90512 81030 62066 24138 48276 96552 93110 86226 72458 44922 89844 79694 59394 18794 37588 75176 50358 722 1444 2888 5776 11552 23104 46208 92416 84838 69682 39370 78740 57486 14978 29956 59912 19830 39660 79320 58646 17298 34596 69192 38390 76780 53566 7138 1427..."
},
{
"input": "100000",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 31072 62144 24288 48576 97152 94304 88608 77216 54432 8864 17728 35456 70912 41824 83648 67296 34592 69184 38368 76736 53472 6944 13888 27776 55552 11104 22208 44416 88832 77664 55328 10656 21312 42624 85248 70496 40992 81984 63968 27936 55872 11744 23488 46976 93952 87904 75808 51616 3232 6464 12928 25856 51712 3424 6848 13696 27392 54784 9568 19136 38272 76544 53088 6176 12352 24704 49408 98816 97632 95264 90528 81056 62112 24224 48448 ..."
},
{
"input": "98300",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 32772 65544 32788 65576 32852 65704 33108 66216 34132 68264 38228 76456 54612 10924 21848 43696 87392 76484 54668 11036 22072 44144 88288 78276 58252 18204 36408 72816 47332 94664 91028 83756 69212 40124 80248 62196 26092 52184 6068 12136 24272 48544 97088 95876 93452 88604 78908 59516 20732 41464 82928 67556 36812 73624 48948 97896 97492 96684 95068 91836 85372 72444 46588 93176 88052 77804 57308 16316 32632 65264 32228 64456 30612 61224..."
},
{
"input": "95324",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 35748 71496 47668 12 24 48 96 192 384 768 1536 3072 6144 12288 24576 49152 2980 5960 11920 23840 47680 36 72 144 288 576 1152 2304 4608 9216 18432 36864 73728 52132 8940 17880 35760 71520 47716 108 216 432 864 1728 3456 6912 13824 27648 55296 15268 30536 61072 26820 53640 11956 23912 47824 324 648 1296 2592 5184 10368 20736 41472 82944 70564 45804 91608 87892 80460 65596 35868 71736 48148 972 1944 3888 7776 15552 31104 62208 29092 58184 2..."
},
{
"input": "87380",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 43692 5 10 20 40 80 160 320 640 1280 2560 5120 10240 20480 40960 81920 76460 65540 43700 21 42 84 168 336 672 1344 2688 5376 10752 21504 43008 86016 84652 81924 76468 65556 43732 85 170 340 680 1360 2720 5440 10880 21760 43520 87040 86700 86020 84660 81940 76500 65620 43860 341 682 1364 2728 5456 10912 21824 43648 87296 87212 87044 86708 86036 84692 82004 76628 65876 44372 1365 2730 5460 10920 21840 43680 87360 87340 87300 87220 87060 867..."
},
{
"input": "86036",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 45036 4036 8072 16144 32288 64576 43116 196 392 784 1568 3136 6272 12544 25088 50176 14316 28632 57264 28492 56984 27932 55864 25692 51384 16732 33464 66928 47820 9604 19208 38416 76832 67628 49220 12404 24808 49616 13196 26392 52784 19532 39064 78128 70220 54404 22772 45544 5052 10104 20208 40416 80832 75628 65220 44404 2772 5544 11088 22176 44352 2668 5336 10672 21344 42688 85376 84716 83396 80756 75476 64916 43796 1556 3112 6224 12448 ..."
},
{
"input": "81914",
"output": "0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 49158 16402 32804 65608 49302 16690 33380 66760 51606 21298 42596 3278 6556 13112 26224 52448 22982 45964 10014 20028 40056 80112 78310 74706 67498 53082 24250 48500 15086 30172 60344 38774 77548 73182 64450 46986 12058 24116 48232 14550 29100 58200 34486 68972 56030 30146 60292 38670 77340 72766 63618 45322 8730 17460 34920 69840 57766 33618 67236 52558 23202 46404 10894 21788 43576 5238 10476 20952 41904 1894 3788 7576 15152 30304 60608..."
}
] | 92 | 0 | 0 | 53,667 |
|
982 | Shark | [
"brute force",
"data structures",
"dsu",
"trees"
] | null | null | For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.
Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $k$ that if the shark in some day traveled the distance strictly less than $k$, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $k$; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $k$.
The shark never returned to the same location after it has moved from it. Thus, in the sequence of $n$ days we can find consecutive nonempty segments when the shark traveled the distance less than $k$ in each of the days: each such segment corresponds to one location. Max wants to choose such $k$ that the lengths of all such segments are equal.
Find such integer $k$, that the number of locations is as large as possible. If there are several such $k$, print the smallest one. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of days.
The second line contains $n$ distinct positive integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) β the distance traveled in each of the day. | Print a single integer $k$, such that
1. the shark was in each location the same number of days, 1. the number of locations is maximum possible satisfying the first condition, 1. $k$ is smallest possible satisfying the first and second conditions. | [
"8\n1 2 7 3 4 8 5 6\n",
"6\n25 1 2 3 14 36\n"
] | [
"7",
"2"
] | In the first example the shark travels inside a location on days $1$ and $2$ (first location), then on $4$-th and $5$-th days (second location), then on $7$-th and $8$-th days (third location). There are three locations in total.
In the second example the shark only moves inside a location on the $2$-nd day, so there is only one location. | [
{
"input": "8\n1 2 7 3 4 8 5 6",
"output": "7"
},
{
"input": "6\n25 1 2 3 14 36",
"output": "2"
},
{
"input": "20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11",
"output": "11"
},
{
"input": "7\n1 2 5 7 3 4 6",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1000000001"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "2\n2 1",
"output": "2"
},
{
"input": "22\n22 1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11 21",
"output": "11"
},
{
"input": "63\n32 48 31 56 30 47 29 60 28 46 27 55 26 45 25 62 24 44 23 54 22 43 21 59 20 42 19 53 18 41 17 63 16 40 15 52 14 39 13 58 12 38 11 51 10 37 9 61 8 36 7 50 6 35 5 57 4 34 3 49 2 33 1",
"output": "33"
},
{
"input": "127\n64 96 63 112 62 95 61 120 60 94 59 111 58 93 57 124 56 92 55 110 54 91 53 119 52 90 51 109 50 89 49 126 48 88 47 108 46 87 45 118 44 86 43 107 42 85 41 123 40 84 39 106 38 83 37 117 36 82 35 105 34 81 33 127 32 80 31 104 30 79 29 116 28 78 27 103 26 77 25 122 24 76 23 102 22 75 21 115 20 74 19 101 18 73 17 125 16 72 15 100 14 71 13 114 12 70 11 99 10 69 9 121 8 68 7 98 6 67 5 113 4 66 3 97 2 65 1",
"output": "65"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 100 99 98 97 96 95 94 93 92 91 90 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 73 72 71 70 69 68 67 66 65 64 63 62 61",
"output": "61"
},
{
"input": "10\n1 2 3 10 9 8 4 5 6 7",
"output": "7"
}
] | 389 | 22,016,000 | 3 | 53,694 |
|
518 | Ilya and Escalator | [
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability *p*, or the first person in the queue doesn't move with probability (1<=-<=*p*), paralyzed by his fear of escalators and making the whole queue wait behind him.
Formally speaking, the *i*-th person in the queue cannot enter the escalator until people with indices from 1 to *i*<=-<=1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after *t* seconds.
Your task is to help him solve this complicated task. | The first line of the input contains three numbers *n*,<=*p*,<=*t* (1<=β€<=*n*,<=*t*<=β€<=2000, 0<=β€<=*p*<=β€<=1). Numbers *n* and *t* are integers, number *p* is real, given with exactly two digits after the decimal point. | Print a single real number β the expected number of people who will be standing on the escalator after *t* seconds. The absolute or relative error mustn't exceed 10<=-<=6. | [
"1 0.50 1\n",
"1 0.50 4\n",
"4 0.20 2\n"
] | [
"0.5\n",
"0.9375\n",
"0.4\n"
] | none | [
{
"input": "1 0.50 1",
"output": "0.500000000000000"
},
{
"input": "1 0.50 4",
"output": "0.937500000000000"
},
{
"input": "4 0.20 2",
"output": "0.400000000000000"
},
{
"input": "2000 0.61 2000",
"output": "1219.999999999999545"
},
{
"input": "100 1.00 200",
"output": "100.000000000000000"
},
{
"input": "417 0.57 742",
"output": "414.074442142061741"
},
{
"input": "100 0.01 53",
"output": "0.530000000000000"
},
{
"input": "300 0.05 55",
"output": "2.750000000000001"
},
{
"input": "1400 0.02 200",
"output": "3.999999999999999"
},
{
"input": "2000 0.01 234",
"output": "2.340000000000000"
},
{
"input": "1 0.01 2000",
"output": "0.999999998136245"
},
{
"input": "300 0.99 1000",
"output": "299.999999999999886"
},
{
"input": "400 0.96 1754",
"output": "400.000000000000171"
},
{
"input": "2000 0.93 100",
"output": "93.000000000000014"
},
{
"input": "1000 0.90 1733",
"output": "999.999999999999545"
},
{
"input": "1 1.00 1",
"output": "1.000000000000000"
},
{
"input": "2000 1.00 2000",
"output": "2000.000000000000000"
},
{
"input": "2000 0.00 2000",
"output": "0.000000000000000"
},
{
"input": "2000 0.01 2000",
"output": "20.000000000000004"
},
{
"input": "2000 0.99 2000",
"output": "1980.000000000000000"
},
{
"input": "654 0.67 999",
"output": "652.821925126205883"
},
{
"input": "132 0.34 241",
"output": "81.939999999977616"
},
{
"input": "984 0.19 1565",
"output": "297.350000000000023"
},
{
"input": "439 0.83 790",
"output": "439.000000000000000"
},
{
"input": "559 0.92 1006",
"output": "558.999999999999773"
},
{
"input": "887 0.69 1596",
"output": "886.999999999999545"
},
{
"input": "211 0.78 379",
"output": "211.000000000000000"
},
{
"input": "539 0.54 970",
"output": "522.459296616033384"
},
{
"input": "659 0.97 1186",
"output": "659.000000000000455"
},
{
"input": "87 0.95 156",
"output": "87.000000000000014"
},
{
"input": "415 0.72 747",
"output": "415.000000000000000"
},
{
"input": "639 0.81 1150",
"output": "638.999999999999659"
},
{
"input": "818 0.99 1472",
"output": "818.000000000000000"
},
{
"input": "246 0.98 442",
"output": "245.999999999999972"
},
{
"input": "470 0.74 846",
"output": "470.000000000000114"
}
] | 124 | 10,649,600 | -1 | 53,711 |
|
126 | Fibonacci Sums | [
"dp",
"math"
] | null | null | Fibonacci numbers have the following form:
Let's consider some non-empty set *S*<==<={*s*1,<=*s*2,<=...,<=*s**k*}, consisting of different Fibonacci numbers. Let's find the sum of values of this set's elements:
Let's call the set *S* a number *n*'s decomposition into Fibonacci sum.
It's easy to see that several numbers have several decompositions into Fibonacci sum. For example, for 13 we have 13,<=5<=+<=8,<=2<=+<=3<=+<=8 β three decompositions, and for 16: 3<=+<=13,<=1<=+<=2<=+<=13,<=3<=+<=5<=+<=8,<=1<=+<=2<=+<=5<=+<=8 β four decompositions.
By the given number *n* determine the number of its possible different decompositions into Fibonacci sum. | The first line contains an integer *t* β the number of tests (1<=β€<=*t*<=β€<=105). Each of the following *t* lines contains one test.
Each test is an integer *n* (1<=β€<=*n*<=β€<=1018).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | For each input data test print a single number on a single line β the answer to the problem. | [
"2\n13\n16\n"
] | [
"3\n4\n"
] | Two decompositions are different if there exists a number that is contained in the first decomposition, but is not contained in the second one. Decompositions that differ only in the order of summands are considered equal. | [
{
"input": "2\n13\n16",
"output": "3\n4"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "1\n1\n2\n1\n2\n2\n1\n3\n2\n2"
},
{
"input": "10\n24\n37\n42\n58\n60\n73\n79\n84\n92\n99",
"output": "5\n6\n6\n7\n6\n6\n8\n7\n8\n6"
},
{
"input": "5\n484775665757\n968685776575\n687675666422\n348587665784\n373875686864",
"output": "117120\n155520\n320160\n115920\n84600"
},
{
"input": "1\n123456789101112",
"output": "2868360"
},
{
"input": "22\n304056783818718320\n491974210728665289\n187917426909946968\n796030994547383610\n912170329762608884\n983952450306818690\n958440306146823493\n882642089000772193\n728253142723222890\n798004545631811295\n339945818819306128\n550043889183050965\n889989708002357094\n679891637638612257\n420196140727489672\n160500643816367088\n259695496911122585\n420196140727489673\n679891637638612258\n679891637638612256\n491974210728665288\n796030994547383611",
"output": "433494437\n433494437\n433494437\n433494437\n528734760\n509752320\n470315160\n465835968\n437082800\n425880000\n268435456\n268435456\n268435456\n1\n1\n42\n42\n43\n43\n43\n701408733\n866988874"
}
] | 30 | 0 | 0 | 53,998 |
|
137 | Palindromes | [
"dp",
"strings"
] | null | null | Friday is Polycarpus' favourite day of the week. Not because it is followed by the weekend, but because the lessons on Friday are 2 IT lessons, 2 math lessons and 2 literature lessons. Of course, Polycarpus has prepared to all of them, unlike his buddy Innocentius. Innocentius spent all evening playing his favourite game Fur2 and didn't have enough time to do the literature task. As Innocentius didn't want to get an F, he decided to do the task and read the book called "Storm and Calm" during the IT and Math lessons (he never used to have problems with these subjects). When the IT teacher Mr. Watkins saw this, he decided to give Innocentius another task so that the boy concentrated more on the lesson and less β on the staff that has nothing to do with IT.
Mr. Watkins said that a palindrome is a string that can be read the same way in either direction, from the left to the right and from the right to the left. A concatenation of strings *a*, *b* is a string *ab* that results from consecutive adding of string *b* to string *a*. Of course, Innocentius knew it all but the task was much harder than he could have imagined. Mr. Watkins asked change in the "Storm and Calm" the minimum number of characters so that the text of the book would also be a concatenation of no more than *k* palindromes. Innocentius can't complete the task and therefore asks you to help him. | The first input line contains a non-empty string *s* which is the text of "Storm and Calm" (without spaces). The length of the string *s* does not exceed 500 characters. String *s* consists of uppercase and lowercase Latin letters. The second line contains a single number *k* (1<=β€<=*k*<=β€<=|*s*|, where |*s*| represents the length of the string *s*). | Print on the first line the minimum number of changes that Innocentius will have to make. Print on the second line the string consisting of no more than *k* palindromes. Each palindrome should be non-empty and consist of uppercase and lowercase Latin letters. Use the character "+" (ASCII-code 43) to separate consecutive palindromes. If there exist several solutions, print any of them.
The letters' case does matter, that is an uppercase letter is not considered equivalent to the corresponding lowercase letter. | [
"abacaba\n1\n",
"abdcaba\n2\n",
"abdcaba\n5\n",
"abacababababbcbabcd\n3\n"
] | [
"0\nabacaba\n",
"1\nabdcdba\n",
"0\na+b+d+c+aba\n",
"1\nabacaba+babab+bcbabcb\n"
] | none | [
{
"input": "abacaba\n1",
"output": "0\nabacaba"
},
{
"input": "abdcaba\n2",
"output": "1\nabdcdba"
},
{
"input": "abdcaba\n5",
"output": "0\na+b+d+c+aba"
},
{
"input": "abacababababbcbabcd\n3",
"output": "1\nabacaba+babab+bcbabcb"
},
{
"input": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba\n1",
"output": "0\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
},
{
"input": "abcabcabcabcxyzxyzxyzxyz\n5",
"output": "7\na+b+cabcaacbac+xyzxyzzyxzyx"
},
{
"input": "aaaaaabbbbbb\n1",
"output": "6\naaaaaaaaaaaa"
},
{
"input": "abcdefg\n7",
"output": "0\na+b+c+d+e+f+g"
},
{
"input": "xxxyyyzzz\n2",
"output": "3\nxxxyyyxxx"
},
{
"input": "zpbdnUpuVzOCzkgMmOXMgnrWrrHAylLovxRLSkRyRlsyZXUYBXZqjpWiHhjwEnNhJTBEFqSvgoSzcDSnNJXdDEyJwyxyEZdtTKcm\n30",
"output": "22\nz+pbddbp+u+V+zOOz+k+gMmOmMg+n+rWr+r+H+A+y+l+L+o+v+x+RLSLR+yRlRy+ZXUYUXZ+qjpWiHhjwEwjhHiWpjq+SvgvS+z+c+D+SnN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ODszuzRWcOzWmhmWzOcWRzuzhhTWawwaWTywPxfyHWgvTQffQTvgWHyfxPwy\n10",
"output": "0\nG+CDnnDC+zmNvNmz+QQ+mTzYWtwEaWiiWaEwtWYzTm+sDODs+zuzRWcOzWmhmWzOcWRzuz+hh+TWawwaWT+ywPxfyHWgvTQffQTvgWHyfxPwy"
},
{
"input": "SWPEISxfnvQhDdWMUMDDFAgnjkoNpKZJWgeftsapnfTiTULMcl\n50",
"output": "0\nS+W+P+E+I+S+x+f+n+v+Q+h+D+d+W+MUM+DD+F+A+g+n+j+k+o+N+p+K+Z+J+W+g+e+f+t+s+a+p+n+f+TiT+U+L+M+c+l"
},
{
"input": "QBJXFByWnwnwyusOgBKpUqxTjfEJaPrRYUHItEVI\n3",
"output": "14\nQBJXFByWnwnWyBFXJBQ+pUqxTjfEEfjTxqUp+ItEtI"
},
{
"input": "YGkzboLjDJFMARChEQBTTBQEhCRAMFJDjLobzkGY\n1",
"output": "0\nYGkzboLjDJFMARChEQBTTBQEhCRAMFJDjLobzkGY"
},
{
"input": "QsAQXXlArrAlXaBSSBaX\n4",
"output": "1\nQssQ+XX+lArrAl+XaBSSBaX"
},
{
"input": "npRAxpncpgQqTHHTqQgpcSbYEhvKBPRDUjnXznRXnjUDRPlKvhEYbNgrtVweZIhmyEqEymhItDwVtrgN\n5",
"output": "5\nnpRARpn+cpgQqTHHTqQgpc+S+bYEhvKBPRDUjnXznzXnjUDRPBKvhEYb+NgrtVweZIhmyEqEymhIZewVtrgN"
},
{
"input": "WdYlPYGSNSGYPlYdWpIyMrtjUleOWVihRoZkUyXWuKuWXyUkZoRhzVWOelUjtrMyIpZassaZBSohcqchoSBZKgKZlhMOXMoMXOMZGZvvRkqSOmHWZxSxZWHmOSrkRvvWPW\n10",
"output": "3\nWdYlPYGSNSGYPlYdW+pIyMrtjUleOWVihRoZkUyXWuKuWXyUkZoRhiVWOelUjtrMyIp+ZassaZ+BSohcqchoSB+ZKgKZ+ll+MOXMoMXOM+ZGZ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eCZoMGFuMlBsGhwnwzUgPVV\n10",
"output": "49\naexKFYychcyYFKxea+qXXlGiJpyttypJiGlXXq+SdOpnSnpOdS+avpcVqIlFlIqVcpva+qQZywnJjaEuJRVRJuEajJnwyZQq+lgZkumdoXPbucFdIymjcmyzWnaNaOrgPnVbTeKglSFzzFSlgKeTbVnPgrOaNanWzymcjmyIdFcubPXodmukZgl+oNgFxkSBwhrkBwVDGzbNBqbGsZuQymGyMIzRhYCRjSYwmIvyjbzlMbAPPqiSCRjQMEKEQQEKEMQjRCSiqPPAbMlzbjyvImwYSjRCYhRzIMyGmyQuZsGbqBNbzGDVwBkrhwBSkxFgNo+uHaRVIvMgaybUubYgmgYbuUbyagMvIVRaHu+egUzwnjLGsBlMbFGMoMCePYrqDVaxkSBLeLOjlXhQgxIDwhtOkztECJfoTMwAIwsFEQipvCnCdCnCvpiQEFswIAwMTofJCEtzkOthwDIxgQhXljOLeLBSkxaVDqrYPeCMoMGFbMlBsGLjnwzUge+..."
},
{
"input": "anZBQZPTfBdhFsBUBTXoZlxkNItepGNkhrRWrIjYJIANGHTGwrFldvwdTooioQkuGRFvIemljhshRpJVMNxTPugHWBnITYyLymOnJLZzFGPmakDhpaUiwWakzPSYjZJLUpoDofCUijrHYxiBSYNbJmITVKcbKBrZZWyGrBPhaikdxnEbHqxqQYIQwTitxaLHkGRhbmumeRHHsxfCVoIKemNeRZrlEpdcRkFocGZohvIKYquujOtPfdzDrIIrDzdfPtOjuuqYKIvhoZGcoFkRcdpElrZReNmeKIoVCfxsHHRemumbhRGkHLaxtiTwQIYQqxqHbEnxdkiahPBrGyWZZrBKbcKVTImJbNYSBixYHrjiUCfoDopULJZjYSPzkaWwiUaphDkamPGFzZLJnOmyLyYTInBWHguPTxNMVJpRhshjlmeIvFRGukQoiooTdwvdlFrwGTHGNAIJYjIrWRrhkNGpetINkxlZoXTBUBsFhdBfTPZQBZna\n1",
"output": "0\nanZBQZPTfBdhFsBUBTXoZlxkNItepGNkhrRWrIjYJI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+Z+C+E+z+n+Y+w+b+m+C+U+V+J+k+p+R+t+u+F+k+u+i+R+y+WW+z+k+Y+b+T+s+y+u+zz+X+w+V+S+U+x+O+M+k+R+G+J+I+x+l+i+d+J+p+S+J+e+T+L+h+w+z+e+s+b+QfQ+K+E+f+H+x+G+v+M+C+q+R+DaD+b+W+c+r+l+J+j+q+O+l+rWr+j+I+q+V+T+f+V+s+y+r+M+N+u+U+x+X+I+G+a+r+z+x+Q+..."
},
{
"input": "aa\n1",
"output": "0\naa"
},
{
"input": "aA\n1",
"output": "1\naa"
},
{
"input": "aA\n2",
"output": "0\na+A"
}
] | 122 | 0 | -1 | 54,062 |
|
409 | On a plane | [
"*special",
"geometry"
] | null | null | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of points on a plane.
Each of the next *n* lines contains two real coordinates *x**i* and *y**i* of the point, specified with exactly 2 fractional digits. All coordinates are between <=-<=1000 and 1000, inclusive.
Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10<=-<=2. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of points on a plane.
Each of the next *n* lines contains two real coordinates *x**i* and *y**i* of the point, specified with exactly 2 fractional digits. All coordinates are between <=-<=1000 and 1000, inclusive. | Output a single real number ΞΈ β the answer to the problem statement. The absolute or relative error of your answer should be at most 10<=-<=2. | [
"8\n-2.14 2.06\n-1.14 2.04\n-2.16 1.46\n-2.14 0.70\n-1.42 0.40\n-0.94 -0.48\n-1.42 -1.28\n-2.16 -1.62\n",
"5\n2.26 1.44\n2.28 0.64\n2.30 -0.30\n1.58 0.66\n3.24 0.66\n",
"8\n6.98 2.06\n6.40 1.12\n5.98 0.24\n5.54 -0.60\n7.16 0.30\n7.82 1.24\n8.34 0.24\n8.74 -0.76\n",
"5\n10.44 2.06\n10.90 0.80\n11.48 -0.48\n12.06 0.76\n12.54 2.06\n",
"8\n16.94 2.42\n15.72 2.38\n14.82 1.58\n14.88 0.50\n15.76 -0.16\n16.86 -0.20\n17.00 0.88\n16.40 0.92\n",
"7\n20.62 3.00\n21.06 2.28\n21.56 1.36\n21.66 0.56\n21.64 -0.52\n22.14 2.32\n22.62 3.04\n"
] | [
"5.410\n",
"5.620\n",
"5.480\n",
"6.040\n",
"6.040\n",
"6.720\n"
] | none | [
{
"input": "8\n-2.14 2.06\n-1.14 2.04\n-2.16 1.46\n-2.14 0.70\n-1.42 0.40\n-0.94 -0.48\n-1.42 -1.28\n-2.16 -1.62",
"output": "5.410"
},
{
"input": "5\n2.26 1.44\n2.28 0.64\n2.30 -0.30\n1.58 0.66\n3.24 0.66",
"output": "5.620"
},
{
"input": "8\n6.98 2.06\n6.40 1.12\n5.98 0.24\n5.54 -0.60\n7.16 0.30\n7.82 1.24\n8.34 0.24\n8.74 -0.76",
"output": "5.480"
},
{
"input": "5\n10.44 2.06\n10.90 0.80\n11.48 -0.48\n12.06 0.76\n12.54 2.06",
"output": "6.040"
},
{
"input": "8\n16.94 2.42\n15.72 2.38\n14.82 1.58\n14.88 0.50\n15.76 -0.16\n16.86 -0.20\n17.00 0.88\n16.40 0.92",
"output": "6.040"
},
{
"input": "7\n20.62 3.00\n21.06 2.28\n21.56 1.36\n21.66 0.56\n21.64 -0.52\n22.14 2.32\n22.62 3.04",
"output": "6.720"
},
{
"input": "14\n99.19 -882.27\n468.09 310.41\n-539.17 665.55\n-355.65 -90.01\n490.35 -966.88\n-102.77 252.03\n981.63 -976.33\n-363.05 -435.09\n-44.93 -37.28\n947.69 530.68\n49.38 -299.65\n503.33 684.17\n199.13 328.89\n31.24 65.36",
"output": "-55.744"
},
{
"input": "1\n1.00 1.01",
"output": "6.010"
},
{
"input": "1\n0.00 0.01",
"output": "5.010"
},
{
"input": "1\n1000.00 999.99",
"output": "1004.990"
},
{
"input": "1\n792.52 879.16",
"output": "884.160"
},
{
"input": "2\n792.70 540.07\n-865.28 -699.23",
"output": "-74.580"
},
{
"input": "3\n792.88 200.98\n-5.87 -263.79\n-134.68 900.15",
"output": "284.113"
}
] | 108 | 1,638,400 | 3 | 54,091 |
|
835 | Roads in the Kingdom | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | In the Kingdom K., there are *n* towns numbered with integers from 1 to *n*. The towns are connected by *n* bi-directional roads numbered with integers from 1 to *n*. The *i*-th road connects the towns *u**i* and *v**i* and its length is *l**i*. There is no more than one road between two towns. Also, there are no roads that connect the towns with itself.
Let's call the inconvenience of the roads the maximum of the shortest distances between all pairs of towns.
Because of lack of money, it was decided to close down one of the roads so that after its removal it is still possible to reach any town from any other. You have to find the minimum possible inconvenience of the roads after closing down one of the roads. | The first line contains the integer *n* (3<=β€<=*n*<=β€<=2Β·105)Β β the number of towns and roads.
The next *n* lines contain the roads description. The *i*-th from these lines contains three integers *u**i*, *v**i*, *l**i* (1<=β€<=*u**i*,<=*v**i*<=β€<=*n*, 1<=β€<=*l**i*<=β€<=109)Β β the numbers of towns connected by the *i*-th road and the length of the *i*-th road. No road connects a town to itself, no two roads connect the same towns.
It's guaranteed that it's always possible to close down one of the roads so that all the towns are still reachable from each other. | Print a single integerΒ β the minimum possible inconvenience of the roads after the refusal from one of the roads. | [
"3\n1 2 4\n2 3 5\n1 3 1\n",
"5\n2 3 7\n3 1 9\n4 1 8\n3 5 4\n4 5 5\n"
] | [
"5\n",
"18\n"
] | none | [] | 31 | 0 | 0 | 54,280 |
|
989 | A Trance of Nightfall | [
"dp",
"geometry",
"matrices",
"probabilities"
] | null | null | "Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually."
"Everything is transient in a way and perennial in another."
Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night skyΒ β the inexhaustible gifts from nature.
Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams.
There is a set $S$ of $n$ points on a coordinate plane.
Kanno starts from a point $P$ that can be chosen on the plane. $P$ is not added to $S$ if it doesn't belong to $S$. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order:
1. Choose a line $l$ such that it passes through at least two elements in $S$ and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably. 1. Move to one of the points that belong to $S$ and lie on $l$. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to $S$).
There are $q$ queries each consisting of two integers $(t_i, m_i)$. For each query, you're to help Kanno maximize the probability of the stopping position being the $t_i$-th element in $S$ after $m_i$ moves with a proper selection of $P$, and output this maximum probability. Note that according to rule 1, $P$ should belong to at least one line that passes through at least two points from $S$. | The first line contains a positive integer $n$ ($2 \leq n \leq 200$)Β β the number of points in $S$.
The $i$-th of the following $n$ lines contains two space-separated integers $x_i$ and $y_i$ ($-10^4 \leq x_i, y_i \leq 10^4$)Β β the coordinates of the $i$-th point in $S$. The input guarantees that for all $1 \leq i \lt j \leq n$, $(x_i, y_i) \neq (x_j, y_j)$ holds.
The next line contains a positive integer $q$ ($1 \leq q \leq 200$)Β β the number of queries.
Each of the following $q$ lines contains two space-separated integers $t$ and $m$ ($1 \leq t_i \leq n$, $1 \leq m_i \leq 10^4$)Β β the index of the target point and the number of moves, respectively. | Output $q$ lines each containing a decimal numberΒ β the $i$-th among them denotes the maximum probability of staying on the $t_i$-th point after $m_i$ steps, with a proper choice of starting position $P$.
Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most $10^{-6}$.
Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $|a - b| \le 10^{-6}$. | [
"5\n0 0\n1 3\n2 2\n3 1\n4 4\n10\n1 1\n2 1\n3 1\n4 1\n5 1\n3 2\n3 3\n3 4\n3 5\n3 6\n"
] | [
"0.50000000000000000000\n0.50000000000000000000\n0.33333333333333331483\n0.50000000000000000000\n0.50000000000000000000\n0.18518518518518517491\n0.15226337448559670862\n0.14494741655235482414\n0.14332164812274550414\n0.14296036624949901017\n"
] | The points in $S$ and possible candidates for line $l$ are depicted in the following figure.
For the first query, when $P = (-1, -3)$, $l$ is uniquely determined to be $3x = y$, and thus Kanno will move to $(0, 0)$ with a probability of $\frac 1 2$.
For the third query, when $P = (2, 2)$, $l$ is chosen equiprobably between $x + y = 4$ and $x = y$. Kanno will then move to the other four points with a probability of $\frac 1 2 \cdot \frac 1 3 = \frac 1 6$ each, or stay at $(2, 2)$ with a probability of $\frac 1 3$. | [] | 46 | 0 | 0 | 54,285 |
|
741 | Arpaβs overnight party and Mehrdadβs silent entering | [
"constructive algorithms",
"dfs and similar",
"graphs"
] | null | null | Note that girls in Arpaβs land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw *n* pairs of friends sitting around a table. *i*-th pair consisted of a boy, sitting on the *a**i*-th chair, and his girlfriend, sitting on the *b**i*-th chair. The chairs were numbered 1 through 2*n* in clockwise direction. There was exactly one person sitting on each chair.
There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:
- Each person had exactly one type of food, - No boy had the same type of food as his girlfriend, - Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2*n* and 1 are considered consecutive.
Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions. | The first line contains an integer *n* (1<=<=β€<=<=*n*<=<=β€<=<=105)Β β the number of pairs of guests.
The *i*-th of the next *n* lines contains a pair of integers *a**i* and *b**i* (1<=<=β€<=*a**i*,<=*b**i*<=β€<=<=2*n*)Β β the number of chair on which the boy in the *i*-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair. | If there is no solution, print -1.
Otherwise print *n* lines, the *i*-th of them should contain two integers which represent the type of food for the *i*-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.
If there are multiple solutions, print any of them. | [
"3\n1 4\n2 5\n3 6\n"
] | [
"1 2\n2 1\n1 2\n"
] | none | [
{
"input": "3\n1 4\n2 5\n3 6",
"output": "1 2\n2 1\n1 2"
},
{
"input": "6\n3 2\n5 11\n7 12\n6 9\n8 4\n1 10",
"output": "1 2\n1 2\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "19\n30 27\n6 38\n10 28\n20 5\n14 18\n32 2\n36 29\n12 1\n31 24\n15 4\n35 11\n3 7\n21 17\n25 19\n16 8\n23 22\n37 33\n13 9\n34 26",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1"
},
{
"input": "4\n4 2\n6 8\n5 1\n3 7",
"output": "1 2\n1 2\n2 1\n2 1"
},
{
"input": "17\n11 12\n17 22\n34 7\n3 1\n5 24\n18 20\n27 30\n16 33\n23 21\n19 4\n2 15\n29 28\n9 8\n13 25\n6 10\n32 26\n31 14",
"output": "1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2"
},
{
"input": "19\n10 7\n9 17\n21 30\n36 8\n14 11\n25 24\n1 23\n38 33\n4 20\n3 37\n27 5\n28 19\n22 2\n6 34\n12 15\n31 32\n35 13\n16 29\n18 26",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1"
},
{
"input": "17\n17 31\n11 23\n34 22\n24 8\n4 1\n7 14\n20 27\n3 19\n12 26\n32 25\n28 18\n16 29\n21 9\n6 2\n33 30\n5 13\n10 15",
"output": "1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1"
},
{
"input": "6\n2 7\n5 9\n12 8\n1 4\n3 6\n10 11",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n1 2"
},
{
"input": "8\n10 3\n2 16\n14 13\n5 15\n1 7\n11 8\n6 4\n12 9",
"output": "1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2"
},
{
"input": "4\n2 8\n3 5\n4 7\n1 6",
"output": "2 1\n2 1\n1 2\n1 2"
},
{
"input": "2\n2 3\n1 4",
"output": "2 1\n1 2"
},
{
"input": "15\n16 22\n4 17\n27 3\n23 24\n18 20\n15 21\n9 7\n2 28\n29 19\n8 30\n14 10\n6 26\n25 11\n12 1\n13 5",
"output": "2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1"
},
{
"input": "10\n19 6\n8 2\n15 18\n17 14\n16 7\n20 10\n5 1\n13 3\n9 12\n11 4",
"output": "2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "9\n12 7\n10 15\n16 14\n2 4\n1 17\n6 9\n8 3\n13 5\n11 18",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1"
},
{
"input": "7\n3 14\n7 4\n13 10\n11 8\n6 1\n5 9\n2 12",
"output": "2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1"
},
{
"input": "6\n2 11\n7 1\n12 8\n4 10\n3 9\n5 6",
"output": "2 1\n2 1\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "8\n13 6\n10 5\n1 12\n11 15\n7 16\n4 14\n9 2\n8 3",
"output": "1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2"
},
{
"input": "8\n16 5\n10 15\n8 11\n2 14\n6 4\n7 3\n1 13\n9 12",
"output": "1 2\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1"
},
{
"input": "7\n10 14\n4 6\n1 11\n7 2\n9 8\n5 13\n3 12",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1"
},
{
"input": "5\n2 5\n10 9\n1 6\n3 8\n4 7",
"output": "2 1\n2 1\n1 2\n1 2\n2 1"
},
{
"input": "8\n14 2\n7 9\n15 6\n13 11\n12 16\n10 5\n8 1\n3 4",
"output": "1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2"
},
{
"input": "5\n4 6\n5 1\n2 3\n7 8\n9 10",
"output": "2 1\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "23\n46 21\n17 3\n27 38\n34 43\n7 6\n8 37\n22 4\n16 42\n36 32\n12 9\n10 45\n26 2\n13 24\n23 29\n18 15\n33 30\n31 5\n11 25\n1 14\n44 39\n19 20\n35 28\n41 40",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1"
},
{
"input": "26\n8 10\n52 21\n2 33\n18 34\n30 51\n5 19\n22 32\n36 28\n42 16\n13 49\n11 17\n31 39\n43 37\n50 15\n29 20\n35 46\n47 23\n3 1\n44 7\n9 27\n6 48\n40 24\n26 14\n45 4\n12 25\n41 38",
"output": "2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1"
},
{
"input": "20\n34 12\n9 6\n5 3\n13 26\n18 15\n16 22\n7 14\n17 37\n38 40\n4 2\n11 23\n21 8\n10 36\n30 33\n28 19\n29 31\n39 20\n35 24\n25 32\n1 27",
"output": "1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2"
},
{
"input": "17\n3 14\n34 22\n24 9\n16 17\n6 30\n33 12\n5 10\n21 8\n32 2\n26 23\n31 27\n19 15\n29 4\n7 18\n25 13\n20 28\n1 11",
"output": "1 2\n1 2\n1 2\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2"
},
{
"input": "24\n30 4\n41 1\n2 11\n22 42\n29 43\n7 14\n16 6\n40 5\n27 34\n46 33\n17 10\n21 39\n28 31\n19 32\n23 20\n25 48\n12 9\n47 37\n38 3\n44 8\n36 18\n13 26\n24 15\n45 35",
"output": "1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2"
},
{
"input": "15\n21 14\n25 5\n7 28\n2 6\n8 27\n29 18\n9 15\n4 26\n12 1\n19 16\n17 20\n24 10\n11 23\n13 22\n30 3",
"output": "1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2"
}
] | 264 | 22,118,400 | -1 | 54,394 |
|
164 | Machine Programming | [
"flows",
"graphs"
] | null | null | One remarkable day company "X" received *k* machines. And they were not simple machines, they were mechanical programmers! This was the last unsuccessful step before switching to android programmers, but that's another story.
The company has now *n* tasks, for each of them we know the start time of its execution *s**i*, the duration of its execution *t**i*, and the company profit from its completion *c**i*. Any machine can perform any task, exactly one at a time. If a machine has started to perform the task, it is busy at all moments of time from *s**i* to *s**i*<=+<=*t**i*<=-<=1, inclusive, and it cannot switch to another task.
You are required to select a set of tasks which can be done with these *k* machines, and which will bring the maximum total profit. | The first line contains two integer numbers *n* and *k* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*k*<=β€<=50) β the numbers of tasks and machines, correspondingly.
The next *n* lines contain space-separated groups of three integers *s**i*,<=*t**i*,<=*c**i* (1<=β€<=*s**i*,<=*t**i*<=β€<=109, 1<=β€<=*c**i*<=β€<=106), *s**i* is the time where they start executing the *i*-th task, *t**i* is the duration of the *i*-th task and *c**i* is the profit of its execution. | Print *n* integers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* should equal 1, if task *i* should be completed and otherwise it should equal 0.
If there are several optimal solutions, print any of them. | [
"3 1\n2 7 5\n1 3 3\n4 1 3\n",
"5 2\n1 5 4\n1 4 5\n1 3 2\n4 1 2\n5 6 1\n"
] | [
"0 1 1\n",
"1 1 0 0 1\n"
] | In the first sample the tasks need to be executed at moments of time 2 ... 8, 1 ... 3 and 4 ... 4, correspondingly. The first task overlaps with the second and the third ones, so we can execute either task one (profit 5) or tasks two and three (profit 6). | [] | 92 | 0 | 0 | 54,407 |
|
493 | Vasya and Polynomial | [
"math"
] | null | null | Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function *P*(*x*)<==<=*a*0<=+<=*a*1*x*1<=+<=...<=+<=*a**n**x**n*. Numbers *a**i* are called coefficients of a polynomial, non-negative integer *n* is called a degree of a polynomial.
Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials *P*(*x*) exist with integer non-negative coefficients so that , and , where and *b* are given positive integers"?
Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem. | The input contains three integer positive numbers no greater than 1018. | If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109<=+<=7. | [
"2 2 2\n",
"2 3 3\n"
] | [
"2\n",
"1\n"
] | none | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "inf"
},
{
"input": "3 5 10",
"output": "0"
},
{
"input": "2 3 1000000000000000000",
"output": "0"
},
{
"input": "7 8 9",
"output": "1"
},
{
"input": "8 10 11",
"output": "0"
},
{
"input": "5 30 930",
"output": "1"
},
{
"input": "3 3 3",
"output": "2"
},
{
"input": "1 5 5",
"output": "1"
},
{
"input": "1 2 2",
"output": "1"
},
{
"input": "1 2 5",
"output": "1"
},
{
"input": "1 2 4",
"output": "1"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000",
"output": "2"
},
{
"input": "1 125 15625",
"output": "1"
},
{
"input": "1000000000000 1000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "5 2 2",
"output": "1"
},
{
"input": "1 3 6561",
"output": "1"
},
{
"input": "3 6 5",
"output": "0"
},
{
"input": "1 5 625",
"output": "1"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "1 2 65536",
"output": "1"
},
{
"input": "1 12 1728",
"output": "1"
},
{
"input": "110 115 114",
"output": "0"
},
{
"input": "1 2 128",
"output": "1"
},
{
"input": "110 1000 998",
"output": "0"
},
{
"input": "5 5 4",
"output": "0"
},
{
"input": "2 2 10",
"output": "0"
},
{
"input": "1 1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "2 999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1 4 288230376151711744",
"output": "1"
},
{
"input": "1 999999999 1000000000000000000",
"output": "0"
},
{
"input": "12365 1 1",
"output": "1"
},
{
"input": "135645 1 365333453",
"output": "0"
},
{
"input": "1 1 12345678901234567",
"output": "0"
},
{
"input": "563236 135645 356563",
"output": "0"
},
{
"input": "6 1 1",
"output": "1"
},
{
"input": "1 7 1",
"output": "0"
},
{
"input": "1 10 1000000000000000000",
"output": "1"
},
{
"input": "1 10 999999999999999999",
"output": "0"
}
] | 93 | 0 | -1 | 54,521 |
|
700 | Cool Slogans | [
"string suffix structures",
"strings"
] | null | null | Bomboslav set up a branding agency and now helps companies to create new logos and advertising slogans. In term of this problems, slogan of the company should be a non-empty substring of its name. For example, if the company name is "hornsandhoofs", then substrings "sand" and "hor" could be its slogans, while strings "e" and "hornss" can not.
Sometimes the company performs rebranding and changes its slogan. Slogan *A* is considered to be cooler than slogan *B* if *B* appears in *A* as a substring at least twice (this occurrences are allowed to overlap). For example, slogan *A*<==<= "abacaba" is cooler than slogan *B*<==<= "ba", slogan *A*<==<= "abcbcbe" is cooler than slogan *B*<==<= "bcb", but slogan *A*<==<= "aaaaaa" is not cooler than slogan *B*<==<= "aba".
You are given the company name *w* and your task is to help Bomboslav determine the length of the longest sequence of slogans *s*1,<=*s*2,<=...,<=*s**k*, such that any slogan in the sequence is cooler than the previous one. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the length of the company name that asks Bomboslav to help. The second line contains the string *w* of length *n*, that consists of lowercase English letters. | Print a single integerΒ β the maximum possible length of the sequence of slogans of the company named *w*, such that any slogan in the sequence (except the first one) is cooler than the previous | [
"3\nabc\n",
"5\nddddd\n",
"11\nabracadabra\n"
] | [
"1\n",
"5\n",
"3\n"
] | none | [] | 61 | 0 | -1 | 54,546 |
|
549 | Haar Features | [
"greedy",
"implementation"
] | null | null | The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represented with a table of size *n*<=Γ<=*m*. The table elements are integers that specify the brightness of each pixel in the image.
A feature also is a rectangular table of size *n*<=Γ<=*m*. Each cell of a feature is painted black or white.
To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of *W*<=-<=*B*, where *W* is the total brightness of the pixels in the image, covered with white feature cells, and *B* is the total brightness of the pixels covered with black feature cells.
Some examples of the most popular Haar features are given below.
Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.
A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.
You have a variable *value*, whose value is initially zero. In one operation you can count the sum of pixel values ββat any prefix rectangle, multiply it by any integer and add to variable *value*.
You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample. | The first line contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of rows and columns in the feature.
Next *n* lines contain the description of the feature. Each line consists of *m* characters, the *j*-th character of the *i*-th line equals to "W", if this element of the feature is white and "B" if it is black. | Print a single number β the minimum number of operations that you need to make to calculate the value of the feature. | [
"6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n",
"3 3\nWBW\nBWW\nWWW\n",
"3 6\nWWBBWW\nWWBBWW\nWWBBWW\n",
"4 4\nBBBB\nBBBB\nBBBB\nBBBW\n"
] | [
"2\n",
"4\n",
"3\n",
"4\n"
] | The first sample corresponds to feature *B*, the one shown in the picture. The value of this feature in an image of size 6βΓβ8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations:
1. add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable *value* (the rectangle is indicated by a red frame); <img class="tex-graphics" src="https://espresso.codeforces.com/59e6d843dfb74d53c1bdfa004d277d661dbfb8fc.png" style="max-width: 100.0%;max-height: 100.0%;"/>1. add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient β-β2 and variable *value*. <img class="tex-graphics" src="https://espresso.codeforces.com/91d79402e81fce528454fd33ea193676082cf259.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1β-β2β=ββ-β1, as required. | [
{
"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "2"
},
{
"input": "3 3\nWBW\nBWW\nWWW",
"output": "4"
},
{
"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW",
"output": "3"
},
{
"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW",
"output": "4"
},
{
"input": "10 9\nBWWWBWWBB\nBBWWBWBBW\nBBWBWBWBB\nBWBWBBBBB\nBBWBWBWBW\nBWWBWWBBW\nWBWWWBWWW\nWBBWBWBWW\nBBWWBWWBB\nBBWWBWWBW",
"output": "61"
},
{
"input": "4 1\nW\nW\nB\nB",
"output": "2"
},
{
"input": "2 10\nBBWBWWBWBB\nBBBBBBBBBW",
"output": "10"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB",
"output": "2"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2"
},
{
"input": "4 5\nBWWBB\nBWBBW\nWBWWW\nWBWWB",
"output": "13"
},
{
"input": "2 9\nWBBBWBBBW\nBWWBBBBBB",
"output": "9"
},
{
"input": "6 6\nBBWWWB\nWBBBWB\nBBBBBW\nWWWWWW\nBBBBBW\nBWWBBB",
"output": "16"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "1 1\nB",
"output": "1"
},
{
"input": "1 8\nWWBWWWWW",
"output": "3"
},
{
"input": "2 8\nBBBBBBBB\nBBBBBBBB",
"output": "1"
},
{
"input": "1 52\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1"
},
{
"input": "11 8\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWBWWWW\nWWWWWWWW\nWBWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "9"
}
] | 155 | 1,331,200 | 3 | 54,581 |
|
982 | The Meeting Place Cannot Be Changed | [
"dfs and similar",
"graphs"
] | null | null | Petr is a detective in Braginsk. Somebody stole a huge amount of money from a bank and Petr is to catch him. Somebody told Petr that some luxurious car moves along the roads without stopping.
Petr knows that it is the robbers who drive the car. The roads in Braginsk are one-directional and each of them connects two intersections. Petr wants to select one intersection such that if the robbers continue to drive the roads indefinitely, they will sooner or later come to that intersection. The initial position of the robbers is unknown. Find such an intersection that fits the requirements. | The first line of the input contains two integers $n$ and $m$ ($2 \leq n \le 10^5$, $2 \leq m \leq 5 \cdot 10^5$)Β β the number of intersections and the number of directed roads in Braginsk, respectively.
Each of the next $m$ lines contains two integers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$)Β β the start and finish of the $i$-th directed road. It is guaranteed that the robbers can move along the roads indefinitely. | Print a single integer $k$Β β the intersection Petr needs to choose. If there are multiple answers, print any. If there are no such intersections, print $-1$. | [
"5 6\n1 2\n2 3\n3 1\n3 4\n4 5\n5 3\n",
"3 3\n1 2\n2 3\n3 1\n"
] | [
"3",
"1"
] | In the first example the robbers can move, for example, along the following routes: $(1-2-3-1)$, $(3-4-5-3)$, $(1-2-3-4-5-3-1)$. We can show that if Petr chooses the $3$-rd intersection, he will eventually meet the robbers independently of their route. | [] | 124 | 102,400 | 0 | 54,799 |
|
847 | Students Initiation | [
"binary search",
"flows",
"graphs"
] | null | null | Soon the first year students will be initiated into students at the University of Berland. The organizers of the initiation come up with a program for this holiday. In their opinion, it would be good if the first-year students presented small souvenirs to each other. When they voiced this idea to the first-year students, they found out the following:
- some pairs of the new students already know each other; - each new student agrees to give souvenirs only to those with whom they are already familiar; - each new student does not want to present too many souvenirs.
The organizers have written down all the pairs of first-year friends who are familiar with each other and now want to determine for each new student, whom they should give souvenirs to. In their opinion, in each pair of familiar students exactly one student must present a souvenir to another student.
First year students already decided to call the unluckiest the one who will have to present the greatest number of souvenirs. The organizers in return promised that the unluckiest will be unlucky to the minimum possible degree: of course, they will have to present the greatest number of souvenirs compared to the other students, but this number will be as small as possible.
Organizers are very busy, and they asked you to determine for each pair of first-year friends who and to whom should present a souvenir. | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=5000, 0<=β€<=*m*<=β€<=*min*(5000,<=*n*Β·(*n*<=-<=1)<=/<=2)) β the number of the first year students and the number of pairs of the students that know each other. The students are numbered from 1 to *n*.
Each of the following *m* lines contains two integers *x**i*,<=*y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*, *x**i*<=β <=*y**i*)Β β the students in each pair.
It is guaranteed that each pair is present in the list exactly once. It is also guaranteed that if there is a pair (*x**i*,<=*y**i*) in the list, then there is no pair (*y**i*,<=*x**i*). | Print a single integer into the first line β the smallest number of souvenirs that the unluckiest student will have to present.
Following should be *m* lines, each containing two integers β the students which are familiar with each other. The first number in the pair must be the student that will present the souvenir to the second student in the pair.
Pairs can be printed in any order. If there are many solutions, print any of them. | [
"5 4\n2 1\n1 3\n2 3\n2 5\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 6\n1 2\n4 1\n4 2\n3 2\n4 3\n1 3\n"
] | [
"1\n1 2\n2 3\n3 1\n5 2\n",
"1\n1 4\n2 1\n3 1\n",
"2\n1 3\n2 1\n2 4\n3 2\n4 1\n4 3\n"
] | none | [] | 46 | 0 | 0 | 54,882 |
|
899 | Segments Removal | [
"data structures",
"dsu",
"flows",
"implementation",
"two pointers"
] | null | null | Vasya has an array of integers of length *n*.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after one operation it becomes [13,<=13,<=2,<=2,<=2].
Compute the number of operations Vasya should make until the array becomes empty, i.e. Vasya removes all elements from it. | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000) β the length of the array.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | [
"4\n2 5 5 2\n",
"5\n6 3 4 1 5\n",
"8\n4 4 4 2 2 100 100 100\n",
"6\n10 10 50 10 50 50\n"
] | [
"2\n",
"5\n",
"3\n",
"4\n"
] | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2,β2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. In each of them he removes the first element from the array.
In the third example Vasya needs three operations. In the first operation he removes all integers 4, in the second β all integers 100, in the third β all integers 2.
In the fourth example in the first operation Vasya removes the first two integers 10. After that the array becomes [50,β10,β50,β50]. Then in the second operation Vasya removes the two rightmost integers 50, so that the array becomes [50,β10]. In the third operation he removes the remaining 50, and the array becomes [10] after that. In the last, fourth operation he removes the only remaining 10. The array is empty after that. | [
{
"input": "4\n2 5 5 2",
"output": "2"
},
{
"input": "5\n6 3 4 1 5",
"output": "5"
},
{
"input": "8\n4 4 4 2 2 100 100 100",
"output": "3"
},
{
"input": "6\n10 10 50 10 50 50",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45",
"output": "1"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "2\n1 100",
"output": "2"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n100 100",
"output": "1"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "2"
},
{
"input": "3\n1 100 1",
"output": "3"
},
{
"input": "3\n1 5 6",
"output": "3"
},
{
"input": "3\n10 4 10",
"output": "3"
},
{
"input": "3\n10 10 4",
"output": "2"
},
{
"input": "4\n100 4 56 33",
"output": "4"
},
{
"input": "4\n1 2 2 1",
"output": "2"
},
{
"input": "4\n1 1 1 3",
"output": "2"
},
{
"input": "4\n5 1 1 1",
"output": "2"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "2\n21 21",
"output": "1"
},
{
"input": "3\n48 48 14",
"output": "2"
},
{
"input": "10\n69 69 69 69 69 13 69 7 69 7",
"output": "6"
},
{
"input": "20\n15 15 71 100 71 71 15 93 15 100 100 71 100 100 100 15 100 100 71 15",
"output": "14"
},
{
"input": "31\n17 17 17 17 29 17 17 29 91 17 29 17 91 17 29 17 17 17 29 17 17 17 17 17 17 17 17 29 29 17 17",
"output": "12"
},
{
"input": "43\n40 69 69 77 9 10 58 69 23 9 58 51 10 69 10 89 77 77 9 9 10 9 69 58 40 10 23 10 58 9 9 77 58 9 77 10 58 58 40 77 9 89 40",
"output": "38"
},
{
"input": "54\n34 75 90 23 47 13 68 37 14 39 48 41 42 100 19 43 68 47 13 47 48 65 45 89 56 86 67 52 87 81 86 63 44 9 89 21 86 89 20 43 43 37 24 43 77 14 43 42 99 92 49 99 27 40",
"output": "53"
},
{
"input": "66\n79 79 49 49 79 81 79 79 79 79 81 49 49 79 49 49 79 49 49 81 81 49 49 49 81 49 49 49 81 81 79 81 49 81 49 79 81 49 79 79 81 49 79 79 81 49 49 79 79 79 81 79 49 47 49 49 47 81 79 49 79 79 79 49 49 49",
"output": "34"
},
{
"input": "80\n80 86 39 5 58 20 66 61 32 75 93 20 57 20 20 61 45 17 86 43 31 75 37 80 92 10 6 18 21 8 93 92 11 75 86 39 53 27 45 77 20 20 1 80 66 13 11 51 58 11 31 51 73 93 15 88 6 32 99 6 39 87 6 39 6 80 8 45 46 45 23 53 23 58 24 53 28 46 87 68",
"output": "78"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7",
"output": "3"
},
{
"input": "9\n1 2 2 2 1 2 2 2 1",
"output": "3"
},
{
"input": "12\n1 1 1 49 63 63 63 19 38 38 65 27",
"output": "7"
},
{
"input": "7\n31 31 21 21 13 96 96",
"output": "4"
},
{
"input": "3\n1000000000 1 1000000000",
"output": "3"
}
] | 30 | 0 | 0 | 55,027 |
|
666 | World Tour | [
"graphs",
"shortest paths"
] | null | null | A famous sculptor Cicasso goes to a world tour!
Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will entirely hold the world tour in his native country β Berland.
Cicasso is very devoted to his work and he wants to be distracted as little as possible. Therefore he will visit only four cities. These cities will be different, so no one could think that he has "favourites". Of course, to save money, he will chose the shortest paths between these cities. But as you have probably guessed, Cicasso is a weird person. Although he doesn't like to organize exhibitions, he likes to travel around the country and enjoy its scenery. So he wants the total distance which he will travel to be as large as possible. However, the sculptor is bad in planning, so he asks you for help.
There are *n* cities and *m* one-way roads in Berland. You have to choose four different cities, which Cicasso will visit and also determine the order in which he will visit them. So that the total distance he will travel, if he visits cities in your order, starting from the first city in your list, and ending in the last, choosing each time the shortest route between a pair of cities β will be the largest.
Note that intermediate routes may pass through the cities, which are assigned to the tour, as well as pass twice through the same city. For example, the tour can look like that: . Four cities in the order of visiting marked as overlines: [1,<=5,<=2,<=4].
Note that Berland is a high-tech country. So using nanotechnologies all roads were altered so that they have the same length. For the same reason moving using regular cars is not very popular in the country, and it can happen that there are such pairs of cities, one of which generally can not be reached by car from the other one. However, Cicasso is very conservative and cannot travel without the car. Choose cities so that the sculptor can make the tour using only the automobile. It is guaranteed that it is always possible to do. | In the first line there is a pair of integers *n* and *m* (4<=β€<=*n*<=β€<=3000,<=3<=β€<=*m*<=β€<=5000) β a number of cities and one-way roads in Berland.
Each of the next *m* lines contains a pair of integers *u**i*,<=*v**i* (1<=β€<=*u**i*,<=*v**i*<=β€<=*n*) β a one-way road from the city *u**i* to the city *v**i*. Note that *u**i* and *v**i* are not required to be distinct. Moreover, it can be several one-way roads between the same pair of cities. | Print four integers β numbers of cities which Cicasso will visit according to optimal choice of the route. Numbers of cities should be printed in the order that Cicasso will visit them. If there are multiple solutions, print any of them. | [
"8 9\n1 2\n2 3\n3 4\n4 1\n4 5\n5 6\n6 7\n7 8\n8 5\n"
] | [
"2 1 8 7\n"
] | Let *d*(*x*,β*y*) be the shortest distance between cities *x* and *y*. Then in the example *d*(2,β1)β=β3,β*d*(1,β8)β=β7,β*d*(8,β7)β=β3. The total distance equals 13. | [] | 31 | 0 | 0 | 55,074 |
|
677 | Vanya and Food Processor | [
"implementation",
"math"
] | null | null | Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed *h* and the processor smashes *k* centimeters of potato each second. If there are less than *k* centimeters remaining, than during this second processor smashes all the remaining potato.
Vanya has *n* pieces of potato, the height of the *i*-th piece is equal to *a**i*. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number *n*. Formally, each second the following happens:
1. If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece. 1. Processor smashes *k* centimeters of potato (or just everything that is inside).
Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed. | The first line of the input contains integers *n*, *h* and *k* (1<=β€<=*n*<=β€<=100<=000,<=1<=β€<=*k*<=β€<=*h*<=β€<=109)Β β the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=*h*)Β β the heights of the pieces. | Print a single integerΒ β the number of seconds required to smash all the potatoes following the process described in the problem statement. | [
"5 6 3\n5 4 3 2 1\n",
"5 6 3\n5 5 5 5 5\n",
"5 6 3\n1 2 1 1 1\n"
] | [
"5\n",
"10\n",
"2\n"
] | Consider the first sample.
1. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside. 1. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining. 1. Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second. 1. Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3. 1. During this second processor finally smashes all the remaining potato and the process finishes.
In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2Β·5β=β10 seconds.
In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds. | [
{
"input": "5 6 3\n5 4 3 2 1",
"output": "5"
},
{
"input": "5 6 3\n5 5 5 5 5",
"output": "10"
},
{
"input": "5 6 3\n1 2 1 1 1",
"output": "2"
},
{
"input": "10 100 80\n76 75 73 71 76 74 73 70 78 75",
"output": "10"
},
{
"input": "10 100 88\n11 23 69 6 71 15 25 1 43 37",
"output": "5"
},
{
"input": "10 100 81\n100 97 96 98 98 95 100 97 97 99",
"output": "20"
},
{
"input": "10 1000000000 34\n262467899 490831561 793808758 450543931 364178715 95212706 14245051 92006075 424282318 436927280",
"output": "100720715"
},
{
"input": "10 1000000000 6\n510204596 367062507 635978332 260764751 339143281 377447788 893030825 977110226 643733983 575665576",
"output": "930023645"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "1 1000000000 1000000000\n1000000000",
"output": "1"
},
{
"input": "1 1000000000 1\n1000000000",
"output": "1000000000"
},
{
"input": "6 1000000000 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "6000000000"
},
{
"input": "20 1000000000 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "20000000000"
},
{
"input": "5 1000000000 1\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "5000000000"
},
{
"input": "10 1000000000 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "10000000000"
},
{
"input": "4 1000000000 1\n1000000000 1000000000 1000000000 1000000000",
"output": "4000000000"
},
{
"input": "10 1000000000 1\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999",
"output": "9999999990"
},
{
"input": "3 1000000000 1\n1000000000 1000000000 1000000000",
"output": "3000000000"
},
{
"input": "25 1000000000 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "25000000000"
},
{
"input": "10 900000000 1\n900000000 900000000 900000000 900000000 900000000 900000000 900000000 900000000 900000000 900000000",
"output": "9000000000"
},
{
"input": "2 1000000000 1\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "3 1000000000 1\n1000000000 1000000000 1",
"output": "2000000001"
},
{
"input": "3 1000000000 1\n999999999 999999999 999999999",
"output": "2999999997"
}
] | 139 | 13,619,200 | 3 | 55,096 |
|
37 | Lesson Timetable | [
"combinatorics",
"dp",
"math"
] | D. Lesson Timetable | 1 | 256 | When Petya has free from computer games time, he attends university classes. Every day the lessons on Petyaβs faculty consist of two double classes. The floor where the lessons take place is a long corridor with *M* classrooms numbered from 1 to *M*, situated along it.
All the students of Petyaβs year are divided into *N* groups. Petya has noticed recently that these groupsβ timetable has the following peculiarity: the number of the classroom where the first lesson of a group takes place does not exceed the number of the classroom where the second lesson of this group takes place.
Once Petya decided to count the number of ways in which one can make a lesson timetable for all these groups. The timetable is a set of 2*N* numbers: for each group the number of the rooms where the first and the second lessons take place. Unfortunately, he quickly lost the track of his calculations and decided to count only the timetables that satisfy the following conditions:
1) On the first lesson in classroom *i* exactly *X**i* groups must be present.
2) In classroom *i* no more than *Y**i* groups may be placed.
Help Petya count the number of timetables satisfying all those conditionsΡ As there can be a lot of such timetables, output modulo 109<=+<=7. | The first line contains one integer *M* (1<=β€<=*M*<=β€<=100) β the number of classrooms.
The second line contains *M* space-separated integers β *X**i* (0<=β€<=*X**i*<=β€<=100) the amount of groups present in classroom *i* during the first lesson.
The third line contains *M* space-separated integers β *Y**i* (0<=β€<=*Y**i*<=β€<=100) the maximal amount of groups that can be present in classroom *i* at the same time.
It is guaranteed that all the *X**i*<=β€<=*Y**i*, and that the sum of all the *X**i* is positive and does not exceed 1000. | In the single line output the answer to the problem modulo 109<=+<=7. | [
"3\n1 1 1\n1 2 3\n",
"3\n1 1 1\n1 1 1\n"
] | [
"36\n",
"6\n"
] | In the second sample test the first and the second lessons of each group must take place in the same classroom, thatβs why the timetables will only be different in the rearrangement of the classroomsβ numbers for each group, e.g. 3!β=β6. | [
{
"input": "3\n1 1 1\n1 2 3",
"output": "36"
},
{
"input": "3\n1 1 1\n1 1 1",
"output": "6"
},
{
"input": "3\n2 1 1\n5 1 2",
"output": "72"
},
{
"input": "5\n2 1 1 1 1\n5 3 1 1 3",
"output": "49320"
},
{
"input": "5\n1 3 15 3 18\n2 6 18 5 19",
"output": "921487545"
},
{
"input": "6\n3 8 2 6 18 2\n6 20 9 6 19 3",
"output": "693504502"
},
{
"input": "7\n3 4 7 8 6 5 2\n6 12 19 16 15 7 5",
"output": "913992323"
},
{
"input": "9\n1 1 1 3 6 1 4 2 1\n1 14 1 6 15 2 14 5 2",
"output": "853357529"
},
{
"input": "9\n7 1 4 7 8 4 5 7 1\n12 10 6 15 13 7 5 17 1",
"output": "71929769"
},
{
"input": "11\n4 12 2 1 2 9 13 1 12 9 1\n16 19 11 8 5 14 19 17 17 14 4",
"output": "737972006"
},
{
"input": "12\n1 5 1 1 4 3 1 1 1 1 1 1\n11 13 7 3 20 9 13 18 8 8 9 4",
"output": "14752815"
},
{
"input": "12\n2 8 18 8 1 8 3 4 2 3 4 13\n5 14 20 16 12 14 14 19 7 19 5 16",
"output": "825613060"
},
{
"input": "13\n3 4 1 2 14 3 5 4 4 2 3 1 1\n4 6 10 5 20 11 10 8 15 6 11 1 1",
"output": "326076016"
},
{
"input": "15\n3 5 2 10 1 3 5 11 3 1 1 4 2 3 2\n8 16 5 14 7 9 10 15 8 18 5 17 3 8 13",
"output": "13869964"
},
{
"input": "31\n1 6 1 13 41 6 1 2 9 23 30 34 11 6 10 14 7 2 2 6 14 8 12 7 4 5 22 6 22 3 14\n4 9 3 27 45 22 3 11 9 32 36 34 43 43 35 44 20 12 25 7 14 8 22 31 24 5 36 9 23 4 49",
"output": "402278182"
},
{
"input": "33\n3 27 7 10 1 1 17 15 2 7 1 10 1 1 9 1 10 4 2 24 10 3 8 21 13 3 8 19 6 22 10 9 19\n5 46 9 40 7 2 39 40 4 26 32 22 4 6 42 2 15 7 24 38 22 45 14 35 35 26 38 33 10 49 49 48 33",
"output": "702251119"
},
{
"input": "34\n4 17 3 9 12 3 13 1 1 13 22 8 1 3 14 5 3 13 2 4 8 3 5 7 5 3 32 12 6 4 3 19 13 1\n22 50 4 25 35 13 24 23 12 24 35 15 5 5 26 30 32 38 3 21 16 5 13 34 22 28 43 36 23 25 27 26 46 3",
"output": "529866511"
},
{
"input": "36\n1 9 20 9 9 1 4 1 11 5 14 1 5 8 7 5 8 10 1 1 2 1 4 15 4 6 9 11 17 4 1 8 1 12 15 18\n3 30 41 21 35 19 20 10 25 18 40 3 33 30 34 15 25 31 10 1 5 27 43 49 12 12 38 27 46 9 17 17 19 25 46 41",
"output": "862453940"
},
{
"input": "39\n23 4 6 2 11 1 2 17 36 1 13 9 14 9 4 6 2 20 3 2 31 6 16 1 3 11 36 3 2 15 3 3 27 20 5 9 17 26 20\n27 20 8 2 27 3 2 34 45 8 39 29 34 28 7 26 11 20 29 3 47 8 30 1 33 25 50 3 4 16 9 4 34 46 25 48 25 27 31",
"output": "533737639"
},
{
"input": "41\n1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1\n4 34 4 9 28 16 37 3 16 4 9 9 25 14 26 43 35 23 28 44 23 42 29 15 34 19 22 40 2 13 44 32 23 37 22 33 38 25 4 1 47",
"output": "641814964"
},
{
"input": "43\n5 6 28 30 15 34 18 2 5 8 8 5 9 16 10 9 9 18 2 13 2 16 4 7 2 19 9 1 11 32 32 27 20 12 24 3 8 6 24 1 6 25 32\n46 26 44 31 16 50 29 19 18 9 19 8 21 29 48 21 35 29 3 29 6 35 5 18 2 25 14 1 38 44 33 32 25 33 43 50 8 19 43 31 30 43 47",
"output": "495674257"
},
{
"input": "44\n21 21 2 6 12 15 1 10 35 3 5 2 7 4 1 10 1 2 6 21 11 3 10 24 27 1 35 10 18 17 5 30 9 9 26 1 20 2 20 5 9 27 6 14\n49 25 10 16 32 39 1 27 44 24 21 5 34 4 1 24 1 2 11 28 13 5 17 28 47 12 44 40 32 29 6 38 14 24 35 37 26 26 47 30 30 43 27 21",
"output": "566172318"
},
{
"input": "46\n20 27 5 4 2 23 7 38 2 1 2 23 1 34 3 3 11 31 3 11 2 10 22 6 11 43 9 4 16 20 3 22 16 20 6 12 6 30 26 17 1 16 3 13 9 27\n27 41 33 4 2 30 18 39 26 3 6 27 1 44 6 3 28 38 42 15 2 29 37 17 35 46 45 49 41 36 7 47 22 45 7 14 23 33 43 50 1 20 5 36 9 32",
"output": "584532065"
},
{
"input": "49\n16 2 9 15 24 5 27 14 22 38 7 1 25 21 12 3 4 4 1 14 26 1 1 10 16 7 1 3 7 32 4 29 13 35 1 1 18 21 2 4 7 1 40 13 31 11 1 1 1\n20 10 12 16 27 11 44 17 36 41 44 30 43 34 13 5 14 42 11 22 37 13 41 23 41 9 4 22 8 38 36 34 24 38 8 1 22 33 5 5 42 6 46 44 45 30 30 5 3",
"output": "58860600"
},
{
"input": "50\n5 1 2 1 1 1 1 1 1 1 2 2 3 2 1 3 1 2 6 1 1 4 3 1 1 4 1 3 1 1 1 3 1 6 3 1 6 1 1 2 4 2 1 1 2 7 7 3 1 2\n40 4 48 29 6 31 5 13 8 14 19 28 31 44 15 21 13 24 39 2 17 42 50 6 20 26 12 29 12 21 50 40 8 42 26 28 42 22 22 18 36 41 15 12 30 45 47 44 19 24",
"output": "710102803"
},
{
"input": "53\n16 2 21 18 8 12 4 25 1 14 19 12 7 3 6 18 26 7 15 5 30 3 6 3 16 12 9 33 8 10 7 4 1 25 5 5 4 14 39 3 9 32 1 17 3 1 3 14 4 14 38 18 34\n25 6 31 37 9 40 4 49 3 47 46 18 37 18 38 25 30 14 39 13 39 22 26 25 44 17 44 36 34 11 12 9 1 40 26 5 8 17 46 9 18 43 1 27 6 44 3 20 7 39 47 21 47",
"output": "211487936"
},
{
"input": "54\n3 14 2 1 17 1 1 9 29 6 24 22 23 18 40 13 8 28 28 2 3 7 1 1 18 12 2 1 1 11 25 31 6 14 11 22 10 34 27 14 8 1 5 6 4 7 3 33 12 18 4 7 16 14\n46 21 25 27 35 1 21 21 36 39 36 44 35 46 44 20 40 32 38 33 4 10 11 7 49 37 7 4 4 43 32 38 40 17 18 25 33 42 46 46 12 5 10 11 5 13 21 50 19 20 49 43 30 39",
"output": "117630575"
},
{
"input": "56\n1 7 18 5 3 7 1 2 6 35 22 33 7 15 27 28 26 4 25 1 7 15 8 23 3 10 1 28 15 11 3 2 3 21 11 8 15 15 3 19 18 1 1 2 11 4 12 15 18 34 4 1 7 7 3 14\n13 10 44 9 42 18 3 26 34 49 31 44 19 45 46 46 40 14 36 1 48 31 14 33 9 15 3 37 31 29 8 27 41 27 38 13 22 43 7 28 33 19 26 10 49 30 35 42 25 45 31 36 20 21 6 49",
"output": "491477817"
},
{
"input": "58\n18 32 4 18 1 8 6 36 6 7 7 13 46 2 30 7 7 14 33 19 18 2 13 3 24 17 9 7 9 18 15 24 11 47 4 35 25 18 2 15 13 30 9 13 8 1 1 1 4 8 4 29 4 30 4 30 7 2\n29 35 37 30 2 8 11 40 6 15 27 20 49 5 46 10 41 23 38 45 18 15 13 9 41 29 45 29 24 49 22 37 43 49 31 39 26 21 11 19 14 41 15 31 43 1 27 18 5 14 9 50 15 32 12 45 9 28",
"output": "724054067"
},
{
"input": "61\n5 9 22 6 1 28 27 5 10 31 3 11 28 1 33 37 5 14 4 30 2 25 12 19 3 2 4 7 1 10 14 1 3 16 21 3 34 23 7 15 8 1 15 8 7 27 1 7 21 4 5 6 18 3 6 6 25 6 2 29 12\n13 15 41 16 30 50 33 9 20 39 9 26 47 4 41 46 17 32 22 43 11 38 28 44 8 4 8 27 48 18 29 2 11 28 33 18 49 31 9 25 21 13 27 27 11 50 2 11 27 45 18 17 24 8 13 17 42 45 4 50 47",
"output": "595745980"
},
{
"input": "62\n24 1 19 3 3 1 3 19 5 5 17 9 29 3 1 1 14 22 16 4 19 14 6 4 20 1 32 16 16 3 3 6 20 3 13 27 26 6 2 24 14 14 13 15 9 22 29 19 32 27 10 13 16 27 41 3 4 5 10 4 6 25\n37 9 33 5 26 19 11 38 8 43 18 10 40 4 2 46 34 29 33 8 43 38 29 27 42 7 32 40 17 4 12 40 37 4 16 47 42 15 13 41 14 23 42 23 44 30 35 36 48 45 29 38 39 40 45 3 49 37 16 36 13 38",
"output": "141757536"
},
{
"input": "65\n4 3 1 11 11 8 13 12 6 6 1 1 3 1 1 3 6 9 2 11 1 7 1 1 5 10 6 2 4 2 1 10 1 7 3 1 12 4 14 12 4 5 6 3 1 14 8 3 8 6 9 3 4 8 2 5 1 1 1 1 5 3 8 3 7\n41 17 5 32 48 29 43 43 24 18 17 7 18 3 3 11 19 48 17 45 9 25 19 39 30 40 36 11 24 13 22 33 16 36 11 5 40 17 47 42 34 32 43 13 41 50 33 39 42 22 42 11 33 43 11 30 35 31 6 2 48 15 30 48 32",
"output": "6130930"
},
{
"input": "66\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n36 5 45 18 23 39 39 22 9 34 13 22 32 25 4 20 44 6 32 6 22 19 5 18 16 16 18 37 22 35 21 11 2 45 42 40 19 11 44 14 46 10 25 12 6 46 39 3 34 44 40 18 45 7 23 9 10 24 47 19 40 32 19 49 39 47",
"output": "617405015"
},
{
"input": "68\n20 11 33 2 11 3 7 8 8 2 2 3 15 2 23 6 8 3 8 45 4 28 4 20 8 4 17 14 17 26 1 1 2 2 3 2 5 2 11 45 8 1 8 10 21 19 8 14 34 21 8 5 15 7 6 20 28 5 27 16 26 13 8 16 25 2 4 26\n43 48 45 22 15 43 28 34 31 2 10 36 37 4 41 8 16 32 30 49 4 42 12 30 13 17 19 25 32 28 8 27 36 3 16 38 30 7 33 46 28 2 39 46 22 45 29 20 44 25 20 9 35 31 12 26 42 40 31 27 35 14 41 36 44 16 14 30",
"output": "866444570"
},
{
"input": "71\n1 1 2 1 4 1 3 3 2 1 1 4 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 4 2 1 1 1 1 2 5 3 1 4 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 4 1 1 1 2 1\n34 6 27 9 42 29 34 37 33 8 1 41 31 19 3 24 32 2 30 35 9 34 15 4 45 3 5 20 13 18 10 21 1 19 43 11 19 40 38 47 26 8 15 11 9 33 45 42 19 49 18 46 27 47 31 22 39 6 41 30 33 17 33 19 5 42 1 50 38 41 18",
"output": "293830358"
},
{
"input": "73\n16 6 3 1 8 2 11 10 3 2 4 1 8 5 1 6 5 1 1 1 4 1 6 1 12 8 1 1 1 1 4 3 11 5 21 16 1 11 8 12 13 3 2 2 5 4 9 14 5 10 4 11 1 3 8 2 6 4 6 2 15 1 11 3 1 8 13 6 1 6 12 10 6\n50 20 44 1 43 17 42 33 9 19 13 13 21 12 1 20 31 9 3 29 23 10 29 5 27 47 1 13 14 4 13 41 28 25 46 42 4 38 25 38 42 19 23 9 19 49 25 46 24 32 26 48 4 20 39 10 46 21 17 22 47 5 38 10 39 50 45 20 45 39 27 46 19",
"output": "163734088"
},
{
"input": "75\n35 14 6 10 9 1 26 39 15 7 2 21 8 7 23 5 1 41 6 29 5 11 3 17 6 10 16 12 3 18 10 6 2 3 10 11 3 2 8 41 9 6 3 3 34 1 1 21 6 27 11 4 16 42 4 4 16 1 1 6 6 1 36 12 1 4 40 2 1 10 24 1 14 8 6\n37 16 11 15 10 2 47 42 41 7 6 30 32 41 48 45 3 42 36 50 24 16 49 19 9 17 42 26 31 23 13 48 2 8 37 23 6 37 8 44 49 19 37 10 43 43 3 36 20 27 25 4 16 48 7 33 16 9 18 40 32 1 42 31 49 7 50 25 3 25 30 4 24 44 30",
"output": "946372299"
},
{
"input": "76\n1 5 3 1 1 1 4 6 3 3 2 5 6 5 1 6 1 2 1 1 1 4 9 7 2 2 2 2 1 1 3 1 4 9 1 2 1 1 1 1 1 3 1 6 4 3 4 1 1 6 2 7 2 7 8 2 3 2 1 1 1 7 2 1 1 1 1 3 1 1 1 3 1 2 1 1\n13 49 36 8 19 6 29 33 45 39 16 41 43 30 4 43 23 44 5 40 8 50 50 49 14 31 24 26 39 24 31 10 33 45 13 32 24 8 8 15 12 47 15 45 47 30 34 34 9 46 15 50 15 40 42 39 17 23 28 12 12 48 18 7 17 3 21 21 8 1 40 28 8 21 12 4",
"output": "883839172"
},
{
"input": "78\n4 1 8 15 10 1 10 2 1 1 2 2 14 5 3 1 14 12 6 9 2 14 1 1 5 23 8 2 2 2 6 7 1 6 1 1 5 10 1 3 9 8 20 23 11 9 1 1 5 1 2 13 19 12 8 1 8 1 15 1 3 4 8 7 2 14 1 1 1 4 14 1 12 2 1 1 12 2\n24 45 43 43 21 1 26 14 25 5 18 8 49 18 20 9 49 38 20 24 41 36 23 6 18 46 22 5 6 38 44 18 5 25 5 26 17 27 3 16 41 27 49 43 30 37 47 2 10 11 20 50 45 27 29 39 30 1 42 27 33 12 16 20 14 31 17 20 3 11 27 5 50 11 12 36 27 19",
"output": "589595389"
},
{
"input": "81\n5 7 1 24 2 9 3 11 27 13 4 7 29 10 29 5 6 12 23 1 4 8 26 21 12 1 10 13 11 1 21 2 10 1 6 7 15 12 20 11 2 1 3 4 9 5 5 6 26 4 8 7 30 24 2 2 21 6 6 1 27 7 34 19 10 17 24 18 27 8 10 6 1 18 1 1 4 8 6 5 1\n23 48 7 48 6 34 46 38 43 25 15 20 44 32 44 39 14 21 49 3 18 26 50 46 35 1 17 47 23 9 32 20 28 18 27 11 36 27 49 28 4 6 27 41 24 33 28 11 41 21 30 13 46 37 7 3 41 12 24 4 42 37 50 30 16 39 40 43 40 29 24 12 34 31 5 34 13 35 30 34 7",
"output": "828852281"
},
{
"input": "83\n4 7 5 10 3 3 7 1 6 1 8 2 1 1 4 9 10 7 3 1 1 11 3 1 14 3 1 7 7 6 12 8 3 3 1 7 1 2 2 3 1 1 1 2 2 1 2 5 10 1 4 9 3 10 6 1 4 3 5 1 11 7 1 11 2 11 5 1 6 4 6 1 5 7 2 7 5 1 1 16 1 1 12\n30 28 35 44 29 11 31 40 34 16 41 32 1 1 47 37 49 22 14 7 5 45 12 3 46 30 36 28 46 50 43 30 11 40 25 30 2 21 9 12 1 19 16 22 30 7 8 37 50 11 39 45 23 38 21 33 26 15 16 5 49 42 42 50 20 50 25 3 30 16 26 2 25 49 19 23 23 39 2 49 30 8 42",
"output": "483023345"
},
{
"input": "85\n1 15 2 2 2 3 1 5 6 6 1 9 10 12 4 6 10 1 5 17 9 17 6 17 1 3 3 2 4 1 5 1 1 21 1 14 3 1 1 3 11 2 6 4 13 1 4 10 1 1 5 17 8 6 20 6 1 4 11 18 3 18 12 1 13 3 1 12 1 6 10 1 1 2 8 3 2 4 5 1 3 2 16 3 2\n1 33 25 16 25 15 25 12 27 32 2 34 26 38 15 26 38 27 13 38 34 42 50 49 5 12 18 16 10 2 17 29 33 46 14 34 8 35 2 10 42 13 23 19 33 1 17 23 21 39 47 49 24 32 47 22 5 17 38 43 12 41 29 28 39 8 15 46 4 21 30 3 6 28 41 15 10 9 11 2 23 23 42 43 19",
"output": "242744849"
},
{
"input": "86\n1 9 13 4 17 15 1 2 10 6 8 1 5 4 3 9 1 3 8 6 18 11 4 17 2 1 20 1 19 15 1 1 6 5 8 15 5 5 1 12 1 4 4 11 1 5 13 7 2 2 7 19 2 7 7 2 10 2 3 17 2 5 1 9 1 16 5 2 15 1 1 8 1 10 18 1 1 21 4 2 6 10 3 8 1 4\n16 46 46 39 33 31 4 16 23 24 17 4 13 37 8 26 1 10 19 45 35 40 20 43 8 14 50 14 38 44 9 4 27 27 27 31 19 38 38 25 9 15 45 30 3 29 42 38 42 6 28 40 5 22 19 42 35 9 22 45 6 14 1 19 9 34 26 9 33 21 7 18 4 35 37 2 25 44 12 14 25 22 29 16 23 16",
"output": "506023527"
},
{
"input": "88\n5 3 8 1 1 2 8 1 4 1 1 4 14 5 2 1 11 1 3 1 8 5 4 1 11 2 1 3 7 1 12 2 1 3 1 4 1 6 1 1 1 6 1 4 8 7 11 2 1 1 1 1 5 4 11 1 1 2 14 12 3 7 1 6 2 1 1 4 5 1 1 1 6 4 2 1 15 11 1 1 1 1 1 11 1 6 9 9\n26 16 40 16 35 6 44 12 24 10 2 27 49 42 29 33 41 25 39 7 27 18 14 12 40 48 37 11 46 1 46 20 31 47 3 14 27 27 26 2 27 21 23 14 28 36 40 11 45 22 8 5 41 49 38 22 16 13 42 42 15 25 5 31 44 28 10 37 46 1 38 5 28 24 8 4 48 44 17 9 15 9 7 38 35 23 41 29",
"output": "555203608"
},
{
"input": "91\n1 1 1 5 5 1 4 1 1 1 3 1 15 9 6 1 4 1 1 1 3 1 4 1 1 1 6 1 1 2 2 4 7 2 2 4 12 5 8 1 1 9 1 1 5 17 5 1 2 5 1 2 3 1 5 1 2 1 7 1 1 1 7 14 7 5 3 1 1 1 2 1 1 13 3 3 7 4 1 6 11 3 16 2 1 1 1 3 1 5 1\n14 11 4 26 22 5 32 37 1 3 35 16 42 43 30 4 41 22 6 13 29 21 39 25 13 1 44 30 8 16 46 34 39 8 14 30 42 32 50 9 2 43 3 17 19 45 44 1 23 19 9 22 22 13 20 18 30 2 28 20 21 8 43 48 24 30 9 6 7 13 37 7 4 39 20 14 48 11 34 37 42 25 46 7 5 5 3 49 44 43 12",
"output": "468862344"
},
{
"input": "92\n5 2 4 1 5 1 4 4 4 1 6 5 2 7 3 4 6 8 2 2 4 1 5 8 2 1 1 2 5 1 8 6 1 5 1 4 1 2 1 2 1 1 1 2 4 1 3 2 1 1 8 9 1 1 1 2 5 1 7 6 1 1 8 4 6 1 3 1 1 5 2 10 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 3\n48 16 21 14 38 10 18 29 32 10 34 36 10 36 31 30 43 45 14 13 48 5 48 35 9 8 43 16 44 32 47 43 31 29 12 24 2 41 24 11 3 13 16 37 25 5 34 19 18 3 36 44 5 41 22 45 33 3 32 29 23 2 47 29 47 15 18 3 3 45 10 50 15 12 1 33 6 1 12 29 12 8 18 37 40 1 2 1 39 7 5 16",
"output": "539103246"
},
{
"input": "94\n5 1 2 1 7 5 9 1 1 8 2 2 1 4 1 1 2 1 8 3 2 3 1 7 1 7 6 1 3 11 7 5 1 12 1 7 5 8 1 17 16 4 1 1 8 1 10 2 1 5 1 1 1 3 1 6 8 4 1 3 4 1 2 5 2 1 1 5 4 1 14 1 1 2 1 2 2 1 13 1 3 11 6 5 1 5 6 1 1 19 5 9 1 3\n33 6 6 2 29 46 36 1 18 30 20 15 12 19 22 5 43 17 19 19 43 49 5 28 34 37 31 16 32 31 30 21 5 39 3 24 37 37 3 48 43 24 2 28 27 2 34 12 37 13 6 10 11 16 4 18 36 21 17 8 39 41 9 48 37 8 9 32 18 31 35 17 21 49 3 39 7 30 47 6 23 28 22 17 20 41 22 18 4 50 24 44 7 46",
"output": "262765740"
},
{
"input": "97\n1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 4 2 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 2 1 1 2 1 2 3 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 3 3 1 2 1 1 2 1\n5 50 21 19 15 47 47 37 19 40 30 6 45 8 18 12 50 38 7 14 25 17 11 23 22 21 17 7 38 28 44 50 34 26 42 20 37 15 46 29 13 45 30 13 35 44 49 31 8 3 41 9 46 11 41 41 28 42 7 29 30 5 31 24 34 26 32 21 26 44 16 31 11 12 2 34 45 46 16 19 24 21 42 35 16 11 50 24 32 42 42 6 31 3 4 42 48",
"output": "797106359"
},
{
"input": "99\n4 6 12 1 1 1 1 1 6 4 10 16 2 1 2 14 11 12 19 8 5 4 11 6 10 2 10 20 1 6 18 2 10 1 2 4 18 3 1 2 3 3 4 24 1 1 3 10 1 1 15 14 20 1 5 8 11 3 6 1 1 12 3 6 1 2 4 8 3 15 10 3 1 1 1 4 7 1 2 2 1 5 3 13 12 7 1 6 12 1 1 8 19 6 16 4 7 1 9\n41 13 28 11 1 15 1 45 16 21 34 44 6 32 14 41 36 32 40 15 24 46 34 21 27 31 44 50 43 28 49 5 19 31 7 25 35 27 7 32 8 9 8 44 2 6 40 44 17 1 30 50 49 44 10 22 21 10 20 4 42 44 10 17 1 5 46 16 7 35 38 7 17 19 1 8 19 8 14 11 21 11 12 39 44 25 36 21 26 1 50 37 50 33 34 12 23 34 34",
"output": "254350197"
},
{
"input": "98\n2 4 2 3 3 3 7 1 1 7 2 2 3 5 3 1 1 1 9 1 4 4 1 9 1 4 1 1 1 1 7 1 1 7 3 1 2 3 3 5 7 1 1 1 1 3 3 1 2 1 3 1 1 3 3 3 3 1 8 1 2 4 8 3 4 8 1 7 1 5 4 1 8 1 1 1 3 1 1 2 1 1 8 1 5 5 1 1 1 1 1 1 5 2 10 2 2 1\n28 43 77 89 93 47 63 32 29 90 33 33 78 99 77 15 47 2 86 19 52 60 30 79 17 69 25 16 20 29 69 70 12 92 37 51 22 56 66 59 68 19 17 7 49 50 55 21 86 3 54 54 12 56 51 80 55 6 71 9 33 39 96 58 57 81 2 96 17 93 72 83 81 16 19 21 33 21 7 36 71 49 89 13 62 49 25 34 36 80 6 77 69 70 97 75 29 15",
"output": "417897655"
},
{
"input": "99\n1 4 1 3 8 1 8 1 1 3 1 2 1 4 1 1 6 3 8 2 2 4 1 3 3 3 2 6 1 5 6 6 3 1 1 1 1 1 2 6 1 2 1 7 2 5 5 2 7 2 1 2 1 1 1 7 1 4 1 6 1 6 1 3 1 4 3 1 1 5 2 5 1 1 9 1 1 2 2 7 6 5 7 1 1 1 1 1 2 3 2 2 6 5 1 7 1 1 1\n24 45 71 50 91 37 92 10 65 38 50 59 29 77 22 10 82 77 89 25 44 72 9 98 98 80 34 81 13 91 86 89 67 56 18 23 38 31 91 94 21 32 89 76 63 69 60 52 87 55 14 22 53 33 27 87 83 81 65 98 9 94 12 76 22 76 55 52 8 59 61 76 64 44 97 14 56 42 62 84 87 86 99 17 25 52 20 5 48 100 36 33 76 89 13 76 40 42 63",
"output": "598966230"
},
{
"input": "96\n11 18 7 3 2 1 11 11 11 1 4 7 1 1 1 12 2 1 1 3 2 3 3 1 2 7 4 8 2 9 1 3 7 4 1 3 21 16 10 3 1 1 2 9 9 1 2 9 6 8 2 15 1 2 12 10 7 1 4 1 1 9 8 2 4 3 7 5 1 23 3 1 4 4 1 4 9 16 5 20 1 2 3 3 1 8 6 8 11 24 2 9 4 13 10 8\n65 87 48 15 16 16 70 53 86 6 49 30 38 10 79 50 33 31 86 22 21 52 19 15 68 36 79 57 15 45 2 18 87 26 3 69 83 69 93 15 4 9 85 61 39 5 25 59 91 79 63 98 5 42 76 52 30 97 93 47 8 57 82 50 21 35 62 52 39 92 16 14 30 19 65 17 61 70 36 90 69 45 24 89 21 42 94 50 72 95 28 95 26 60 51 40",
"output": "701815457"
},
{
"input": "96\n24 1 15 29 12 2 2 2 28 10 27 1 5 12 15 17 1 1 3 23 11 11 7 6 4 10 4 2 15 3 1 8 5 16 1 12 10 2 8 17 21 3 26 1 1 6 22 5 21 8 8 1 3 4 1 1 1 1 29 4 24 1 3 3 1 6 1 4 1 6 2 1 11 8 1 9 8 9 6 9 4 3 1 13 1 1 4 31 5 22 20 4 17 14 7 1\n91 7 49 87 41 63 25 10 89 61 85 5 81 45 53 68 4 5 32 81 36 59 93 46 65 49 44 29 52 54 16 55 76 83 11 47 64 8 91 100 87 75 76 26 15 41 95 17 75 36 45 4 29 26 26 28 24 5 99 75 95 4 12 13 4 93 79 26 74 29 63 30 84 97 22 68 87 45 43 56 76 80 16 64 20 1 58 94 50 81 76 16 100 63 24 68",
"output": "914414631"
},
{
"input": "100\n1 2 1 1 1 3 6 1 1 3 1 1 6 2 1 2 4 1 2 1 2 1 1 1 1 1 1 1 3 1 3 5 1 1 2 1 1 1 1 2 1 1 1 4 3 1 2 1 1 1 2 1 1 3 4 1 2 1 3 2 3 2 4 1 1 2 2 2 1 1 1 3 1 5 2 3 1 1 2 1 1 1 4 1 1 1 3 1 1 2 2 3 1 1 1 2 1 2 6 1\n14 71 1 75 39 64 94 28 93 93 51 40 96 57 73 85 94 41 78 44 95 44 3 25 18 23 32 17 85 69 91 78 33 47 34 74 31 34 28 60 44 12 68 82 46 35 50 38 81 74 44 18 55 50 67 83 100 2 99 33 87 75 94 10 43 49 54 86 35 84 50 66 34 77 73 98 28 58 43 65 11 49 74 21 19 13 46 43 82 99 37 64 16 95 16 67 28 57 89 24",
"output": "495136672"
},
{
"input": "98\n1 2 12 12 11 1 2 2 4 1 3 7 10 2 1 2 6 1 1 4 9 1 10 9 1 2 1 3 9 3 2 1 2 2 3 12 4 10 1 15 10 3 1 1 4 4 11 3 2 6 15 15 1 14 7 13 13 4 6 5 13 14 1 1 4 1 1 6 1 1 4 8 1 1 8 3 10 17 1 3 1 3 2 1 5 1 1 13 3 1 7 1 6 8 1 2 9 6\n9 93 81 73 82 19 32 59 27 4 23 90 78 70 7 21 94 16 57 74 47 10 91 71 20 13 26 22 95 16 18 17 12 65 45 70 78 50 41 72 84 20 29 24 37 43 60 17 77 32 91 89 58 70 53 62 60 25 30 94 65 70 5 40 58 21 5 92 24 14 37 70 12 5 55 20 59 98 65 23 11 81 35 62 64 71 3 83 19 11 74 49 51 69 52 72 43 35",
"output": "577974735"
},
{
"input": "100\n3 1 4 9 4 7 5 2 5 12 1 13 4 1 2 11 1 6 3 2 7 1 1 4 1 2 1 9 7 8 3 1 1 4 11 1 1 6 5 1 1 12 1 10 7 1 1 2 1 7 10 2 2 2 8 1 1 15 5 5 3 1 4 9 1 5 6 16 4 8 7 6 4 1 2 4 5 1 2 5 4 1 1 2 5 1 2 5 1 7 1 1 1 1 13 5 1 1 6 5\n64 11 30 56 49 88 96 50 81 87 14 78 70 9 54 68 24 80 47 14 47 61 7 58 9 90 2 89 61 57 40 21 37 31 91 16 61 62 34 18 2 72 8 75 48 5 7 23 9 53 69 32 55 24 58 24 45 95 72 40 55 10 54 82 33 48 62 100 49 89 99 98 42 69 15 56 33 70 22 38 64 2 21 23 90 18 16 34 92 56 25 55 91 6 90 67 7 18 43 36",
"output": "98721170"
},
{
"input": "97\n1 11 7 2 4 20 5 4 2 2 6 3 1 6 1 1 1 5 1 4 16 12 4 1 1 2 8 5 1 7 16 11 1 1 1 1 2 3 1 7 1 2 9 1 2 21 1 6 4 1 5 14 1 13 4 6 18 2 10 17 4 7 18 2 7 1 8 1 1 1 4 10 11 14 1 1 5 7 3 2 4 5 14 7 11 11 3 12 4 1 1 1 7 18 9 8 11\n57 66 40 57 35 97 41 40 11 25 59 23 12 32 70 63 55 76 18 34 75 89 55 4 2 20 50 35 10 56 83 64 25 39 21 79 25 38 32 34 16 10 58 18 17 95 14 56 94 13 52 74 68 70 28 52 82 21 46 92 66 43 91 18 54 36 67 8 80 2 41 87 55 75 23 12 48 73 23 61 62 38 94 73 70 74 21 67 51 6 39 72 47 84 93 64 61",
"output": "352661963"
},
{
"input": "98\n13 8 14 6 5 10 2 3 2 2 1 2 5 1 10 11 1 11 6 3 1 4 4 2 1 5 11 1 3 1 1 1 13 11 1 1 1 1 5 4 14 10 1 1 1 1 2 5 1 6 1 9 5 3 4 1 3 1 12 7 5 4 2 2 1 1 2 7 10 2 7 7 1 9 1 11 1 9 8 4 3 4 14 1 1 2 1 9 5 3 4 7 1 13 1 2 1 2\n93 47 86 43 36 60 60 56 22 100 6 18 89 6 63 64 18 92 67 40 35 49 81 28 1 35 84 48 63 2 61 2 77 83 11 1 18 10 62 38 87 84 9 10 17 30 52 73 11 53 27 65 97 47 33 9 58 52 85 71 55 83 44 18 6 41 85 65 100 41 84 94 12 83 20 91 29 92 81 29 32 28 91 20 8 44 9 97 91 24 50 88 44 98 35 25 7 33",
"output": "399942311"
},
{
"input": "96\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n17 71 52 81 51 92 15 54 94 47 14 19 96 39 21 86 79 47 25 53 48 22 29 33 15 20 71 37 96 59 72 87 68 75 15 66 83 41 91 90 20 80 96 42 63 35 70 9 34 85 23 2 4 69 28 25 49 26 72 80 49 41 44 98 72 46 12 35 71 98 96 61 50 96 40 49 85 15 13 52 23 61 70 55 57 84 12 8 88 60 70 66 51 38 58 24",
"output": "157429506"
},
{
"input": "99\n1 1 2 1 4 1 3 1 4 4 1 2 1 1 1 1 3 4 1 3 1 1 2 1 1 1 1 1 2 1 1 1 5 1 1 1 1 1 3 4 3 2 1 1 2 1 1 1 4 2 2 1 1 3 1 1 1 1 1 1 2 1 1 2 4 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 3 2 1 4 1 1 1 1 1 1 1 2 1 4 1\n42 51 42 43 77 74 75 51 96 85 50 99 21 18 43 16 80 71 38 73 52 20 64 37 40 48 3 20 72 77 9 25 95 56 25 13 8 90 54 79 78 46 26 11 62 12 4 24 84 59 75 9 50 92 5 27 17 5 32 49 91 23 12 43 99 12 67 36 77 18 20 60 89 66 37 10 20 58 57 11 19 63 58 2 75 72 12 90 51 17 32 67 33 49 2 57 13 77 43",
"output": "986939833"
},
{
"input": "100\n1 4 4 1 7 4 1 1 1 2 4 5 1 1 3 2 1 5 2 1 3 1 2 3 3 1 1 1 2 2 1 1 1 1 1 3 3 4 2 4 1 1 3 1 3 1 2 1 2 1 3 1 1 1 1 2 1 2 1 7 1 1 1 1 1 4 7 1 7 3 2 4 1 2 2 8 6 2 2 1 1 6 8 6 3 4 2 7 4 5 1 8 6 1 1 1 1 1 5 1\n11 58 48 88 85 67 50 77 62 75 93 52 53 14 65 80 22 72 47 1 75 7 76 46 42 25 48 7 58 51 8 48 2 7 4 69 100 95 41 99 58 7 96 61 61 35 26 20 57 3 70 42 15 70 58 96 8 79 2 73 22 3 28 49 2 68 90 90 81 31 31 82 21 32 22 86 71 53 45 33 23 75 95 95 33 48 51 79 76 86 31 94 81 22 34 22 49 58 78 23",
"output": "867199119"
},
{
"input": "99\n2 12 1 6 6 1 4 4 1 1 4 1 2 1 6 4 1 5 1 2 7 10 6 3 6 1 4 8 3 1 1 4 1 3 1 4 4 7 3 5 5 1 1 6 9 6 2 1 3 6 3 3 3 2 3 1 1 2 2 1 5 8 5 1 1 1 1 2 9 1 11 1 1 6 2 6 1 1 1 2 7 1 4 1 4 1 3 2 3 6 1 1 3 5 6 6 5 1 1\n57 98 82 89 93 69 99 84 11 7 68 35 32 37 99 82 11 66 14 71 80 86 50 30 83 40 83 81 42 21 14 36 11 32 49 71 39 69 55 75 82 13 53 93 96 69 38 23 29 50 32 48 46 39 57 8 18 66 51 10 58 67 96 57 14 10 30 88 93 15 96 37 45 77 43 58 9 4 10 39 93 42 43 25 81 55 40 22 30 88 27 15 72 40 94 57 38 6 32",
"output": "52488242"
},
{
"input": "96\n1 3 1 1 1 1 2 1 1 1 1 1 1 2 1 1 3 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 2 1 2 3 1 1 1 1 1 2 3 1 1 1 1 1 1 1 1 2 1 2 1 1 3 1 3 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 3 1 5 5 1 2 1 3 1 3 1\n26 78 33 33 5 34 100 4 6 97 72 14 13 93 58 79 90 17 40 10 32 63 11 21 47 93 34 22 26 36 65 25 26 72 76 79 85 89 61 41 4 66 25 43 57 17 48 10 26 32 24 27 72 51 62 45 61 23 78 39 86 40 14 43 34 61 98 28 21 27 23 33 18 49 87 63 49 23 38 19 6 26 77 14 4 97 50 96 91 68 49 61 95 83 98 27",
"output": "374095891"
},
{
"input": "97\n1 1 1 1 1 4 1 1 4 2 4 1 4 1 8 1 1 1 2 2 1 1 1 1 1 1 8 6 2 5 3 1 6 5 1 1 1 2 1 3 1 3 8 2 1 3 4 1 1 1 2 6 2 1 1 1 1 4 1 2 3 1 3 1 1 8 4 1 1 1 1 1 4 1 1 1 1 1 1 5 1 7 1 1 6 1 3 4 1 1 1 8 3 1 5 5 6\n38 27 31 69 71 88 23 14 48 51 47 81 56 39 96 63 12 54 69 41 65 73 63 44 53 14 96 69 42 89 88 31 71 68 8 68 16 55 13 56 58 45 91 74 37 49 87 36 49 21 36 91 94 42 23 73 24 94 67 58 52 41 38 12 64 100 69 2 78 10 36 73 54 54 20 42 40 30 15 77 76 99 84 13 97 38 57 50 33 17 43 97 99 80 57 72 87",
"output": "726040274"
},
{
"input": "100\n3 5 1 1 1 3 1 4 1 3 1 1 1 1 3 2 1 3 2 5 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 3 1 1 3 1 4 2 1 1 1 1 3 4 1 4 1 1 1 1 2 1 4 2 2 1 1 4 5 1 1 1 3 3 1 1 3 3 3 1 1 2 1 5 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 3 1 1 1 1 1\n87 83 15 23 27 79 31 71 9 67 44 9 62 33 65 42 57 99 65 89 21 43 46 14 12 58 28 4 61 1 5 27 3 43 55 99 75 37 25 99 83 97 73 68 9 24 63 72 80 44 73 67 68 26 54 52 41 72 51 61 32 40 97 99 73 48 84 67 98 52 25 61 62 55 14 39 35 3 100 94 17 16 56 41 21 45 7 76 47 31 16 62 25 15 79 11 9 92 32 95",
"output": "774150918"
},
{
"input": "98\n10 2 12 2 1 3 1 14 23 5 1 17 2 2 2 4 1 1 3 5 5 1 9 1 4 1 6 13 1 3 1 12 8 16 1 7 5 3 6 4 1 9 1 14 1 5 1 1 2 1 1 9 1 3 23 2 4 6 10 2 14 9 1 3 13 14 1 10 4 6 9 5 1 13 12 1 20 14 5 5 14 1 5 8 9 1 5 7 8 1 1 4 8 3 14 8 6 1\n78 51 80 17 2 60 26 98 97 63 40 96 29 94 9 51 59 8 45 39 25 3 40 85 66 5 36 58 57 22 18 73 98 84 10 49 41 17 46 25 65 89 7 59 30 30 4 25 15 2 17 71 25 21 98 15 18 44 97 51 83 87 68 43 78 63 12 56 37 69 75 38 5 73 51 15 100 100 72 26 71 7 38 77 85 21 24 71 82 21 11 19 81 54 81 59 95 81",
"output": "453188792"
},
{
"input": "96\n1 1 1 3 1 2 1 2 1 1 1 1 1 3 1 1 1 1 4 1 4 1 1 1 1 3 4 1 1 1 1 1 1 1 6 1 3 1 1 4 3 1 1 2 1 1 1 1 1 1 3 1 1 3 1 1 2 6 2 1 5 1 1 1 1 1 1 1 4 2 2 1 2 3 5 1 1 1 3 1 5 1 1 3 3 1 1 2 3 2 1 1 3 1 1 1\n98 13 18 41 27 29 64 49 56 14 64 40 66 79 35 51 57 18 76 8 89 50 3 100 34 95 57 3 28 4 82 84 27 36 97 6 49 71 32 60 47 14 26 38 19 6 19 13 33 45 44 3 33 95 12 53 87 90 55 11 80 11 11 43 30 11 90 39 100 47 46 2 71 69 73 63 50 40 69 22 98 20 17 53 99 71 18 73 78 77 87 2 93 29 13 62",
"output": "144833882"
}
] | 1,000 | 31,744,000 | 0 | 55,115 |
183 | Headquarters | [
"constructive algorithms",
"math"
] | null | null | Sensation, sensation in the two-dimensional kingdom! The police have caught a highly dangerous outlaw, member of the notorious "Pihters" gang. The law department states that the outlaw was driving from the gang's headquarters in his car when he crashed into an ice cream stall. The stall, the car, and the headquarters each occupies exactly one point on the two-dimensional kingdom.
The outlaw's car was equipped with a GPS transmitter. The transmitter showed that the car made exactly *n* movements on its way from the headquarters to the stall. A movement can move the car from point (*x*,<=*y*) to one of these four points: to point (*x*<=-<=1,<=*y*) which we will mark by letter "L", to point (*x*<=+<=1,<=*y*) β "R", to point (*x*,<=*y*<=-<=1) β "D", to point (*x*,<=*y*<=+<=1) β "U".
The GPS transmitter is very inaccurate and it doesn't preserve the exact sequence of the car's movements. Instead, it keeps records of the car's possible movements. Each record is a string of one of these types: "UL", "UR", "DL", "DR" or "ULDR". Each such string means that the car made a single movement corresponding to one of the characters of the string. For example, string "UL" means that the car moved either "U", or "L".
You've received the journal with the outlaw's possible movements from the headquarters to the stall. The journal records are given in a chronological order. Given that the ice-cream stall is located at point (0,<=0), your task is to print the number of different points that can contain the gang headquarters (that is, the number of different possible locations of the car's origin). | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=2Β·105) β the number of the car's movements from the headquarters to the stall.
Each of the following *n* lines describes the car's possible movements. It is guaranteed that each possible movement is one of the following strings: "UL", "UR", "DL", "DR" or "ULDR".
All movements are given in chronological order.
Please do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin and cout stream or the %I64d specifier. | Print a single integer β the number of different possible locations of the gang's headquarters. | [
"3\nUR\nUL\nULDR\n",
"2\nDR\nDL\n"
] | [
"9\n",
"4\n"
] | The figure below shows the nine possible positions of the gang headquarters from the first sample:
For example, the following movements can get the car from point (1,β0) to point (0,β0): | [
{
"input": "3\nUR\nUL\nULDR",
"output": "9"
},
{
"input": "2\nDR\nDL",
"output": "4"
},
{
"input": "4\nUL\nUR\nDR\nDL",
"output": "9"
},
{
"input": "10\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL",
"output": "11"
},
{
"input": "6\nUL\nDL\nDL\nUL\nUL\nDL",
"output": "16"
},
{
"input": "1\nUL",
"output": "2"
},
{
"input": "1\nUR",
"output": "2"
},
{
"input": "1\nDR",
"output": "2"
},
{
"input": "1\nDL",
"output": "2"
},
{
"input": "1\nULDR",
"output": "4"
},
{
"input": "2\nUL\nULDR",
"output": "6"
},
{
"input": "4\nULDR\nUR\nULDR\nUR",
"output": "15"
},
{
"input": "10\nUR\nDR\nUL\nDR\nUL\nULDR\nUR\nUL\nULDR\nUL",
"output": "45"
},
{
"input": "4\nUL\nUR\nDR\nDL",
"output": "9"
},
{
"input": "10\nUL\nUR\nUR\nDR\nDR\nDR\nDL\nDL\nDL\nDL",
"output": "35"
},
{
"input": "6\nUR\nDL\nUR\nDL\nUR\nDL",
"output": "7"
}
] | 778 | 0 | 3 | 55,169 |
|
1,005 | Median on Segments (Permutations Edition) | [
"sortings"
] | null | null | You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$.
The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.
For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence.
Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. | The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) β the length of the given sequence and the required value of the median.
The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. | Print the required number. | [
"5 4\n2 4 5 3 1\n",
"5 5\n1 2 3 4 5\n",
"15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n"
] | [
"4\n",
"1\n",
"48\n"
] | In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$. | [
{
"input": "5 4\n2 4 5 3 1",
"output": "4"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9",
"output": "48"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "2 1\n2 1",
"output": "2"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "2"
},
{
"input": "3 1\n1 3 2",
"output": "2"
},
{
"input": "3 1\n2 1 3",
"output": "3"
},
{
"input": "3 1\n2 3 1",
"output": "2"
},
{
"input": "3 1\n3 1 2",
"output": "3"
},
{
"input": "3 1\n3 2 1",
"output": "2"
},
{
"input": "5 2\n2 1 3 4 5",
"output": "3"
},
{
"input": "6 3\n3 6 1 4 2 5",
"output": "6"
},
{
"input": "7 4\n1 7 6 4 2 3 5",
"output": "10"
},
{
"input": "8 7\n2 3 6 8 7 5 4 1",
"output": "4"
},
{
"input": "9 9\n6 4 8 5 1 7 2 9 3",
"output": "1"
},
{
"input": "10 1\n6 9 8 10 4 3 7 1 5 2",
"output": "3"
},
{
"input": "11 2\n9 4 7 5 11 1 3 8 10 2 6",
"output": "3"
},
{
"input": "12 3\n6 4 3 7 8 10 1 2 11 5 12 9",
"output": "4"
},
{
"input": "14 5\n13 14 5 11 3 2 10 8 12 9 6 1 7 4",
"output": "10"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "3"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "182"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "1"
}
] | 3,000 | 13,107,200 | 0 | 55,226 |
|
528 | Fuzzy Search | [
"bitmasks",
"brute force",
"fft"
] | null | null | Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings consisting of letters 'A', 'T', 'G' and 'C'.
Let's consider the following scenario. There is a fragment of a human DNA chain, recorded as a string *S*. To analyze the fragment, you need to find all occurrences of string *T* in a string *S*. However, the matter is complicated by the fact that the original chain fragment could contain minor mutations, which, however, complicate the task of finding a fragment. Leonid proposed the following approach to solve this problem.
Let's write down integer *k*<=β₯<=0 β the error threshold. We will say that string *T* occurs in string *S* on position *i* (1<=β€<=*i*<=β€<=|*S*|<=-<=|*T*|<=+<=1), if after putting string *T* along with this position, each character of string *T* corresponds to the some character of the same value in string *S* at the distance of at most *k*. More formally, for any *j* (1<=β€<=*j*<=β€<=|*T*|) there must exist such *p* (1<=β€<=*p*<=β€<=|*S*|), that |(*i*<=+<=*j*<=-<=1)<=-<=*p*|<=β€<=*k* and *S*[*p*]<==<=*T*[*j*].
For example, corresponding to the given definition, string "ACAT" occurs in string "AGCAATTCAT" in positions 2, 3 and 6.
Note that at *k*<==<=0 the given definition transforms to a simple definition of the occurrence of a string in a string.
Help Leonid by calculating in how many positions the given string *T* occurs in the given string *S* with the given error threshold. | The first line contains three integers |*S*|,<=|*T*|,<=*k* (1<=β€<=|*T*|<=β€<=|*S*|<=β€<=200<=000, 0<=β€<=*k*<=β€<=200<=000) β the lengths of strings *S* and *T* and the error threshold.
The second line contains string *S*.
The third line contains string *T*.
Both strings consist only of uppercase letters 'A', 'T', 'G' and 'C'. | Print a single number β the number of occurrences of *T* in *S* with the error threshold *k* by the given definition. | [
"10 4 1\nAGCAATTCAT\nACAT\n"
] | [
"3\n"
] | If you happen to know about the structure of the human genome a little more than the author of the problem, and you are not impressed with Leonid's original approach, do not take everything described above seriously. | [
{
"input": "10 4 1\nAGCAATTCAT\nACAT",
"output": "3"
},
{
"input": "1 1 0\nA\nA",
"output": "1"
},
{
"input": "1 1 0\nA\nT",
"output": "0"
},
{
"input": "1 1 1\nA\nT",
"output": "0"
},
{
"input": "5 3 0\nATATA\nATA",
"output": "2"
},
{
"input": "5 3 1\nATATA\nATA",
"output": "3"
},
{
"input": "7 1 2\nATGCGTA\nA",
"output": "6"
},
{
"input": "7 1 3\nATGCGTA\nA",
"output": "7"
},
{
"input": "4 4 0\nATGC\nGCTA",
"output": "0"
},
{
"input": "4 4 1\nATGC\nGCTA",
"output": "0"
},
{
"input": "4 4 2\nATGC\nGCTA",
"output": "0"
}
] | 31 | 0 | 0 | 55,233 |
|
767 | Change-free | [
"greedy"
] | null | null | Student Arseny likes to plan his life for *n* days ahead. He visits a canteen every day and he has already decided what he will order in each of the following *n* days. Prices in the canteen do not change and that means Arseny will spend *c**i* rubles during the *i*-th day.
There are 1-ruble coins and 100-ruble notes in circulation. At this moment, Arseny has *m* coins and a sufficiently large amount of notes (you can assume that he has an infinite amount of them). Arseny loves modern technologies, so he uses his credit card everywhere except the canteen, but he has to pay in cash in the canteen because it does not accept cards.
Cashier always asks the student to pay change-free. However, it's not always possible, but Arseny tries to minimize the dissatisfaction of the cashier. Cashier's dissatisfaction for each of the days is determined by the total amount of notes and coins in the change. To be precise, if the cashier gives Arseny *x* notes and coins on the *i*-th day, his dissatisfaction for this day equals *x*Β·*w**i*. Cashier always gives change using as little coins and notes as possible, he always has enough of them to be able to do this.
Arseny wants to pay in such a way that the total dissatisfaction of the cashier for *n* days would be as small as possible. Help him to find out how he needs to pay in each of the *n* days!
Note that Arseny always has enough money to pay, because he has an infinite amount of notes. Arseny can use notes and coins he received in change during any of the following days. | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=105, 0<=β€<=*m*<=β€<=109)Β β the amount of days Arseny planned his actions for and the amount of coins he currently has.
The second line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=105)Β β the amounts of money in rubles which Arseny is going to spend for each of the following days.
The third line contains a sequence of integers *w*1,<=*w*2,<=...,<=*w**n* (1<=β€<=*w**i*<=β€<=105)Β β the cashier's dissatisfaction coefficients for each of the following days. | In the first line print one integerΒ β minimum possible total dissatisfaction of the cashier.
Then print *n* lines, the *i*-th of then should contain two numbersΒ β the amount of notes and the amount of coins which Arseny should use to pay in the canteen on the *i*-th day.
Of course, the total amount of money Arseny gives to the casher in any of the days should be no less than the amount of money he has planned to spend. It also shouldn't exceed 106 rubles: Arseny never carries large sums of money with him.
If there are multiple answers, print any of them. | [
"5 42\n117 71 150 243 200\n1 1 1 1 1\n",
"3 0\n100 50 50\n1 3 2\n",
"5 42\n117 71 150 243 200\n5 4 3 2 1\n"
] | [
"79\n1 17\n1 0\n2 0\n2 43\n2 0\n",
"150\n1 0\n1 0\n0 50\n",
"230\n1 17\n1 0\n1 50\n3 0\n2 0\n"
] | none | [
{
"input": "5 42\n117 71 150 243 200\n1 1 1 1 1",
"output": "79\n1 17\n1 0\n2 0\n2 43\n2 0"
},
{
"input": "3 0\n100 50 50\n1 3 2",
"output": "150\n1 0\n1 0\n0 50"
},
{
"input": "5 42\n117 71 150 243 200\n5 4 3 2 1",
"output": "230\n1 17\n1 0\n1 50\n3 0\n2 0"
},
{
"input": "5 32\n83 13 61 34 31\n7 5 6 8 8",
"output": "353\n1 0\n0 13\n1 0\n0 34\n0 31"
},
{
"input": "14 138\n479 330 487 127 170 55 122 480 331 434 447 246 104 263\n1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "166\n5 0\n3 30\n5 0\n1 27\n2 0\n1 0\n1 22\n5 0\n3 31\n4 34\n4 47\n2 46\n1 4\n3 0"
},
{
"input": "1 0\n49\n2",
"output": "102\n1 0"
},
{
"input": "1 100\n51\n2",
"output": "0\n0 51"
},
{
"input": "1 50\n51\n100000",
"output": "4900000\n1 0"
},
{
"input": "20 148\n469 474 336 120 365 172 159 297 301 477 335 471 320 300 486 279 449 215 384 297\n29 63 60 16 35 31 55 97 66 97 55 19 6 33 26 21 71 4 16 30",
"output": "6265\n5 0\n4 74\n3 36\n2 0\n4 0\n2 0\n1 59\n3 0\n3 1\n4 77\n3 35\n5 0\n3 20\n3 0\n5 0\n3 0\n4 49\n2 15\n4 0\n3 0"
},
{
"input": "20 20\n209 457 118 182 443 455 336 128 225 295 186 64 230 30 259 407 39 378 341 44\n10 6 6 5 9 2 9 5 5 9 88334 75309 89717 85121 58293 77761 79913 57434 93590 54508",
"output": "3709\n3 0\n5 0\n2 0\n2 0\n5 0\n5 0\n4 0\n2 0\n3 0\n3 0\n1 86\n0 64\n2 30\n0 30\n2 59\n4 7\n0 39\n3 78\n3 41\n0 44"
},
{
"input": "20 20\n209 457 118 182 443 455 336 128 225 295 186 64 230 30 259 407 39 378 341 44\n10 96444 6 88786 9 54221 9 69661 5 89056 3 75309 3 85121 5 77761 5 57434 2 54508",
"output": "3746\n3 0\n4 57\n2 0\n1 82\n5 0\n4 55\n4 0\n1 28\n3 0\n2 95\n2 0\n0 64\n3 0\n0 30\n3 0\n4 7\n1 0\n3 78\n4 0\n0 44"
},
{
"input": "20 431\n417 327 307 311 485 355 412 383 368 66 237 201 171 266 317 33 297 204 380 462\n5 4 3 8 7 1 9 6 1 2 6 7 6 3 6 4 10 7 4 1",
"output": "255\n4 17\n3 27\n3 7\n3 11\n4 85\n4 0\n4 12\n3 83\n4 0\n1 0\n2 37\n2 1\n1 71\n2 66\n3 17\n0 33\n3 0\n2 4\n4 0\n4 62"
},
{
"input": "20 16\n5 8 13 6 20 13 18 8 12 16 5 3 2 11 9 3 6 9 9 20\n5 9 6 7 8 10 10 2 5 6 4 2 7 1 6 10 4 10 4 8",
"output": "659\n1 0\n0 8\n0 13\n0 6\n0 20\n0 13\n0 18\n1 0\n0 12\n0 16\n0 5\n0 3\n0 2\n0 11\n0 9\n0 3\n0 6\n0 9\n0 9\n0 20"
},
{
"input": "40 0\n450 450 350 350 450 350 450 450 450 450 150 450 150 450 150 350 150 150 450 350 350 150 450 350 350 350 150 250 450 450 150 250 450 350 150 250 450 250 250 250\n99998 99997 99996 99996 100000 100000 99995 99999 99995 99999 99996 100000 99997 99995 99997 99995 99999 99998 100000 99995 99996 99999 99995 99998 99998 100000 99999 99998 99997 99998 99999 99999 100000 99998 99997 99998 100000 99996 99999 99999",
"output": "99996350\n5 0\n5 0\n4 0\n4 0\n4 50\n3 50\n5 0\n4 50\n5 0\n4 50\n2 0\n4 50\n2 0\n5 0\n2 0\n4 0\n1 50\n1 50\n4 50\n4 0\n4 0\n1 50\n5 0\n3 50\n3 50\n3 50\n1 50\n3 0\n5 0\n5 0\n1 50\n2 50\n4 50\n3 50\n2 0\n3 0\n4 50\n3 0\n2 50\n2 50"
},
{
"input": "50 135\n111 438 6 371 492 211 134 405 258 420 103 438 78 238 127 421 81 57 351 434 380 138 105 335 409 459 229 298 92 106 244 244 19 465 312 69 26 372 498 285 291 199 7 144 367 37 496 227 115 208\n5 57 97 77 38 83 96 85 53 29 79 23 89 91 75 47 62 49 64 55 91 47 32 68 39 61 17 25 52 23 74 68 75 99 5 92 62 90 12 85 97 35 47 47 58 53 15 43 45 79",
"output": "26974\n2 0\n4 38\n0 6\n4 0\n5 0\n2 11\n1 34\n4 5\n3 0\n5 0\n1 3\n5 0\n1 0\n2 38\n1 27\n4 21\n1 0\n1 0\n3 51\n4 34\n4 0\n1 38\n1 5\n3 35\n4 9\n5 0\n3 0\n3 0\n1 0\n2 0\n2 44\n2 44\n0 19\n4 65\n4 0\n0 69\n0 26\n3 72\n5 0\n3 0\n3 0\n2 0\n0 7\n1 44\n4 0\n0 37\n5 0\n2 27\n1 15\n2 8"
}
] | 30 | 0 | 0 | 55,325 |
|
0 | none | [
"none"
] | null | null | There are two decks of cards lying on the table in front of you, some cards in these decks lay face up, some of them lay face down. You want to merge them into one deck in which each card is face down. You're going to do it in two stages.
The first stage is to merge the two decks in such a way that the relative order of the cards from the same deck doesn't change. That is, for any two different cards *i* and *j* in one deck, if card *i* lies above card *j*, then after the merge card *i* must also be above card *j*.
The second stage is performed on the deck that resulted from the first stage. At this stage, the executed operation is the turning operation. In one turn you can take a few of the top cards, turn all of them, and put them back. Thus, each of the taken cards gets turned and the order of these cards is reversed. That is, the card that was on the bottom before the turn, will be on top after it.
Your task is to make sure that all the cards are lying face down. Find such an order of merging cards in the first stage and the sequence of turning operations in the second stage, that make all the cards lie face down, and the number of turns is minimum. | The first input line contains a single integer *n* β the number of cards in the first deck (1<=β€<=*n*<=β€<=105).
The second input line contains *n* integers, separated by single spaces *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=1). Value *a**i* equals 0, if the *i*-th card is lying face down, and 1, if the card is lying face up. The cards are given in the order from the topmost one to the bottommost one.
The third input line contains integer *m* β the number of cards in the second deck (1<=β€<=*m*<=β€<=105).
The fourth input line contains *m* integers, separated by single spaces *b*1,<=*b*2,<=...,<=*b**m* (0<=β€<=*b**i*<=β€<=1). Value *b**i* equals 0, if the *i*-th card is lying face down, and 1, if the card is lying face up. The cards are given in the order from the topmost to the bottommost. | In the first line print *n*<=+<=*m* space-separated integers β the numbers of the cards in the order, in which they will lie after the first stage. List the cards from top to bottom. The cards from the first deck should match their indexes from 1 to *n* in the order from top to bottom. The cards from the second deck should match their indexes, increased by *n*, that is, numbers from *n*<=+<=1 to *n*<=+<=*m* in the order from top to bottom.
In the second line print a single integer *x* β the minimum number of turn operations you need to make all cards in the deck lie face down. In the third line print *x* integers: *c*1,<=*c*2,<=...,<=*c**x* (1<=β€<=*c**i*<=β€<=*n*<=+<=*m*), each of them represents the number of cards to take from the top of the deck to perform a turn operation. Print the operations in the order, in which they should be performed.
If there are multiple optimal solutions, print any of them. It is guaranteed that the minimum number of operations doesn't exceed 6Β·105. | [
"3\n1 0 1\n4\n1 1 1 1\n",
"5\n1 1 1 1 1\n5\n0 1 0 1 0\n"
] | [
"1 4 5 6 7 2 3\n3\n5 6 7\n",
"6 1 2 3 4 5 7 8 9 10\n4\n1 7 8 9\n"
] | none | [] | 92 | 0 | 0 | 55,380 |
|
115 | Linear Kingdom Races | [
"data structures",
"dp"
] | null | null | You are a car race organizer and would like to arrange some races in Linear Kingdom.
Linear Kingdom has *n* consecutive roads spanning from left to right. The roads are numbered from 1 to *n* from left to right, thus the roads follow in the order of their numbers' increasing. There will be several races that may be held on these roads. Each race will use a consecutive subset of these roads. Also, each race will pay some amount of money to you if this race is held. No races overlap in time, so some roads can be used in several races.
Unfortunately, some of the roads are in a bad condition and they need repair. Each road has repair costs associated with it, you are required to pay this cost to repair the road. A race can only take place if all the roads used in the race are renovated. Your task is to repair such roads (possibly all or none) that will maximize your profit. Your profit is defined as the total money you get from the races that are held minus the total money you spent to repair the roads. Note that you may decide not to repair any road and gain zero profit.
Print the maximum profit you can gain. | The first line contains two single-space separated integers, *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=2Β·105), denoting the number of roads and the number of races, respectively.
Then *n* lines follow, each line will contain a single non-negative integer not exceeding 109 denoting the cost to repair a road. The costs are given in order from road 1 to road *n*.
Finally, *m* lines follow. Each line is single-space-separated triplets of integers. Each triplet will be given as *lb*, *ub*, and *p* (1<=β€<=*lb*<=β€<=*ub*<=β€<=*n*,<=1<=β€<=*p*<=β€<=109), which means that the race these three integers describe will use all the roads from *lb* to *ub*, inclusive, and if it's held you get *p*. | Print a single integer denoting the maximum possible profit you can gain.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout stream (also you may use %I64d specificator). | [
"7 4\n3\n2\n3\n2\n1\n2\n3\n1 2 5\n2 3 5\n3 5 3\n7 7 5\n",
"2 1\n0\n3\n1 2 5\n",
"3 1\n10\n10\n10\n1 3 10\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the optimal solution is to repair roads 1, 2, 3, and 7. Three races will take place which nets you 15. The road repair costs 11, hence your profit is 4. | [
{
"input": "7 4\n3\n2\n3\n2\n1\n2\n3\n1 2 5\n2 3 5\n3 5 3\n7 7 5",
"output": "4"
},
{
"input": "2 1\n0\n3\n1 2 5",
"output": "2"
},
{
"input": "3 1\n10\n10\n10\n1 3 10",
"output": "0"
},
{
"input": "3 2\n10\n10\n12\n1 2 25\n2 3 5",
"output": "5"
},
{
"input": "7 5\n1\n2\n3\n0\n5\n6\n7\n1 3 3\n1 2 3\n1 1 3\n4 6 15\n7 7 4",
"output": "7"
},
{
"input": "5 5\n0\n0\n0\n0\n0\n1 1 1000000000\n2 2 1000000000\n3 3 1000000000\n4 4 1000000000\n5 5 1000000000",
"output": "5000000000"
},
{
"input": "3 2\n3\n8\n3\n1 2 10\n2 3 10",
"output": "6"
},
{
"input": "10 8\n33930500\n249890727\n553757132\n571301286\n535990315\n433808986\n428745197\n461561455\n355416641\n127410873\n1 10 419764974\n3 9 229470163\n3 10 291232092\n2 10 483262264\n3 5 561890379\n6 8 333274969\n2 9 762222268\n2 9 731460943",
"output": "60764940"
},
{
"input": "1 1\n1\n1 1 2",
"output": "1"
},
{
"input": "5 3\n1\n0\n0\n2\n0\n3 4 5\n3 4 1\n1 3 3",
"output": "6"
},
{
"input": "10 8\n212749027\n472287218\n528909998\n592722741\n656413986\n521299317\n454014903\n356019417\n201615821\n190915667\n3 7 194993664\n2 10 654414593\n1 5 318407622\n4 9 78092496\n6 10 710430585\n2 8 717871540\n1 5 618048353\n2 6 354310856",
"output": "0"
},
{
"input": "11 8\n2\n0\n0\n0\n11\n2\n9\n7\n9\n4\n3\n1 1 6\n5 5 9\n5 5 6\n3 11 7\n6 11 4\n6 11 3\n2 10 6\n5 9 9",
"output": "8"
},
{
"input": "10 10\n0\n8\n6\n9\n3\n6\n5\n0\n4\n6\n5 9 9\n1 7 10\n2 4 1\n2 10 3\n4 7 9\n1 4 2\n5 10 2\n2 7 7\n6 7 3\n8 9 10",
"output": "10"
},
{
"input": "10 10\n3\n4\n10\n0\n5\n1\n4\n6\n0\n4\n6 6 8\n5 10 5\n1 6 7\n1 7 4\n3 5 8\n6 6 7\n8 10 10\n1 4 10\n2 9 9\n3 7 8",
"output": "39"
},
{
"input": "5 5\n4\n2\n4\n2\n4\n1 5 4\n1 5 3\n3 5 3\n4 5 5\n4 5 2",
"output": "1"
},
{
"input": "3 3\n2\n3\n0\n1 3 3\n1 3 1\n1 2 2",
"output": "1"
},
{
"input": "10 20\n0\n4\n12\n14\n2\n7\n3\n7\n0\n0\n3 4 3\n4 7 1\n6 9 5\n3 6 7\n5 9 10\n3 9 2\n2 10 13\n7 9 12\n9 9 3\n1 4 2\n3 5 8\n7 8 13\n4 10 8\n2 6 6\n4 10 1\n7 7 14\n1 9 14\n7 7 15\n8 9 10\n5 5 11",
"output": "109"
}
] | 31 | 0 | 0 | 55,508 |
|
894 | Ralph and Mushrooms | [
"dp",
"graphs"
] | null | null | Ralph is going to collect mushrooms in the Mushroom Forest.
There are *m* directed paths connecting *n* trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantastic speed. New mushrooms regrow as soon as Ralph finishes mushroom collection on a path. More specifically, after Ralph passes a path the *i*-th time, there regrow *i* mushrooms less than there was before this pass. That is, if there is initially *x* mushrooms on a path, then Ralph will collect *x* mushrooms for the first time, *x*<=-<=1 mushrooms the second time, *x*<=-<=1<=-<=2 mushrooms the third time, and so on. However, the number of mushrooms can never be less than 0.
For example, let there be 9 mushrooms on a path initially. The number of mushrooms that can be collected from the path is 9, 8, 6 and 3 when Ralph passes by from first to fourth time. From the fifth time and later Ralph can't collect any mushrooms from the path (but still can pass it).
Ralph decided to start from the tree *s*. How many mushrooms can he collect using only described paths? | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=106, 0<=β€<=*m*<=β€<=106), representing the number of trees and the number of directed paths in the Mushroom Forest, respectively.
Each of the following *m* lines contains three integers *x*, *y* and *w* (1<=β€<=*x*,<=*y*<=β€<=*n*, 0<=β€<=*w*<=β€<=108), denoting a path that leads from tree *x* to tree *y* with *w* mushrooms initially. There can be paths that lead from a tree to itself, and multiple paths between the same pair of trees.
The last line contains a single integer *s* (1<=β€<=*s*<=β€<=*n*)Β β the starting position of Ralph. | Print an integer denoting the maximum number of the mushrooms Ralph can collect during his route. | [
"2 2\n1 2 4\n2 1 4\n1\n",
"3 3\n1 2 4\n2 3 3\n1 3 8\n1\n"
] | [
"16",
"8"
] | In the first sample Ralph can pass three times on the circle and collect 4β+β4β+β3β+β3β+β1β+β1β=β16 mushrooms. After that there will be no mushrooms for Ralph to collect.
In the second sample, Ralph can go to tree 3 and collect 8 mushrooms on the path from tree 1 to tree 3. | [
{
"input": "2 2\n1 2 4\n2 1 4\n1",
"output": "16"
},
{
"input": "3 3\n1 2 4\n2 3 3\n1 3 8\n1",
"output": "8"
},
{
"input": "1 0\n1",
"output": "0"
}
] | 732 | 26,009,600 | -1 | 55,535 |
|
492 | Vanya and Computer Game | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya and his friend Vova play a computer game where they need to destroy *n* monsters to pass a level. Vanya's character performs attack with frequency *x* hits per second and Vova's character performs attack with frequency *y* hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1<=/<=*x* seconds for the first character and 1<=/<=*y* seconds for the second one). The *i*-th monster dies after he receives *a**i* hits.
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit. | The first line contains three integers *n*,*x*,*y* (1<=β€<=*n*<=β€<=105, 1<=β€<=*x*,<=*y*<=β€<=106) β the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
Next *n* lines contain integers *a**i* (1<=β€<=*a**i*<=β€<=109)Β β the number of hits needed do destroy the *i*-th monster. | Print *n* lines. In the *i*-th line print word "Vanya", if the last hit on the *i*-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time. | [
"4 3 2\n1\n2\n3\n4\n",
"2 1 1\n1\n2\n"
] | [
"Vanya\nVova\nVanya\nBoth\n",
"Both\nBoth\n"
] | In the first sample Vanya makes the first hit at time 1β/β3, Vova makes the second hit at time 1β/β2, Vanya makes the third hit at time 2β/β3, and both boys make the fourth and fifth hit simultaneously at the time 1.
In the second sample Vanya and Vova make the first and second hit simultaneously at time 1. | [
{
"input": "4 3 2\n1\n2\n3\n4",
"output": "Vanya\nVova\nVanya\nBoth"
},
{
"input": "2 1 1\n1\n2",
"output": "Both\nBoth"
},
{
"input": "7 5 20\n26\n27\n28\n29\n30\n31\n32",
"output": "Vova\nVova\nVova\nBoth\nBoth\nVova\nVova"
},
{
"input": "10 10 1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "Vanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nBoth"
},
{
"input": "10 1 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "Vova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nBoth"
},
{
"input": "1 999999 1000000\n1000000000",
"output": "Vanya"
},
{
"input": "5 5 6\n999999999\n999999998\n999999997\n999999996\n999999995",
"output": "Vova\nVanya\nVova\nVanya\nVova"
},
{
"input": "10 13 27\n3\n21\n23\n17\n15\n23\n16\n7\n24\n20",
"output": "Vanya\nVanya\nVova\nVova\nVanya\nVova\nVova\nVova\nVanya\nVova"
},
{
"input": "1 1 1\n1",
"output": "Both"
},
{
"input": "5 999999 1000000\n1999997\n1999998\n1999999\n2000000\n2000001",
"output": "Vova\nBoth\nBoth\nVova\nVanya"
},
{
"input": "5 999998 1000000\n999997\n999998\n999999\n1000000\n1000001",
"output": "Vova\nBoth\nBoth\nVova\nVanya"
},
{
"input": "20 5 15\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39",
"output": "Both\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth"
},
{
"input": "11 22 33\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65",
"output": "Both\nVova\nVanya\nVova\nBoth\nBoth\nVova\nVanya\nVova\nBoth\nBoth"
}
] | 31 | 0 | 0 | 55,628 |
|
0 | none | [
"none"
] | null | null | It's well-known that blog posts are an important part of Codeforces platform. Every blog post has a global characteristic changing over timeΒ β its community rating. A newly created blog post's community rating is 0. Codeforces users may visit the blog post page and rate it, changing its community rating by +1 or -1.
Consider the following model of Codeforces users' behavior. The *i*-th user has his own estimated blog post rating denoted by an integer *a**i*. When a user visits a blog post page, he compares his estimated blog post rating to its community rating. If his estimated rating is higher, he rates the blog post with +1 (thus, the blog post's community rating increases by 1). If his estimated rating is lower, he rates the blog post with -1 (decreasing its community rating by 1). If the estimated rating and the community rating are equal, user doesn't rate the blog post at all (in this case we'll say that user rates the blog post for 0). In any case, after this procedure user closes the blog post page and never opens it again.
Consider a newly created blog post with the initial community rating of 0. For each of *n* Codeforces users, numbered from 1 to *n*, his estimated blog post rating *a**i* is known.
For each *k* from 1 to *n*, inclusive, the following question is asked. Let users with indices from 1 to *k*, in some order, visit the blog post page, rate the blog post and close the page. Each user opens the blog post only after the previous user closes it. What could be the maximum possible community rating of the blog post after these *k* visits? | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=5Β·105)Β β the number of Codeforces users.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=5Β·105<=β€<=*a**i*<=β€<=5Β·105)Β β estimated blog post ratings for users in order from 1 to *n*. | For each *k* from 1 to *n*, output a single integer equal to the maximum possible community rating of the blog post after users with indices from 1 to *k*, in some order, visit the blog post page, rate the blog post, and close the page. | [
"4\n2 0 2 2\n",
"7\n2 -3 -2 5 0 -3 1\n"
] | [
"1\n1\n2\n2\n",
"1\n0\n-1\n0\n1\n1\n2\n"
] | none | [] | 30 | 0 | 0 | 55,735 |
|
489 | SwapSort | [
"greedy",
"implementation",
"sortings"
] | null | null | In this problem your goal is to sort an array consisting of *n* integers in at most *n* swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number of swaps β your task is to find any sequence that is no longer than *n*. | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=3000) β the number of array elements. The second line contains elements of array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=109<=β€<=*a**i*<=β€<=109), where *a**i* is the *i*-th element of the array. The elements are numerated from 0 to *n*<=-<=1 from left to right. Some integers may appear in the array more than once. | In the first line print *k* (0<=β€<=*k*<=β€<=*n*) β the number of swaps. Next *k* lines must contain the descriptions of the *k* swaps, one per line. Each swap should be printed as a pair of integers *i*, *j* (0<=β€<=*i*,<=*j*<=β€<=*n*<=-<=1), representing the swap of elements *a**i* and *a**j*. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print *i*<==<=*j* and swap the same pair of elements multiple times.
If there are multiple answers, print any of them. It is guaranteed that at least one answer exists. | [
"5\n5 2 5 1 4\n",
"6\n10 20 20 40 60 60\n",
"2\n101 100\n"
] | [
"2\n0 3\n4 2\n",
"0\n",
"1\n0 1\n"
] | none | [
{
"input": "5\n5 2 5 1 4",
"output": "2\n0 3\n4 2"
},
{
"input": "6\n10 20 20 40 60 60",
"output": "0"
},
{
"input": "2\n101 100",
"output": "1\n0 1"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n1000000000 -1000000000",
"output": "1\n0 1"
},
{
"input": "8\n5 2 6 8 3 1 6 8",
"output": "4\n0 5\n4 2\n5 3\n6 5"
},
{
"input": "2\n200000000 199999999",
"output": "1\n0 1"
},
{
"input": "3\n100000000 100000002 100000001",
"output": "1\n1 2"
},
{
"input": "5\n1000000000 -10000000 0 8888888 7777777",
"output": "3\n0 1\n2 1\n4 2"
},
{
"input": "5\n10 30 20 50 40",
"output": "2\n1 2\n4 3"
}
] | 857 | 204,800 | 3 | 55,816 |
|
478 | Red-Green Towers | [
"dp"
] | null | null | There are *r* red and *g* green blocks for construction of the red-green tower. Red-green tower can be built following next rules:
- Red-green tower is consisting of some number of levels; - Let the red-green tower consist of *n* levels, then the first level of this tower should consist of *n* blocks, second level β of *n*<=-<=1 blocks, the third one β of *n*<=-<=2 blocks, and so on β the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one; - Each level of the red-green tower should contain blocks of the same color.
Let *h* be the maximum possible number of levels of red-green tower, that can be built out of *r* red and *g* green blocks meeting the rules above. The task is to determine how many different red-green towers having *h* levels can be built out of the available blocks.
Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.
You are to write a program that will find the number of different red-green towers of height *h* moduloΒ 109<=+<=7. | The only line of input contains two integers *r* and *g*, separated by a single space β the number of available red and green blocks respectively (0<=β€<=*r*,<=*g*<=β€<=2Β·105, *r*<=+<=*g*<=β₯<=1). | Output the only integer β the number of different possible red-green towers of height *h* moduloΒ 109<=+<=7. | [
"4 6\n",
"9 7\n",
"1 1\n"
] | [
"2\n",
"6\n",
"2\n"
] | The image in the problem statement shows all possible red-green towers for the first sample. | [
{
"input": "4 6",
"output": "2"
},
{
"input": "9 7",
"output": "6"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "2 19",
"output": "1"
},
{
"input": "18 3",
"output": "2"
},
{
"input": "100000 1",
"output": "2"
},
{
"input": "1 100000",
"output": "2"
},
{
"input": "6 6",
"output": "6"
},
{
"input": "10 10",
"output": "18"
},
{
"input": "200000 200000",
"output": "206874596"
},
{
"input": "0 1",
"output": "1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "0 200000",
"output": "1"
},
{
"input": "200000 0",
"output": "1"
},
{
"input": "199396 0",
"output": "1"
},
{
"input": "199395 0",
"output": "1"
},
{
"input": "0 199397",
"output": "1"
},
{
"input": "121147 78249",
"output": "64290784"
},
{
"input": "78250 121147",
"output": "981737243"
},
{
"input": "121146 78249",
"output": "832902708"
},
{
"input": "199585 199586",
"output": "438320405"
},
{
"input": "199586 199586",
"output": "876640810"
},
{
"input": "199585 199585",
"output": "199771918"
},
{
"input": "107344 159729",
"output": "849320920"
},
{
"input": "2954 1977",
"output": "835530858"
},
{
"input": "25580 17318",
"output": "263898876"
},
{
"input": "89671 32487",
"output": "654128709"
},
{
"input": "38 36",
"output": "612"
},
{
"input": "136749 183300",
"output": "906576609"
},
{
"input": "10000 10000",
"output": "885988055"
},
{
"input": "200000 199999",
"output": "396481680"
}
] | 46 | 0 | 0 | 55,833 |
|
0 | none | [
"none"
] | null | null | There are *n* animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number *i* in the queue will have to visit his office exactly *a**i* times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving *k* animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out. | The first line of input data contains two space-separated integers *n* and *k* (1<=β€<=*n*<=β€<=105, 0<=β€<=*k*<=β€<=1014). In the second line are given space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | If the doctor will overall carry out less than *k* examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers β number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted. | [
"3 3\n1 2 1\n",
"4 10\n3 3 2 1\n",
"7 10\n1 3 3 1 2 3 1\n"
] | [
"2 ",
"-1\n",
"6 2 3 "
] | In the first sample test:
- Before examination: {1,β2,β3} - After the first examination: {2,β3} - After the second examination: {3,β2} - After the third examination: {2}
In the second sample test:
- Before examination: {1,β2,β3,β4,β5,β6,β7} - After the first examination: {2,β3,β4,β5,β6,β7} - After the second examination: {3,β4,β5,β6,β7,β2} - After the third examination: {4,β5,β6,β7,β2,β3} - After the fourth examination: {5,β6,β7,β2,β3} - After the fifth examination: {6,β7,β2,β3,β5} - After the sixth examination: {7,β2,β3,β5,β6} - After the seventh examination: {2,β3,β5,β6} - After the eighth examination: {3,β5,β6,β2} - After the ninth examination: {5,β6,β2,β3} - After the tenth examination: {6,β2,β3} | [
{
"input": "3 3\n1 2 1",
"output": "2 "
},
{
"input": "4 10\n3 3 2 1",
"output": "-1"
},
{
"input": "7 10\n1 3 3 1 2 3 1",
"output": "6 2 3 "
},
{
"input": "1 0\n1",
"output": "1 "
},
{
"input": "6 101\n9 78 54 62 2 91",
"output": "4 6 2 3 "
},
{
"input": "9 100\n11 11 11 11 11 11 11 11 11",
"output": "-1"
},
{
"input": "10 77\n7 45 10 10 9 8 1 2 3 1",
"output": "2 "
},
{
"input": "5 12\n1 3 4 1 5",
"output": "5 "
},
{
"input": "5 23\n7 1 4 7 9",
"output": "1 4 5 "
},
{
"input": "5 41\n19 19 19 15 20",
"output": "2 3 4 5 1 "
},
{
"input": "10 7\n5 1 2 5 4 3 5 2 2 4",
"output": "8 9 10 1 3 4 5 6 7 "
},
{
"input": "10 109\n5 5 4 4 8 10 9 10 9 8",
"output": "-1"
},
{
"input": "20 430\n25 27 25 24 24 49 11 30 24 50 48 40 41 5 19 45 16 43 43 12",
"output": "12 13 16 18 19 2 6 8 10 11 "
},
{
"input": "20 314\n7 14 13 11 11 11 14 14 9 9 12 11 13 13 10 13 11 12 10 10",
"output": "-1"
},
{
"input": "20 252\n2 8 13 3 12 15 1 7 11 14 5 7 2 12 5 12 10 5 6 1",
"output": "-1"
},
{
"input": "20 329\n21 48 18 162 100 7 83 104 32 145 24 122 5 25 16 99 53 116 164 79",
"output": "16 17 18 19 20 1 2 4 5 7 8 9 10 11 12 14 "
},
{
"input": "50 892\n50 50 43 50 44 50 44 44 49 50 50 47 50 50 48 50 40 45 50 42 46 50 49 48 47 49 44 45 44 46 48 45 48 43 45 48 48 47 47 49 47 37 45 31 44 45 39 50 48 50",
"output": "43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 "
},
{
"input": "50 68\n12 6 15 15 7 4 1 18 11 2 3 4 9 6 8 2 6 10 1 2 16 10 22 28 23 2 17 33 3 3 5 1 5 6 5 5 2 6 2 10 2 14 1 24 12 12 4 4 2 10",
"output": "21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 1 2 3 4 5 6 8 9 11 12 13 14 15 17 18 "
},
{
"input": "50 224\n5 4 5 5 5 5 5 3 5 5 5 5 4 5 5 4 5 5 5 5 5 5 5 5 4 5 5 4 5 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4",
"output": "33 34 35 36 37 38 39 40 41 42 43 44 45 46 "
},
{
"input": "50 479\n15 64 28 16 6 4 28 3 20 55 4 43 48 21 23 75 2 42 14 6 51 27 50 7 26 13 5 12 7 36 19 3 11 1 9 1 6 23 12 7 19 24 25 19 11 11 42 15 14 40",
"output": "39 41 42 43 44 47 48 49 50 1 2 3 4 7 9 10 12 13 14 15 16 18 19 21 22 23 25 26 30 31 38 "
},
{
"input": "150 2476\n70 21 114 127 22 11 29 59 51 59 35 3 53 88 5 8 44 4 8 100 1 27 1 25 27 56 48 22 23 103 85 66 14 58 20 7 176 11 19 26 105 97 83 3 29 30 52 92 59 11 135 37 59 8 66 20 47 19 143 16 93 18 57 71 1 13 141 1 119 6 2 87 40 68 28 22 20 53 31 19 15 33 32 9 70 63 16 26 77 7 45 52 73 25 22 21 68 79 16 3 164 22 3 42 15 6 1 18 59 3 55 110 33 2 93 11 31 23 92 24 35 116 38 101 53 3 70 4 76 46 2 45 1 3 14 35 57 21 113 8 45 36 32 45 60 13 68 27 40 17",
"output": "26 27 28 29 30 31 32 34 37 40 41 42 43 45 46 47 48 49 51 52 53 55 57 59 61 63 64 67 69 72 73 74 75 76 78 79 82 83 85 86 88 89 91 92 93 94 95 96 97 98 101 102 104 109 111 112 113 115 117 118 119 120 121 122 123 124 125 127 129 130 132 136 137 138 139 141 142 143 144 145 147 148 149 1 3 4 5 7 8 9 10 11 13 14 17 20 22 24 25 "
}
] | 60 | 0 | 0 | 55,898 |
|
474 | Captain Marmot | [
"brute force",
"geometry"
] | null | null | Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has *n* regiments, each consisting of 4 moles.
Initially, each mole *i* (1<=β€<=*i*<=β€<=4*n*) is placed at some position (*x**i*,<=*y**i*) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.
Each mole *i* has a home placed at the position (*a**i*,<=*b**i*). Moving this mole one time means rotating his position point (*x**i*,<=*y**i*) 90 degrees counter-clockwise around it's home point (*a**i*,<=*b**i*).
A regiment is compact only if the position points of the 4 moles form a square with non-zero area.
Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible. | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100), the number of regiments.
The next 4*n* lines contain 4 integers *x**i*, *y**i*, *a**i*, *b**i* (<=-<=104<=β€<=*x**i*,<=*y**i*,<=*a**i*,<=*b**i*<=β€<=104). | Print *n* lines to the standard output. If the regiment *i* can be made compact, the *i*-th line should contain one integer, the minimal number of required moves. Otherwise, on the *i*-th line print "-1" (without quotes). | [
"4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0\n"
] | [
"1\n-1\n3\n3\n"
] | In the first regiment we can move once the second or the third mole.
We can't make the second regiment compact.
In the third regiment, from the last 3 moles we can move once one and twice another one.
In the fourth regiment, we can move twice the first mole and once the third mole. | [
{
"input": "4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0",
"output": "1\n-1\n3\n3"
},
{
"input": "3\n-2248 6528 -2144 6181\n-2245 6663 -2100 7054\n-4378 7068 -4061 7516\n-4274 6026 -3918 5721\n4942 -6793 5014 -6807\n3463 -5170 3112 -5181\n2870 -6992 3038 -6567\n5688 -4318 5358 -4744\n5249 7233 5016 6863\n4312 7385 4162 7383\n5965 9138 5607 8728\n4053 8349 4124 8389",
"output": "8\n6\n6"
},
{
"input": "5\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0\n0 1 0 0\n1 0 0 0\n-1 0 0 0\n0 -1 0 0",
"output": "1\n-1\n3\n3\n0"
},
{
"input": "1\n0 3 0 3\n3 2 3 2\n-1 0 -1 0\n2 -1 2 -1",
"output": "0"
},
{
"input": "3\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0\n1 2 0 0\n-1 2 0 0\n-1 -2 0 0\n1 -2 0 0",
"output": "-1\n0\n-1"
},
{
"input": "1\n1 0 2 0\n-1 0 -2 0\n0 2 0 3\n0 -2 0 -3",
"output": "4"
},
{
"input": "1\n1 0 0 0\n3 1 0 0\n2 3 0 0\n0 2 0 0",
"output": "0"
},
{
"input": "1\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0",
"output": "-1"
},
{
"input": "1\n1 0 2 0\n-1 0 -2 0\n0 1 0 2\n0 -1 0 -2",
"output": "0"
},
{
"input": "2\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0",
"output": "-1\n0"
},
{
"input": "3\n-1 3 0 0\n3 1 0 0\n1 -3 0 0\n-3 -1 0 0\n1 1 0 0\n1 1 0 0\n1 1 0 0\n1 1 0 0\n-4 12 0 0\n-4 12 0 0\n-4 12 0 0\n-4 12 0 0",
"output": "0\n6\n6"
},
{
"input": "4\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0\n1 2 0 0\n-1 2 0 0\n-1 -2 0 0\n1 -2 0 0\n19 0 0 0\n0 20 0 0\n-19 0 0 0\n0 -20 0 0",
"output": "-1\n0\n-1\n-1"
},
{
"input": "1\n0 0 0 0\n1 0 1 0\n1 1 1 1\n-1 0 -1 0",
"output": "-1"
},
{
"input": "1\n0 0 0 0\n1 1 1 1\n2 0 2 0\n1 -1 1 -1",
"output": "0"
},
{
"input": "1\n1 1 1 1\n1 1 1 1\n2 2 2 2\n2 2 2 2",
"output": "-1"
},
{
"input": "1\n0 0 0 0\n0 1 0 1\n2 0 2 0\n2 1 2 1",
"output": "-1"
},
{
"input": "1\n-1 1 -9999 9999\n3 3 10000 10000\n3 -3 10000 -10000\n-1 -1 -9999 -9999",
"output": "8"
},
{
"input": "1\n2 0 5 5\n0 1 5 5\n0 -1 5 5\n-2 0 5 5",
"output": "-1"
},
{
"input": "1\n-1 1 -9999 9999\n-1 -1 9998 9998\n-1 1 9998 -9998\n-1 -1 -9999 -9999",
"output": "8"
},
{
"input": "1\n0 0 -1 -1\n-3 4 0 0\n2 4 0 0\n5 0 0 0",
"output": "-1"
},
{
"input": "1\n0 -1 0 -1\n2 0 2 0\n0 1 0 1\n-2 0 -2 0",
"output": "-1"
},
{
"input": "1\n2 1 0 0\n-2 1 0 0\n2 -1 0 0\n-2 -1 0 0",
"output": "-1"
},
{
"input": "1\n0 1 0 1\n0 -1 0 -1\n1 0 1 0\n-1 0 -1 0",
"output": "0"
}
] | 187 | 4,198,400 | 3 | 56,162 |
|
212 | Privatization | [
"flows",
"graphs"
] | null | null | There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions.
Changes are coming to Berland β the state decided to privatize BerAvia, namely, to sell out all flights to *t* private companies. Each of these companies wants to get the maximal number of flights, so if the Berland flights are sold unevenly, Berland can be accused of partiality. Berland Government decided to sell the flights as evenly as possible between the *t* companies.
The unevenness of the distribution of flights between companies is calculated as follows. For each city *i* (both Berland and Beerland) we'll calculate the value of
Help the Berland government come up with the most even distribution plan of selling flights. | The first input line contains four integers *n*,<=*m*,<=*k* and *t* (1<=β€<=*n*,<=*m*,<=*t*<=β€<=200;1<=β€<=*k*<=β€<=5000), where *n*,<=*m* are the numbers of cities in Berland and Beerland, correspondingly, *k* is the number of flights between them, and *t* is the number of private companies. Next *k* lines describe the flights, one per line, as pairs of positive integers *x**i*,<=*y**i* (1<=β€<=*x**i*<=β€<=*n*;1<=β€<=*y**i*<=β€<=*m*), where *x**i* and *y**i* are the indexes of cities in Berland and Beerland, correspondingly, connected by the *i*-th flight. There is at most one flight between any pair of cities, each flight connects cities of different countries. The cities in Berland are indexed from 1 to *n*, and in Beerland β from 1 to *m*. | Print the unevenness of the sought plan on the first line. On the second line print a sequence of *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=β€<=*c**i*<=β€<=*t*), where *c**i* is the index of the company that should buy the *i*-th flight. Assume that the flights are indexed from 1 to *k* in the order they appear in the input. If there are multiple solutions, print any of them. | [
"3 5 8 2\n1 4\n1 3\n3 3\n1 2\n1 1\n2 1\n1 5\n2 2\n"
] | [
"4\n2 1 2 1 2 1 2 2 "
] | none | [] | 92 | 0 | 0 | 56,170 |
|
605 | Freelancer's Dreams | [
"geometry"
] | null | null | Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least *p* experience points, and a desired flat in Moscow costs *q* dollars. Mikhail is determined to follow his dreams and registered at a freelance site.
He has suggestions to work on *n* distinct projects. Mikhail has already evaluated that the participation in the *i*-th project will increase his experience by *a**i* per day and bring *b**i* dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time.
Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true.
For example, suppose Mikhail is suggested to work on three projects and *a*1<==<=6, *b*1<==<=2, *a*2<==<=1, *b*2<==<=3, *a*3<==<=2, *b*3<==<=6. Also, *p*<==<=20 and *q*<==<=20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed, *a*1Β·2.5<=+<=*a*2Β·0<=+<=*a*3Β·2.5<==<=6Β·2.5<=+<=1Β·0<=+<=2Β·2.5<==<=20 and *b*1Β·2.5<=+<=*b*2Β·0<=+<=*b*3Β·2.5<==<=2Β·2.5<=+<=3Β·0<=+<=6Β·2.5<==<=20. | The first line of the input contains three integers *n*, *p* and *q* (1<=β€<=*n*<=β€<=100<=000,<=1<=β€<=*p*,<=*q*<=β€<=1<=000<=000)Β β the number of projects and the required number of experience and money.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=1<=000<=000)Β β the daily increase in experience and daily income for working on the *i*-th project. | Print a real valueΒ β the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"3 20 20\n6 2\n1 3\n2 6\n",
"4 1 1\n2 3\n3 2\n2 3\n3 2\n"
] | [
"5.000000000000000\n",
"0.400000000000000\n"
] | First sample corresponds to the example in the problem statement. | [
{
"input": "3 20 20\n6 2\n1 3\n2 6",
"output": "5.000000000000000"
},
{
"input": "4 1 1\n2 3\n3 2\n2 3\n3 2",
"output": "0.400000000000000"
},
{
"input": "3 12 12\n5 1\n2 2\n1 5",
"output": "4.000000000000000"
},
{
"input": "3 12 12\n5 1\n4 4\n1 5",
"output": "3.000000000000000"
},
{
"input": "3 1 1\n1 1\n1 1\n1 1",
"output": "1.000000000000000"
},
{
"input": "1 4 6\n2 3",
"output": "2.000000000000000"
},
{
"input": "1 3 4\n2 3",
"output": "1.500000000000000"
},
{
"input": "2 1 1000000\n2 4\n5 2",
"output": "250000.000000000000000"
},
{
"input": "2 1000000 1\n2 4\n5 2",
"output": "200000.000000000000000"
},
{
"input": "2 1000000 1000000\n2 4\n5 2",
"output": "312500.000000000000000"
},
{
"input": "6 2 2\n2 4\n5 2\n5 2\n2 4\n2 4\n5 2",
"output": "0.625000000000000"
},
{
"input": "1 3 5\n2 3",
"output": "1.666666666666667"
},
{
"input": "2 10 3\n2 4\n5 2",
"output": "2.000000000000000"
},
{
"input": "2 10 4\n2 4\n5 2",
"output": "2.000000000000000"
},
{
"input": "2 10 5\n2 4\n5 2",
"output": "2.187500000000000"
},
{
"input": "2 5 8\n2 4\n5 2",
"output": "2.125000000000000"
},
{
"input": "2 4 8\n2 4\n5 2",
"output": "2.000000000000000"
},
{
"input": "2 3 8\n2 4\n5 2",
"output": "2.000000000000000"
},
{
"input": "2 4 1\n2 4\n5 2",
"output": "0.800000000000000"
},
{
"input": "2 4 2\n2 4\n5 2",
"output": "0.875000000000000"
},
{
"input": "2 4 3\n2 4\n5 2",
"output": "1.062500000000000"
},
{
"input": "2 5 3\n2 4\n5 2",
"output": "1.187500000000000"
},
{
"input": "2 5 4\n2 4\n5 2",
"output": "1.375000000000000"
},
{
"input": "2 4 4\n2 4\n5 2",
"output": "1.250000000000000"
},
{
"input": "2 3 4\n2 4\n5 2",
"output": "1.125000000000000"
},
{
"input": "2 3 3\n2 4\n5 2",
"output": "0.937500000000000"
},
{
"input": "2 2 3\n2 4\n5 2",
"output": "0.812500000000000"
},
{
"input": "2 1 3\n2 4\n5 2",
"output": "0.750000000000000"
},
{
"input": "2 2 4\n2 4\n5 2",
"output": "1.000000000000000"
},
{
"input": "2 5 2\n2 4\n5 2",
"output": "1.000000000000000"
},
{
"input": "2 5 4\n2 2\n4 3",
"output": "1.333333333333333"
},
{
"input": "6 1000000 999999\n999999 1\n999995 999994\n999996 999996\n999997 999995\n999998 999997\n1 999998",
"output": "1.000002000006000"
},
{
"input": "7 123456 123459\n10 2\n3 4\n11 3\n8 1\n5 2\n7 1\n1 8",
"output": "21786.705882352940534"
},
{
"input": "10 123457 123459\n5 2\n11 4\n1 8\n11 1\n7 1\n10 2\n8 1\n11 3\n3 4\n11 8",
"output": "15432.375000000000000"
},
{
"input": "10 630 764\n679 16\n34 691\n778 366\n982 30\n177 9\n739 279\n992 89\n488 135\n7 237\n318 318",
"output": "1.472265278375486"
},
{
"input": "10 468662 93838\n589910 727627\n279516 867207\n470524 533177\n467834 784167\n295605 512137\n104422 629804\n925609 728473\n922365 500342\n998983 958315\n425628 935048",
"output": "0.469139114479426"
},
{
"input": "10 18 25\n4 8\n16 27\n16 13\n1 26\n8 13\n2 14\n24 8\n4 29\n3 19\n19 20",
"output": "1.041450777202072"
},
{
"input": "10 17 38\n6 35\n16 37\n6 12\n16 29\n27 15\n23 28\n4 27\n30 12\n5 4\n40 17",
"output": "1.036423841059603"
},
{
"input": "10 36 35\n32 37\n17 30\n20 24\n11 21\n24 9\n25 6\n37 23\n14 8\n32 20\n17 39",
"output": "1.072669826224329"
}
] | 0 | 0 | -1 | 56,264 |
|
818 | Four Melodies | [
"flows",
"graphs"
] | null | null | Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, and recently she had recorded two tracks that became very popular. Now she has got a lot of fans who are waiting for new tracks.
This time Alice wants to form four melodies for her tracks.
Alice has a sheet with *n* notes written on it. She wants to take four such non-empty non-intersecting subsequences that all of them form a melody and sum of their lengths is maximal.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Subsequence forms a melody when each two adjacent notes either differ by 1 or are congruent modulo 7.
You should write a program which will calculate maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody. | The first line contains one integer number *n* (4<=β€<=*n*<=β€<=3000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105) β notes written on a sheet. | Print maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody. | [
"5\n1 3 5 7 9\n",
"5\n1 3 5 7 2\n"
] | [
"4\n",
"5\n"
] | In the first example it is possible to compose 4 melodies by choosing any 4 notes (and each melody will consist of only one note).
In the second example it is possible to compose one melody with 2 notes β {1,β2}. Remaining notes are used in other three melodies (one note per each melody). | [
{
"input": "5\n1 3 5 7 9",
"output": "4"
},
{
"input": "5\n1 3 5 7 2",
"output": "5"
},
{
"input": "4\n1 3 5 7",
"output": "4"
},
{
"input": "4\n1 1 1 1",
"output": "4"
},
{
"input": "4\n1 1 2 1",
"output": "4"
},
{
"input": "4\n3 2 3 1",
"output": "4"
},
{
"input": "4\n3 4 2 2",
"output": "4"
},
{
"input": "4\n5 3 4 3",
"output": "4"
},
{
"input": "4\n5 3 1 4",
"output": "4"
},
{
"input": "4\n3 5 2 4",
"output": "4"
},
{
"input": "4\n8 6 8 1",
"output": "4"
},
{
"input": "4\n6 3 6 4",
"output": "4"
},
{
"input": "5\n8 1 4 8 2",
"output": "5"
},
{
"input": "6\n2 7 8 6 5 7",
"output": "6"
},
{
"input": "7\n9 12 12 1 8 12 12",
"output": "7"
},
{
"input": "8\n16 1 8 13 14 5 4 4",
"output": "8"
},
{
"input": "9\n5 4 10 10 13 17 15 15 12",
"output": "9"
},
{
"input": "10\n19 18 20 1 7 1 3 14 1 11",
"output": "9"
},
{
"input": "11\n6 13 20 20 3 12 8 21 3 19 18",
"output": "11"
},
{
"input": "12\n21 20 4 4 4 15 13 12 17 15 11 13",
"output": "12"
},
{
"input": "13\n4 17 14 24 5 17 22 25 20 3 19 12 25",
"output": "11"
},
{
"input": "14\n8 14 20 7 26 22 7 26 2 16 19 20 5 6",
"output": "12"
},
{
"input": "15\n3 16 14 2 24 6 11 7 9 23 13 10 7 27 27",
"output": "14"
},
{
"input": "16\n19 9 4 4 9 21 10 18 27 9 5 3 6 12 21 18",
"output": "13"
},
{
"input": "17\n16 26 6 8 6 25 4 31 25 23 30 21 5 34 19 8 13",
"output": "14"
},
{
"input": "18\n17 31 24 19 7 36 23 16 28 1 22 3 20 3 12 5 10 25",
"output": "14"
},
{
"input": "19\n8 18 34 1 25 23 22 29 12 36 10 23 21 22 8 35 1 31 29",
"output": "16"
},
{
"input": "20\n26 5 4 29 39 3 5 16 36 18 36 11 16 8 36 4 15 37 25 13",
"output": "18"
}
] | 31 | 409,600 | -1 | 56,328 |
|
101 | Vectors | [
"implementation",
"math"
] | C. Vectors | 1 | 256 | At a geometry lesson Gerald was given a task: to get vector *B* out of vector *A*. Besides, the teacher permitted him to perform the following operations with vector *Π*:
- Turn the vector by 90 degrees clockwise.- Add to the vector a certain vector *C*.
Operations could be performed in any order any number of times.
Can Gerald cope with the task? | The first line contains integers *x*1 ΠΈ *y*1 β the coordinates of the vector *A* (<=-<=108<=β€<=*x*1,<=*y*1<=β€<=108). The second and the third line contain in the similar manner vectors *B* and *C* (their coordinates are integers; their absolute value does not exceed 108). | Print "YES" (without the quotes) if it is possible to get vector *B* using the given operations. Otherwise print "NO" (without the quotes). | [
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n2 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | [
{
"input": "0 0\n1 1\n0 1",
"output": "YES"
},
{
"input": "0 0\n1 1\n1 1",
"output": "YES"
},
{
"input": "0 0\n1 1\n2 2",
"output": "NO"
},
{
"input": "2 3\n2 3\n0 0",
"output": "YES"
},
{
"input": "-4 -2\n0 0\n-2 -1",
"output": "YES"
},
{
"input": "-100000000 -100000000\n100000000 100000000\n0 1",
"output": "YES"
},
{
"input": "3 4\n-4 3\n1 7",
"output": "YES"
},
{
"input": "1 1\n2 2\n-3 -3",
"output": "YES"
},
{
"input": "0 1\n2 3\n7 -11",
"output": "NO"
},
{
"input": "-2 2\n3 3\n5 0",
"output": "YES"
},
{
"input": "1 3\n3 1\n3 3",
"output": "YES"
},
{
"input": "0 0\n0 0\n0 0",
"output": "YES"
},
{
"input": "0 0\n12 12\n0 0",
"output": "NO"
},
{
"input": "0 100000000\n0 -100000000\n1 0",
"output": "YES"
},
{
"input": "100000000 4444\n-4444 -100000000\n50000000 50000000",
"output": "YES"
},
{
"input": "45 6\n65 5\n0 5",
"output": "NO"
},
{
"input": "1 0\n0 1\n2 1",
"output": "YES"
},
{
"input": "7 11\n13 13\n0 4",
"output": "YES"
},
{
"input": "4 2\n0 -1\n2 -2",
"output": "NO"
},
{
"input": "4 -3\n-3 1\n0 -2",
"output": "NO"
},
{
"input": "-2 -1\n0 1\n-2 -3",
"output": "NO"
},
{
"input": "-1 1\n2 1\n-2 -1",
"output": "NO"
},
{
"input": "4 0\n4 -3\n2 4",
"output": "NO"
},
{
"input": "-3 -2\n-3 3\n4 4",
"output": "NO"
},
{
"input": "2 1\n1 -4\n-4 -2",
"output": "NO"
},
{
"input": "3 1\n1 -1\n-1 -4",
"output": "NO"
},
{
"input": "2 -1\n-2 -4\n1 -1",
"output": "NO"
},
{
"input": "0 4\n-1 -3\n4 1",
"output": "NO"
},
{
"input": "-4 1\n-4 2\n0 -2",
"output": "NO"
},
{
"input": "-2 -2\n-2 3\n3 -1",
"output": "NO"
},
{
"input": "-3 0\n2 1\n-2 0",
"output": "YES"
},
{
"input": "-1 -2\n3 -2\n-3 -1",
"output": "NO"
},
{
"input": "3 1\n-2 3\n-2 -2",
"output": "NO"
},
{
"input": "0 -4\n-1 -2\n0 1",
"output": "YES"
},
{
"input": "-4 -4\n1 0\n-1 -3",
"output": "NO"
},
{
"input": "2 0\n-2 1\n2 3",
"output": "NO"
},
{
"input": "-2 4\n0 1\n-2 1",
"output": "YES"
},
{
"input": "4 1\n2 -1\n3 0",
"output": "YES"
},
{
"input": "2 3\n3 -3\n3 -2",
"output": "NO"
},
{
"input": "2 4\n-4 1\n3 3",
"output": "NO"
},
{
"input": "-4 -3\n-3 -4\n1 4",
"output": "NO"
},
{
"input": "3 2\n1 0\n-4 -1",
"output": "NO"
},
{
"input": "0 -4\n-3 -2\n3 -1",
"output": "NO"
},
{
"input": "-2 2\n4 -2\n-2 -2",
"output": "NO"
},
{
"input": "2 2\n-2 1\n0 -3",
"output": "YES"
},
{
"input": "0 4\n1 1\n-4 2",
"output": "NO"
},
{
"input": "-4 -4\n4 1\n-4 -2",
"output": "NO"
},
{
"input": "-4 2\n4 -1\n-2 -1",
"output": "YES"
},
{
"input": "-7 9\n-2 10\n-6 -4",
"output": "NO"
},
{
"input": "4 7\n2 9\n-7 -6",
"output": "NO"
},
{
"input": "-6 9\n6 6\n9 6",
"output": "NO"
},
{
"input": "-9 4\n8 1\n-8 8",
"output": "NO"
},
{
"input": "-4 3\n9 -2\n-3 -3",
"output": "YES"
},
{
"input": "-1 -7\n3 -2\n-4 -3",
"output": "NO"
},
{
"input": "-9 4\n-2 -8\n9 4",
"output": "NO"
},
{
"input": "8 2\n-10 1\n10 -2",
"output": "NO"
},
{
"input": "-7 9\n5 5\n-2 6",
"output": "NO"
},
{
"input": "-8 1\n-10 -8\n1 -4",
"output": "YES"
},
{
"input": "-65 -52\n31 -22\n0 -77",
"output": "NO"
},
{
"input": "74 -55\n0 50\n-68 26",
"output": "NO"
},
{
"input": "-84 28\n33 -15\n-19 93",
"output": "NO"
},
{
"input": "69 -30\n-66 -100\n86 -38",
"output": "NO"
},
{
"input": "-43 41\n-99 92\n-20 51",
"output": "NO"
},
{
"input": "-17 -33\n56 -75\n-93 65",
"output": "NO"
},
{
"input": "-95 -32\n-90 -43\n-40 16",
"output": "NO"
},
{
"input": "-48 -92\n59 -39\n-45 14",
"output": "NO"
},
{
"input": "95 -13\n22 -36\n-25 -60",
"output": "NO"
},
{
"input": "81 -91\n88 91\n-90 -77",
"output": "NO"
},
{
"input": "281 -914\n-217 113\n479 329",
"output": "NO"
},
{
"input": "620 514\n-276 966\n578 106",
"output": "NO"
},
{
"input": "-253 -283\n-400 834\n718 -701",
"output": "NO"
},
{
"input": "478 884\n418 -713\n-704 -961",
"output": "NO"
},
{
"input": "-380 -712\n-263 -104\n187 -329",
"output": "NO"
},
{
"input": "-2919 -7389\n-4955 -1807\n2103 9400",
"output": "NO"
},
{
"input": "6040 9662\n1903 7813\n5296 8638",
"output": "NO"
},
{
"input": "-6008 -6748\n-7106 -5319\n-1940 8048",
"output": "NO"
},
{
"input": "-2171 -9855\n4255 -3857\n6446 9559",
"output": "NO"
},
{
"input": "-8916 9282\n2666 2344\n9109 -2730",
"output": "NO"
},
{
"input": "-52856 -58459\n-41878 81991\n-22821 59850",
"output": "NO"
},
{
"input": "10327 -86117\n-51156 -26888\n-41007 27453",
"output": "NO"
},
{
"input": "-46921 46529\n87797 -73235\n18213 -86569",
"output": "NO"
},
{
"input": "-66381 86177\n24332 -47590\n-57592 80499",
"output": "NO"
},
{
"input": "-69415 74546\n37868 -89407\n19505 -59846",
"output": "NO"
},
{
"input": "-817674 316187\n-934134 660884\n-297136 -482732",
"output": "NO"
},
{
"input": "-127066 941778\n-654926 -838416\n809821 -229819",
"output": "NO"
},
{
"input": "251893 526074\n593818 288991\n-120613 211128",
"output": "NO"
},
{
"input": "910801 387995\n-846325 167413\n-425681 -149086",
"output": "NO"
},
{
"input": "769260 131679\n-399548 -620680\n-439456 -164378",
"output": "NO"
},
{
"input": "4931249 7448503\n8740191 1123509\n4410817 -3494433",
"output": "NO"
},
{
"input": "6752575 4525855\n-2269760 5249721\n7718280 -5550799",
"output": "NO"
},
{
"input": "9121753 -1624238\n1358642 -7305098\n9182854 -2204498",
"output": "NO"
},
{
"input": "-8540887 -7511495\n-2659834 -6893955\n8115011 -3482324",
"output": "NO"
},
{
"input": "-4664203 -2707147\n7039468 5543778\n5854600 -7808563",
"output": "NO"
},
{
"input": "-33622572 -65473509\n-54144104 -59861983\n89814248 47623606",
"output": "NO"
},
{
"input": "-75629161 -68114618\n23285096 90997125\n84795646 72358903",
"output": "NO"
},
{
"input": "-79956125 -88524398\n10949698 32312326\n-76024701 -77225990",
"output": "NO"
},
{
"input": "26164297 21666711\n-20848219 -49928045\n-36819763 26811563",
"output": "NO"
},
{
"input": "98219518 -66590186\n14970849 -24409139\n82951915 43915349",
"output": "NO"
},
{
"input": "67195377 58333196\n-60739152 -69557068\n-82003989 74825425",
"output": "NO"
},
{
"input": "92141071 -48275413\n-47968469 -13277723\n-15839680 51548907",
"output": "NO"
},
{
"input": "82237071 -62729681\n45778244 -73153917\n25235041 83636828",
"output": "NO"
},
{
"input": "82539131 17433579\n-56091046 68716401\n-73706000 41779060",
"output": "NO"
},
{
"input": "-21570525 17439241\n-47857043 39456884\n-36121539 69473879",
"output": "NO"
},
{
"input": "-38 -99\n76 43\n53 -84",
"output": "NO"
},
{
"input": "-52 0\n-60 -50\n-47 91",
"output": "NO"
},
{
"input": "-53 30\n-14 -19\n-61 11",
"output": "NO"
},
{
"input": "60 55\n-88 -38\n0 59",
"output": "NO"
},
{
"input": "89 55\n-13 27\n-13 -81",
"output": "NO"
},
{
"input": "76 73\n82 -92\n-95 95",
"output": "NO"
},
{
"input": "-81 57\n-96 0\n-73 -58",
"output": "NO"
},
{
"input": "0 45\n42 -47\n-51 -82",
"output": "NO"
},
{
"input": "16 39\n95 18\n39 -64",
"output": "NO"
},
{
"input": "-23 36\n-72 0\n44 -60",
"output": "NO"
},
{
"input": "57 43\n58 -54\n-43 0",
"output": "NO"
},
{
"input": "51 77\n-9 81\n0 79",
"output": "NO"
},
{
"input": "0 14\n88 0\n88 0",
"output": "NO"
},
{
"input": "0 0\n48 0\n-62 68",
"output": "NO"
},
{
"input": "-35 -90\n0 -42\n-8 -60",
"output": "NO"
},
{
"input": "59 0\n84 -28\n0 58",
"output": "NO"
},
{
"input": "10 -15\n23 0\n88 -36",
"output": "NO"
},
{
"input": "-66 -34\n59 -38\n13 0",
"output": "NO"
},
{
"input": "0 -14\n80 94\n-14 15",
"output": "NO"
},
{
"input": "-28 0\n0 43\n0 -51",
"output": "NO"
},
{
"input": "0 0\n-30010581 33889813\n12862004 15575384",
"output": "NO"
},
{
"input": "94993760 -37786635\n-75326491 -21534927\n77949983 95218547",
"output": "NO"
},
{
"input": "72913933 0\n54300106 60510850\n32295823 -60694017",
"output": "NO"
},
{
"input": "0 -77922994\n47873382 0\n-48532375 -33729248",
"output": "NO"
},
{
"input": "-50600641 25410541\n0 80575245\n0 62979800",
"output": "NO"
},
{
"input": "-34280877 -82070958\n66030914 -52671703\n0 -90987154",
"output": "NO"
},
{
"input": "27523869 0\n52900492 0\n33031150 -65488267",
"output": "NO"
},
{
"input": "69226391 60708120\n43106396 25795293\n80380957 88577789",
"output": "NO"
},
{
"input": "0 40072438\n-61016486 88561432\n28431496 60485628",
"output": "NO"
},
{
"input": "0 24078959\n75842668 -56466325\n-64025705 12045125",
"output": "NO"
},
{
"input": "24334185 -27189752\n0 -47230185\n0 -37588021",
"output": "NO"
},
{
"input": "45479363 56862079\n28029163 0\n-38736303 59867108",
"output": "NO"
},
{
"input": "-66738889 -24309585\n-39387414 -42921545\n-10462276 0",
"output": "NO"
},
{
"input": "-95534030 -14392539\n-89751090 79655267\n-77491839 40745315",
"output": "NO"
},
{
"input": "-48666683 22046293\n77649947 84819904\n-32803712 -99366118",
"output": "NO"
},
{
"input": "10150745 93724033\n-59625481 -18232739\n34384941 -28147896",
"output": "NO"
},
{
"input": "-12344578 -26470996\n0 -25186906\n-11572514 -38120367",
"output": "NO"
},
{
"input": "-59220368 0\n0 -75968891\n0 74081590",
"output": "NO"
},
{
"input": "-78038627 -49761049\n0 22143739\n0 -60448485",
"output": "NO"
},
{
"input": "80358706 0\n23898082 -87631921\n-48798084 88174414",
"output": "NO"
},
{
"input": "10 13\n13 10\n0 0",
"output": "NO"
},
{
"input": "0 0\n10 13\n10 13",
"output": "YES"
},
{
"input": "10 13\n0 0\n0 0",
"output": "NO"
},
{
"input": "10 13\n-10 -13\n0 0",
"output": "YES"
},
{
"input": "10 13\n-13 10\n0 0",
"output": "YES"
},
{
"input": "100000000 1\n99999999 1\n0 0",
"output": "NO"
},
{
"input": "100000000 1\n99999999 1\n1 0",
"output": "YES"
},
{
"input": "100000000 1\n99999999 1\n0 1",
"output": "YES"
},
{
"input": "100000000 1\n99999999 1\n100000000 1",
"output": "NO"
},
{
"input": "0 0\n1 0\n100000000 0",
"output": "NO"
},
{
"input": "0 0\n1 1\n100000000 100000000",
"output": "NO"
},
{
"input": "0 0\n100000000 99999999\n100000000 100000000",
"output": "NO"
},
{
"input": "0 0\n99999999 1\n100000000 1",
"output": "NO"
},
{
"input": "100000000 0\n99999999 1\n0 0",
"output": "NO"
},
{
"input": "100000000 0\n99999999 1\n1 0",
"output": "YES"
},
{
"input": "100000000 0\n99999999 1\n100000000 1",
"output": "YES"
},
{
"input": "100000000 0\n1 0\n100000000 0",
"output": "NO"
},
{
"input": "100000000 0\n1 1\n100000000 100000000",
"output": "NO"
},
{
"input": "100000000 0\n100000000 99999999\n100000000 100000000",
"output": "NO"
},
{
"input": "100000000 0\n99999999 1\n100000000 1",
"output": "YES"
},
{
"input": "100000000 100000000\n100000000 100000000\n0 1",
"output": "YES"
},
{
"input": "5491 -1888\n58611137 -17279700\n5629 -7705",
"output": "YES"
},
{
"input": "6791 1587\n23543337 24784850\n3970 2327",
"output": "YES"
},
{
"input": "1214 8046\n84729946 38445218\n3488 -5838",
"output": "YES"
},
{
"input": "-8725 -6466\n77278594 -3622341\n9344 -1256",
"output": "YES"
},
{
"input": "-5922 -2466\n-46708374 -71085154\n-9882 298",
"output": "YES"
},
{
"input": "4560 -6056\n97943322 -20616116\n-1107 -5440",
"output": "YES"
},
{
"input": "-5645 2118\n-23770935 62615171\n-2080 9473",
"output": "YES"
},
{
"input": "2630 8069\n-75372166 10085837\n-781 5563",
"output": "YES"
},
{
"input": "-2588 9699\n50743921 -45114432\n-5288 -7358",
"output": "YES"
},
{
"input": "6889 9158\n-843345 89332306\n7495 518",
"output": "YES"
},
{
"input": "-2037 -1006\n-13301683 -83185771\n-3487 -4590",
"output": "YES"
},
{
"input": "-925 -1240\n25904140 -92743662\n-8028 -2933",
"output": "YES"
},
{
"input": "-573 5611\n-88934372 16274202\n-689 9294",
"output": "YES"
},
{
"input": "-2859 7599\n37114911 -75750711\n-9150 -7398",
"output": "YES"
},
{
"input": "-9234 9520\n58867682 17319702\n2273 -5831",
"output": "YES"
},
{
"input": "3411 2674\n-21536783 -33506984\n-8254 -3778",
"output": "YES"
},
{
"input": "1778735 -1803902\n-92875004 -2966747\n-4125460 1149178",
"output": "YES"
},
{
"input": "-2413874 4166580\n83681508 25911924\n8615149 -6396049",
"output": "YES"
},
{
"input": "5987456 -1627274\n-45083510 25782192\n-758074 971006",
"output": "YES"
},
{
"input": "-881780 8157586\n-83355045 -86221641\n-5080144 1016625",
"output": "YES"
},
{
"input": "836292 -1555463\n44451624 -63102407\n-7051275 -9619647",
"output": "YES"
},
{
"input": "-5493123 4007625\n-49191721 -31674255\n-9754636 6418706",
"output": "YES"
},
{
"input": "-2797960 2819364\n59202462 71529306\n7799041 -4640234",
"output": "YES"
},
{
"input": "-7355750 -5710643\n-48075697 25746997\n-3569463 3650928",
"output": "YES"
},
{
"input": "2517677 8638224\n-75757217 -17117074\n-2847910 1342478",
"output": "YES"
},
{
"input": "-1782346 -522853\n56023653 37655619\n7455445 -936314",
"output": "YES"
},
{
"input": "3922510 4979687\n-83613487 73792320\n-2355010 7196240",
"output": "YES"
},
{
"input": "-2911250 -3788914\n9975544 20015444\n7278331 4185016",
"output": "YES"
},
{
"input": "9495309 -4445256\n66581093 -48831427\n5864682 -8016505",
"output": "YES"
},
{
"input": "-6389242 -2092524\n-18806778 85154882\n8457769 5141401",
"output": "YES"
},
{
"input": "-6223066 -5334825\n36109780 -5416931\n3246899 -4890875",
"output": "YES"
},
{
"input": "-1334950 3309875\n-20438919 -45390492\n-722222 280804",
"output": "YES"
},
{
"input": "122542 -4826228\n-20855162 89301242\n8917870 2568139",
"output": "YES"
},
{
"input": "-4662151 6642823\n-620983 29911124\n6914655 -1204368",
"output": "YES"
},
{
"input": "806224 -7075643\n94593948 -33094579\n-540130 -5612242",
"output": "YES"
},
{
"input": "2370720 9260730\n-31929898 43611588\n2817748 6788032",
"output": "YES"
},
{
"input": "5 -12\n-47316040 -62956553\n-7 0",
"output": "YES"
},
{
"input": "-7 0\n-51538008 -92285620\n-3 0",
"output": "YES"
},
{
"input": "-12 9\n21015609 49124671\n3 2",
"output": "YES"
},
{
"input": "-11 -10\n-1042937 89231497\n0 9",
"output": "YES"
},
{
"input": "-3 11\n6154942 80496611\n5 0",
"output": "YES"
},
{
"input": "-13 12\n826557 -90209918\n0 -5",
"output": "YES"
},
{
"input": "-3 -9\n-72817057 -54284335\n-3 -1",
"output": "YES"
},
{
"input": "-8 -8\n66949614 -53875176\n-2 -4",
"output": "YES"
},
{
"input": "6 2\n-97096230 19770854\n-5 4",
"output": "YES"
},
{
"input": "10 7\n91660376 -58581376\n0 -7",
"output": "YES"
},
{
"input": "0 0\n100000000 99999997\n1 0",
"output": "YES"
},
{
"input": "0 0\n100000000 99999997\n0 1",
"output": "YES"
},
{
"input": "-100000000 -100000000\n100000000 100000000\n1 0",
"output": "YES"
},
{
"input": "0 0\n100000000 100000000\n1 0",
"output": "YES"
},
{
"input": "32 34\n-50070000 21003000\n0 1",
"output": "YES"
},
{
"input": "0 0\n100000000 99999999\n1 0",
"output": "YES"
},
{
"input": "0 0\n1 1\n0 0",
"output": "NO"
},
{
"input": "0 0\n100000000 0\n1 2",
"output": "YES"
},
{
"input": "0 0\n100000000 99999999\n1 0",
"output": "YES"
},
{
"input": "1 1\n1 2\n0 0",
"output": "NO"
},
{
"input": "0 0\n4 2\n1 1",
"output": "YES"
},
{
"input": "100000000 100000000\n0 0\n1 1",
"output": "YES"
},
{
"input": "0 0\n10000000 10000000\n1 1",
"output": "YES"
},
{
"input": "1 2\n-2 1\n0 0",
"output": "YES"
},
{
"input": "1 1\n1 -1\n0 0",
"output": "YES"
},
{
"input": "0 0\n-63411382 -42720436\n123456 543253",
"output": "YES"
}
] | 62 | 0 | 0 | 56,442 |
360 | Levko and Strings | [
"combinatorics",
"dp"
] | null | null | Levko loves strings of length *n*, consisting of lowercase English letters, very much. He has one such string *s*. For each string *t* of length *n*, Levko defines its beauty relative to *s* as the number of pairs of indexes *i*, *j* (1<=β€<=*i*<=β€<=*j*<=β€<=*n*), such that substring *t*[*i*..*j*] is lexicographically larger than substring *s*[*i*..*j*].
The boy wondered how many strings *t* are there, such that their beauty relative to *s* equals exactly *k*. Help him, find the remainder after division this number by 1000000007 (109<=+<=7).
A substring *s*[*i*..*j*] of string *s*<==<=*s*1*s*2... *s**n* is string *s**i**s**i*<=<=+<=<=1... *s**j*.
String *x*<=<==<=<=*x*1*x*2... *x**p* is lexicographically larger than string *y*<=<==<=<=*y*1*y*2... *y**p*, if there is such number *r* (*r*<=<<=*p*), that *x*1<=<==<=<=*y*1,<=<=*x*2<=<==<=<=*y*2,<=<=... ,<=<=*x**r*<=<==<=<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. The string characters are compared by their ASCII codes. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=2000, 0<=β€<=*k*<=β€<=2000).
The second line contains a non-empty string *s* of length *n*. String *s* consists only of lowercase English letters. | Print a single number β the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\nyz\n",
"2 3\nyx\n",
"4 7\nabcd\n"
] | [
"26\n",
"2\n",
"21962\n"
] | none | [] | 31 | 0 | 0 | 56,521 |
|
895 | Eyes Closed | [
"data structures",
"probabilities"
] | null | null | Vasya and Petya were tired of studying so they decided to play a game. Before the game begins Vasya looks at array *a* consisting of *n* integers. As soon as he remembers all elements of *a* the game begins. Vasya closes his eyes and Petya does *q* actions of one of two types:
1) Petya says 4 integers *l*1,<=*r*1,<=*l*2,<=*r*2Β β boundaries of two non-intersecting segments. After that he swaps one random element from the [*l*1,<=*r*1] segment with another random element from the [*l*2,<=*r*2] segment.
2) Petya asks Vasya the sum of the elements of *a* in the [*l*,<=*r*] segment.
Vasya is a mathematician so he answers Petya the mathematical expectation of the sum of the elements in the segment.
Your task is to write a program which will answer the second type questions as Vasya would do it. In other words your program should print the mathematical expectation of the sum of the elements of *a* in the [*l*,<=*r*] segment for every second type query. | The first line contains two integers *n*,<=*q* (2<=β€<=*n*<=β€<=105,<=1<=β€<=*q*<=β€<=105) Β β the number of elements in the array and the number of queries you need to handle.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109) Β β elements of the array.
The next *q* lines contain Petya's actions of type 1 or 2.
If it is a type 1 action then the line contains 5 integers 1,<=*l*1,<=*r*1,<=*l*2,<=*r*2 (1<=β€<=*l*1<=β€<=*r*1<=β€<=*n*,<=1<=β€<=*l*2<=β€<=*r*2<=β€<=*n*).
If it is a type 2 query then the line contains 3 integers 2,<=*l*,<=*r* (1<=β€<=*l*<=β€<=*r*<=β€<=*n*).
It is guaranteed that there is at least one type 2 query and segments [*l*1,<=*r*1],<=[*l*2,<=*r*2] don't have common elements. | For each type 2 query print one real numberΒ β the mathematical expectation of the sum of elements in the segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=4 Β β formally, the answer is correct if where *x* is jury's answer and *y* is yours. | [
"4 4\n1 1 2 2\n1 2 2 3 3\n2 1 2\n1 1 2 3 4\n2 1 2\n",
"10 5\n1 1 1 1 1 2 2 2 2 2\n1 1 5 6 10\n2 1 5\n1 1 5 6 10\n1 1 5 6 10\n2 6 10\n",
"10 10\n1 2 3 4 5 6 7 8 9 10\n1 1 5 6 10\n1 1 5 6 10\n2 1 5\n1 1 3 6 9\n2 1 3\n1 5 7 8 10\n1 1 1 10 10\n2 1 5\n2 7 10\n2 1 10\n"
] | [
"3.0000000\n3.0000000\n",
"6.0000000\n8.0400000\n",
"23.0000000\n14.0000000\n28.0133333\n21.5733333\n55.0000000\n"
] | none | [] | 2,500 | 49,561,600 | 0 | 56,548 |
|
519 | A and B and Interesting Substrings | [
"data structures",
"dp",
"two pointers"
] | null | null | A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string *s*. Now they are trying to find out how many substrings *t* of a string *s* are interesting to B (that is, *t* starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings *t* that are interesting to them. Can you do it? | The first line contains 26 integers *x**a*,<=*x**b*,<=...,<=*x**z* (<=-<=105<=β€<=*x**i*<=β€<=105) β the value assigned to letters *a*,<=*b*,<=*c*,<=...,<=*z* respectively.
The second line contains string *s* of length between 1 and 105 characters, consisting of Lating lowercase lettersβ the string for which you need to calculate the answer. | Print the answer to the problem. | [
"1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n",
"1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n"
] | [
"2\n",
"2\n"
] | In the first sample test strings satisfying the condition above are *abca* and *bcab*.
In the second sample test strings satisfying the condition above are two occurences of *aa*. | [
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab",
"output": "2"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa",
"output": "2"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd",
"output": "4"
},
{
"input": "-3 4 -4 -1 3 5 -5 -3 3 2 1 4 5 -3 -1 4 2 -2 1 -1 1 5 -4 0 -5 4\nolspxykjqr",
"output": "0"
},
{
"input": "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx",
"output": "7"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nbb",
"output": "1"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na",
"output": "0"
},
{
"input": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\nhhhhhhhhhh",
"output": "45"
}
] | 62 | 0 | 0 | 56,797 |
|
455 | Serega and Fun | [
"data structures"
] | null | null | Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up with such a problem.
You are given an array *a* consisting of *n* positive integers and queries to it. The queries can be of two types:
1. Make a unit cyclic shift to the right on the segment from *l* to *r* (both borders inclusive). That is rearrange elements of the array in the following manner:*a*[*l*],<=*a*[*l*<=+<=1],<=...,<=*a*[*r*<=-<=1],<=*a*[*r*]<=β<=*a*[*r*],<=*a*[*l*],<=*a*[*l*<=+<=1],<=...,<=*a*[*r*<=-<=1].1. Count how many numbers equal to *k* are on the segment from *l* to *r* (both borders inclusive).
Fedor hurried to see Serega enjoy the problem and Serega solved it really quickly. Let's see, can you solve it? | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of elements of the array. The second line contains *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=β€<=*a*[*i*]<=β€<=*n*).
The third line contains a single integer *q* (1<=β€<=*q*<=β€<=105) β the number of queries. The next *q* lines contain the queries.
As you need to respond to the queries online, the queries will be encoded. A query of the first type will be given in format: 1 *l*'*i* *r*'*i*. A query of the second type will be given in format: 2 *l*'*i* *r*'*i* *k*'*i*. All the number in input are integer. They satisfy the constraints: 1<=β€<=*l*'*i*,<=*r*'*i*,<=*k*'*i*<=β€<=*n*.
To decode the queries from the data given in input, you need to perform the following transformations:
Where *lastans* is the last reply to the query of the 2-nd type (initially, *lastans*<==<=0). If after transformation *l**i* is greater than *r**i*, you must swap these values. | For each query of the 2-nd type print the answer on a single line. | [
"7\n6 6 2 7 4 2 5\n7\n1 3 6\n2 2 4 2\n2 2 4 7\n2 2 2 5\n1 2 6\n1 1 4\n2 1 7 3\n",
"8\n8 4 2 2 7 7 8 8\n8\n1 8 8\n2 8 1 7\n1 8 1\n1 7 3\n2 8 8 3\n1 1 4\n1 2 7\n1 4 5\n"
] | [
"2\n1\n0\n0\n",
"2\n0\n"
] | none | [
{
"input": "7\n6 6 2 7 4 2 5\n7\n1 3 6\n2 2 4 2\n2 2 4 7\n2 2 2 5\n1 2 6\n1 1 4\n2 1 7 3",
"output": "2\n1\n0\n0"
},
{
"input": "8\n8 4 2 2 7 7 8 8\n8\n1 8 8\n2 8 1 7\n1 8 1\n1 7 3\n2 8 8 3\n1 1 4\n1 2 7\n1 4 5",
"output": "2\n0"
},
{
"input": "10\n7 2 3 4 3 2 4 4 9 1\n10\n1 4 5\n1 1 6\n1 3 10\n1 5 7\n2 5 8 5\n2 6 7 7\n2 1 8 5\n2 7 9 8\n1 1 2\n2 5 9 9",
"output": "0\n0\n0\n0\n0"
}
] | 77 | 5,836,800 | -1 | 56,898 |
|
448 | Divisors | [
"brute force",
"dfs and similar",
"implementation",
"number theory"
] | null | null | Bizon the Champion isn't just friendly, he also is a rigorous coder.
Let's define function *f*(*a*), where *a* is a sequence of integers. Function *f*(*a*) returns the following sequence: first all divisors of *a*1 go in the increasing order, then all divisors of *a*2 go in the increasing order, and so on till the last element of sequence *a*. For example, *f*([2,<=9,<=1])<==<=[1,<=2,<=1,<=3,<=9,<=1].
Let's determine the sequence *X**i*, for integer *i* (*i*<=β₯<=0): *X*0<==<=[*X*] ([*X*] is a sequence consisting of a single number *X*), *X**i*<==<=*f*(*X**i*<=-<=1) (*i*<=><=0). For example, at *X*<==<=6 we get *X*0<==<=[6], *X*1<==<=[1,<=2,<=3,<=6], *X*2<==<=[1,<=1,<=2,<=1,<=3,<=1,<=2,<=3,<=6].
Given the numbers *X* and *k*, find the sequence *X**k*. As the answer can be rather large, find only the first 105 elements of this sequence. | A single line contains two space-separated integers β *X* (1<=β€<=*X*<=β€<=1012) and *k* (0<=β€<=*k*<=β€<=1018). | Print the elements of the sequence *X**k* in a single line, separated by a space. If the number of elements exceeds 105, then print only the first 105 elements. | [
"6 1\n",
"4 2\n",
"10 3\n"
] | [
"1 2 3 6 \n",
"1 1 2 1 2 4 \n",
"1 1 1 2 1 1 5 1 1 2 1 5 1 2 5 10 \n"
] | none | [
{
"input": "6 1",
"output": "1 2 3 6 "
},
{
"input": "4 2",
"output": "1 1 2 1 2 4 "
},
{
"input": "10 3",
"output": "1 1 1 2 1 1 5 1 1 2 1 5 1 2 5 10 "
},
{
"input": "10 0",
"output": "10 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 1000000000000000000",
"output": "1 "
},
{
"input": "16 10",
"output": "1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 2..."
},
{
"input": "963761198400 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 32 33 34 35 36 38 39 40 42 44 45 46 48 50 51 52 54 55 56 57 60 63 64 65 66 68 69 70 72 75 76 77 78 80 81 84 85 88 90 91 92 95 96 99 100 102 104 105 108 110 112 114 115 117 119 120 126 130 132 133 135 136 138 140 143 144 150 152 153 154 156 160 161 162 165 168 170 171 175 176 180 182 184 187 189 190 192 195 198 200 204 207 208 209 210 216 220 221 224 225 228 230 231 234 238 240 247 252 253 255 260 264 266 270 272 273 275 276 280 2..."
},
{
"input": "963761198400 65535",
"output": "1 1 1 1 1 1 1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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "911780559690 2",
"output": "1 1 2 1 3 1 5 1 2 3 6 1 7 1 2 5 10 1 11 1 13 1 2 7 14 1 3 5 15 1 17 1 19 1 3 7 21 1 2 11 22 1 23 1 2 13 26 1 2 3 5 6 10 15 30 1 3 11 33 1 2 17 34 1 5 7 35 1 2 19 38 1 3 13 39 1 2 3 6 7 14 21 42 1 2 23 46 1 3 17 51 1 5 11 55 1 3 19 57 1 61 1 5 13 65 1 2 3 6 11 22 33 66 1 67 1 3 23 69 1 2 5 7 10 14 35 70 1 7 11 77 1 2 3 6 13 26 39 78 1 5 17 85 1 7 13 91 1 5 19 95 1 2 3 6 17 34 51 102 1 3 5 7 15 21 35 105 1 2 5 10 11 22 55 110 1 2 3 6 19 38 57 114 1 5 23 115 1 7 17 119 1 2 61 122 1 2 5 10 13 26 65 130 1 7 19 ..."
},
{
"input": "911780559690 5",
"output": "1 1 1 1 1 2 1 1 1 1 3 1 1 1 1 5 1 1 1 1 2 1 1 1 3 1 1 1 2 1 1 3 1 1 2 1 3 1 2 3 6 1 1 1 1 7 1 1 1 1 2 1 1 1 5 1 1 1 2 1 1 5 1 1 2 1 5 1 2 5 10 1 1 1 1 11 1 1 1 1 13 1 1 1 1 2 1 1 1 7 1 1 1 2 1 1 7 1 1 2 1 7 1 2 7 14 1 1 1 1 3 1 1 1 5 1 1 1 3 1 1 5 1 1 3 1 5 1 3 5 15 1 1 1 1 17 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "956722026041 10",
"output": "1 1 1 1 1 1 1 1 1 1 353 1 1 1 1 1 1 1 1 1 2710260697 1 1 1 1 1 1 1 1 1 353 1 1 1 1 1 1 1 1 2710260697 1 1 1 1 1 1 1 1 353 1 1 1 1 1 1 1 2710260697 1 1 1 1 1 1 1 353 1 1 1 1 1 1 2710260697 1 1 1 1 1 1 353 1 1 1 1 1 2710260697 1 1 1 1 1 353 1 1 1 1 2710260697 1 1 1 1 353 1 1 1 2710260697 1 1 1 353 1 1 2710260697 1 1 353 1 2710260697 1 353 2710260697 956722026041 "
},
{
"input": "956722026041 225",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "956722026041 8459",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "999962000357 5",
"output": "1 1 1 1 1 999979 1 1 1 1 999983 1 1 1 1 999979 1 1 1 999983 1 1 1 999979 1 1 999983 1 1 999979 1 999983 1 999979 999983 999962000357 "
},
{
"input": "999944000663 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "999966000289 5",
"output": "1 1 1 1 1 999983 1 1 1 1 999983 1 1 1 999983 1 1 999983 1 999983 999966000289 "
},
{
"input": "999958000441 18",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 1 999979 1 1 1 1 1 1 999979 1 1 1 1 1 999979 1 1 1 1 999979 1 1 1 999979 1 1 999979 1 999979 999958000441 "
},
{
"input": "999922001521 145",
"output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 3 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 1 1 1 3 1 1 1 1 1 2 1 1 1 1 3 1 1 1 1 2 1 1 1 3 1 1 1 2 1 1 3 1 1 2 1 3 1..."
},
{
"input": "79 1",
"output": "1 79 "
},
{
"input": "83 3",
"output": "1 1 1 83 "
},
{
"input": "85 7",
"output": "1 1 1 1 1 1 1 5 1 1 1 1 1 1 17 1 1 1 1 1 1 5 1 1 1 1 1 17 1 1 1 1 1 5 1 1 1 1 17 1 1 1 1 5 1 1 1 17 1 1 1 5 1 1 17 1 1 5 1 17 1 5 17 85 "
},
{
"input": "89 4",
"output": "1 1 1 1 89 "
},
{
"input": "89 5",
"output": "1 1 1 1 1 89 "
},
{
"input": "89 10",
"output": "1 1 1 1 1 1 1 1 1 1 89 "
},
{
"input": "95 5",
"output": "1 1 1 1 1 5 1 1 1 1 19 1 1 1 1 5 1 1 1 19 1 1 1 5 1 1 19 1 1 5 1 19 1 5 19 95 "
},
{
"input": "95 9",
"output": "1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 19 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 19 1 1 1 1 1 1 1 5 1 1 1 1 1 1 19 1 1 1 1 1 1 5 1 1 1 1 1 19 1 1 1 1 1 5 1 1 1 1 19 1 1 1 1 5 1 1 1 19 1 1 1 5 1 1 19 1 1 5 1 19 1 5 19 95 "
},
{
"input": "99 6",
"output": "1 1 1 1 1 1 3 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 3 1 3 9 1 1 1 1 1 11 1 1 1 1 1 3 1 1 1 1 11 1 1 1 1 3 1 1 1 11 1 1 1 3 1 1 11 1 1 3 1 11 1 3 11 33 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 3 1 3 9 1 1 1 1 11 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "47110247360 1",
"output": "1 2 4 5 8 10 11 16 20 22 32 40 44 55 64 80 88 110 160 176 220 320 352 440 704 880 1760 3520 13383593 26767186 53534372 66917965 107068744 133835930 147219523 214137488 267671860 294439046 428274976 535343720 588878092 736097615 856549952 1070687440 1177756184 1472195230 2141374880 2355512368 2944390460 4282749760 4711024736 5888780920 9422049472 11777561840 23555123680 47110247360 "
},
{
"input": "115718588597 7",
"output": "1 1 1 1 1 1 1 3499 1 1 1 1 1 1 33071903 1 1 1 1 1 1 3499 1 1 1 1 1 33071903 1 1 1 1 1 3499 1 1 1 1 33071903 1 1 1 1 3499 1 1 1 33071903 1 1 1 3499 1 1 33071903 1 1 3499 1 33071903 1 3499 33071903 115718588597 "
},
{
"input": "186474413482 9",
"output": "1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 2 1 1 1 1 1 1 7 1 1 1 1 1 1 2 1 1 1 1 1 7 1 1 1 1 1 2 1 1 1 1 7 1 1 1 1 2 1 1 1 7 1 1 1 2 1 1 7 1 1 2 1 7 1 2 7 14 1 1 1 1 1 1 1 1 17 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 17 1 1 1 1 1 1 1 2 1 1 1 1 1 1 17 1 1 1 1 1 1 2 1 1 1 1 1 17 1 1 1 1 1 2 1 1 1 1 17 1 1 1 1 2 1 1 1 17 1 1 1 2 1 1 17 1 1 2 1 17 1 2 17 34 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 17 1 1 1 1 1 1 1 7 1 1 1 1 1 1 17 1 1 1 1 1 1 7 1 1 1 1 1 17 1 1 1 1 1 7 1 1 1 1 17 1 1 ..."
},
{
"input": "252935271071 2",
"output": "1 1 7 1 29 1 73 1 7 29 203 1 7 73 511 1 29 73 2117 1 7 29 73 203 511 2117 14819 1 17068309 1 7 17068309 119478163 1 29 17068309 494980961 1 73 17068309 1245986557 1 7 29 203 17068309 119478163 494980961 3464866727 1 7 73 511 17068309 119478163 1245986557 8721905899 1 29 73 2117 17068309 494980961 1245986557 36133610153 1 7 29 73 203 511 2117 14819 17068309 119478163 494980961 1245986557 3464866727 8721905899 36133610153 252935271071 "
},
{
"input": "321543612308 10",
"output": "1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 1 1 1 4129 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 4129 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 4129 1 1 1 1 1 1 1 2 1 1 1 1 1 1 4129 1 1 1 1 1 1 2 1 1 1 1 1 4129 1 1 1 1 1 2 1 1 1 1 4129 1 1 1 1 2 1 1 1 4129 1 1 1 2 1 1 4129 1 1 2 1 4129 1 2 4129 8258 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 1 1 1 1 1 ..."
},
{
"input": "392299437193 3",
"output": "1 1 1 392299437193 "
},
{
"input": "458760294782 5",
"output": "1 1 1 1 1 2 1 1 1 1 37 1 1 1 1 2 1 1 1 37 1 1 1 2 1 1 37 1 1 2 1 37 1 2 37 74 1 1 1 1 6199463443 1 1 1 1 2 1 1 1 6199463443 1 1 1 2 1 1 6199463443 1 1 2 1 6199463443 1 2 6199463443 12398926886 1 1 1 1 37 1 1 1 6199463443 1 1 1 37 1 1 6199463443 1 1 37 1 6199463443 1 37 6199463443 229380147391 1 1 1 1 2 1 1 1 37 1 1 1 2 1 1 37 1 1 2 1 37 1 2 37 74 1 1 1 6199463443 1 1 1 2 1 1 6199463443 1 1 2 1 6199463443 1 2 6199463443 12398926886 1 1 1 37 1 1 6199463443 1 1 37 1 6199463443 1 37 6199463443 229380147391 1 1..."
},
{
"input": "529516119667 3",
"output": "1 1 1 5231 1 1 101226557 1 1 5231 1 101226557 1 5231 101226557 529516119667 "
},
{
"input": "598124460904 4",
"output": "1 1 1 1 2 1 1 1 2 1 1 2 1 2 4 1 1 1 2 1 1 2 1 2 4 1 1 2 1 2 4 1 2 4 8 1 1 1 74765557613 1 1 1 2 1 1 74765557613 1 1 2 1 74765557613 1 2 74765557613 149531115226 1 1 1 2 1 1 2 1 2 4 1 1 74765557613 1 1 2 1 74765557613 1 2 74765557613 149531115226 1 1 2 1 2 4 1 74765557613 1 2 74765557613 149531115226 1 2 4 74765557613 149531115226 299062230452 1 1 1 2 1 1 2 1 2 4 1 1 2 1 2 4 1 2 4 8 1 1 74765557613 1 1 2 1 74765557613 1 2 74765557613 149531115226 1 1 2 1 2 4 1 74765557613 1 2 74765557613 149531115226 1 2 4 ..."
},
{
"input": "571312007450 10",
"output": "1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 2 1 1 1 1 1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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
}
] | 155 | 7,168,000 | -1 | 56,998 |
|
89 | Space mines | [
"geometry"
] | D. Space mines | 2 | 256 | Once upon a time in the galaxy of far, far away...
Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.
When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon β space mines. Let's describe a space mine's build.
Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius *r* with the center in the point *O*. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point *P*, such that (transporting long-spiked mines is problematic), where |*OP*| is the length of the segment connecting *O* and *P*. It is convenient to describe the point *P* by a vector *p* such that *P*<==<=*O*<=+<=*p*.
The Death Star is shaped like a ball with the radius of *R* (*R* exceeds any mine's radius). It moves at a constant speed along the *v* vector at the speed equal to |*v*|. At the moment the rebels noticed the Star of Death, it was located in the point *A*.
The rebels located *n* space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.
Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed). | The first input data line contains 7 integers *A**x*,<=*A**y*,<=*A**z*,<=*v**x*,<=*v**y*,<=*v**z*,<=*R*. They are the Death Star's initial position, the direction of its movement, and its radius (<=-<=10<=β€<=*v**x*,<=*v**y*,<=*v**z*<=β€<=10, |*v*|<=><=0, 0<=<<=*R*<=β€<=100).
The second line contains an integer *n*, which is the number of mines (1<=β€<=*n*<=β€<=100). Then follow *n* data blocks, the *i*-th of them describes the *i*-th mine.
The first line of each block contains 5 integers *O**ix*,<=*O**iy*,<=*O**iz*,<=*r**i*,<=*m**i*, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0<=<<=*r**i*<=<<=100,<=0<=β€<=*m**i*<=β€<=10). Then follow *m**i* lines, describing the spikes of the *i*-th mine, where the *j*-th of them describes the *i*-th spike and contains 3 integers *p**ijx*,<=*p**ijy*,<=*p**ijz* β the coordinates of the vector where the given spike is directed ().
The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that *R*<=><=*r**i* for any 1<=β€<=*i*<=β€<=*n*. For any mines *i*<=β <=*j* the following inequality if fulfilled: . Initially the Death Star and the mines do not have common points. | If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.
If the Death Star will not touch a mine, print "-1" (without quotes).
For the answer the absolute or relative error of 10<=-<=6 is acceptable. | [
"0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0\n",
"8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0\n",
"30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0\n"
] | [
"10.0000000000",
"-1",
"74.6757620881"
] | none | [
{
"input": "0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0",
"output": "10.0000000000"
},
{
"input": "8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0",
"output": "-1"
},
{
"input": "30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0",
"output": "74.6757620881"
},
{
"input": "100 99 30 -1 -5 -3 100\n1\n100 -90 -50 5 4\n0 6 0\n7 0 0\n6 1 1\n0 -6 -1",
"output": "17.6693584143"
},
{
"input": "0 0 0 5 5 5 20\n1\n-20 0 -30 10 2\n0 11 2\n-5 -8 -6",
"output": "-1"
},
{
"input": "-4 5 8 6 1 5 10\n5\n10 -3 -3 3 1\n0 -4 -2\n5 9 -8 1 1\n-1 0 -1\n-9 8 -6 1 2\n-1 0 1\n0 -1 1\n0 4 -7 3 2\n2 -1 -3\n4 -2 0\n0 -9 -9 3 1\n0 -3 -1",
"output": "-1"
},
{
"input": "-47 -7 -43 5 -8 -10 13\n13\n-10 -40 -34 5 3\n6 -2 3\n-4 -1 -4\n-6 -1 2\n-36 45 33 10 2\n-4 -6 8\n0 -14 -5\n14 -15 6 1 3\n-1 -1 0\n1 0 -1\n0 -1 1\n9 -32 6 6 2\n-1 6 -1\n-4 -2 -5\n45 -31 2 11 2\n0 14 8\n-12 -11 0\n-5 35 -3 7 2\n-9 1 1\n-3 -9 1\n-17 -13 -6 2 1\n2 0 1\n-45 -41 16 10 1\n10 -6 -4\n-46 30 4 4 3\n0 5 -1\n1 4 0\n0 -5 3\n23 10 -31 9 1\n-10 -3 -2\n26 10 0 9 2\n9 -3 2\n-1 4 -10\n-45 12 23 1 1\n-1 1 0\n22 -1 45 5 3\n6 0 4\n0 1 -5\n-4 -1 -3",
"output": "-1"
},
{
"input": "-10000 0 0 1 0 0 2\n1\n10000 3 0 1 0",
"output": "20000.0000000000"
},
{
"input": "-10000 0 0 1 0 0 3\n1\n10000 6 0 2 1\n-3 0 0",
"output": "-1"
},
{
"input": "-10000 0 0 10 1 0 100\n1\n9995 2110 0 10 0",
"output": "2000.2694337364"
},
{
"input": "-10000 0 0 10 1 0 100\n1\n9994 2110 0 10 0",
"output": "-1"
}
] | 92 | 0 | 0 | 57,049 |
317 | Princess and Her Shadow | [
"constructive algorithms",
"shortest paths"
] | null | null | Princess Vlada enjoys springing in the meadows and walking in the forest. One day β wonderful, sunny day β during her walk Princess found out with astonishment that her shadow was missing! "Blimey!", β she thought and started her search of the shadow in the forest.
Normally the Shadow is too lazy and simply sleeps under the Princess. But at this terrifically hot summer day she got bored of such a dull life, so she decided to play with Vlada.
The forest, where our characters entertain themselves, may be represented as a set of integer cells in the plane, where the Shadow and the Princess can move only up, down, left and right by 1. Some cells (as it happens in decent forests) are occupied by trees. The Shadow and the Princess are not allowed to enter a cell occupied by a tree. Unfortunately, these are the hard times for the forest, so there are very few trees growing here...
At first the Princess was walking within the cell (*v**x*,Β *v**y*), while the Shadow hid from the Princess in the cell (*s**x*,Β *s**y*). The Princess, The Shadow and the trees are located in the different cells.
The Shadow is playing with the Princess. As soon as the Princess moves by 1 in some direction, the Shadow simultaneously flies by 1 in the same direction, if it is possible (if the cell to fly to is not occupied by some tree); otherwise, the Shadow doesn't move. The Shadow is very shadowy, so our characters do not interfere with each other.
We say that the Shadow is caught by the Princess if after some move both of them are located in the same cell. Vlada managed to catch her Shadow! Can you? | First line of the input contains the coordinates of the characters *v**x*, *v**y*, *s**x*, *s**y* and the number of trees *m* (0<=β€<=*m*<=β€<=400). The following *m* lines contain the coordinates of the trees.
All the coordinates are integers between -100 and 100, inclusive. The Princess, The Shadow and the trees are located in the different cells. | If it is impossible for the Princess to catch the Shadow, print "-1" (without quotes).
Otherwise print a sequence of characters "L", "R", "D", "U", corresponding to the Princess's moves, following which she will be able to catch the Shadow at some turn (L β move to the left, R β to the right, U β up, D β down; axis *x* is directed to the right, *y* β up).
The number of characters (that is, the number of moves) must not exceed 106. All the Princess's moves should be correct, that is must not lead to the cell where a tree grows. It is allowed for the Princess and the Shadow to occupy the same cell before the last turn. | [
"0 0 1 0 1\n0 1\n",
"5 0 3 0 8\n2 -1\n2 0\n2 1\n3 -1\n4 1\n4 0\n3 1\n4 -1\n",
"3 2 1 1 3\n0 1\n1 0\n0 0\n"
] | [
"LLUR\n",
"-1\n",
"DLL"
] | Below the pictures for the samples are given (Princess, Shadow and the trees are colored in pink, gray and black correspondingly; the blue dot marks the lattice center).
In the first case the Princess may make two left steps, one step upwards and one right step: <img class="tex-graphics" src="https://espresso.codeforces.com/34c3019570fb4cf80b391e93dbddf22fef48f245.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the following case the Princess cannot catch the Shadow: <img class="tex-graphics" src="https://espresso.codeforces.com/063241343ce7958dbc94911c730502450d2396d0.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the last sample the Princess may make two left steps and one down step (in any order): <img class="tex-graphics" src="https://espresso.codeforces.com/9772707754e3581e7b3ff8557e1617678d4c421b.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [] | 92 | 0 | 0 | 57,092 |
|
730 | Running Over The Bridges | [
"greedy",
"implementation",
"math"
] | null | null | Polycarp is playing a game called "Running Over The Bridges". In this game he has to run over *n* bridges from the left to the right. Bridges are arranged one after the other, so the *i*-th bridge begins where the (*i*<=-<=1)-th bridge ends.
You have the following data about bridges: *l**i* and *t**i* β the length of the *i*-th bridge and the maximum allowed time which Polycarp can spend running over the *i*-th bridge. Thus, if Polycarp is in the beginning of the bridge *i* at the time *T* then he has to leave it at the time *T*<=+<=*t**i* or earlier. It is allowed to reach the right end of a bridge exactly at the time *T*<=+<=*t**i*.
Polycarp can run from the left side to the right one with speed 0.5, so he will run over a bridge with length *s* in time 2Β·*s*. Besides, he has several magical drinks. If he uses one drink, his speed increases twice (i.e. to value 1) for *r* seconds. All magical drinks are identical. Please note that Polycarp can use a drink only at integer moments of time, and he drinks it instantly and completely. Additionally, if Polycarp uses a drink at the moment *T* he can use the next drink not earlier than at the moment *T*<=+<=*r*.
What is the minimal number of drinks Polycarp has to use to run over all *n* bridges? If this number is not greater than 105, then you have to find out the moments of time when Polycarp has to use each magical drink. | The first line contains two integers *n* and *r* (1<=β€<=*n*<=β€<=2Β·105, 1<=β€<=*r*<=β€<=1012) β the number of bridges and the duration of the effect of a magical drink.
The second line contains a sequence of integers *l*1,<=*l*2,<=...,<=*l**n* (1<=β€<=*l**i*<=β€<=5Β·106), where *l**i* is equal to the length of the *i*-th bridge.
The third line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=107), where *t**i* is equal to the maximum allowed time which Polycarp can spend running over the *i*-th bridge. | The first line of the output should contain *k* β the minimal number of drinks which Polycarp has to use, or -1 if there is no solution.
If the solution exists and the value of *k* is not greater than 105 then output *k* integers on the next line β moments of time from beginning of the game when Polycarp has to use drinks. Print the moments of time in chronological order. If there are several solutions, you can output any of them. | [
"1 3\n7\n10\n",
"3 3\n3 3 3\n3 3 2\n",
"3 100000\n5 5 5\n5 7 8\n",
"4 1000\n1 2 3 4\n10 9 10 9\n"
] | [
"2\n0 3\n",
"-1\n",
"1\n0 \n",
"0\n\n"
] | In the first case, there is only one bridge and it is clear that Polycarp cannot run over it without magical drinks. So, if he will use one magical drink on start (moment of time 0), and the second one β three seconds later (moment of time 3), he will be able to reach the end of the bridge in time. Please note, in this case there are several possible answers to the problem. For example, Polycarp can use the first drink at the moment of time 4 and the second one β at the moment of time 7.
In the second case, Polycarp cannot run over all bridges even if he will use magical drinks. So, answer in this case is -1.
In the fourth case, Polycarp can run over all bridges without magical drinks. | [] | 46 | 0 | 0 | 57,291 |
|
449 | Jzzhu and Apples | [
"constructive algorithms",
"number theory"
] | null | null | Jzzhu has picked *n* apples from his big apple tree. All the apples are numbered from 1 to *n*. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.
Jzzhu wonders how to get the maximum possible number of groups. Can you help him? | A single integer *n* (1<=β€<=*n*<=β€<=105), the number of the apples. | The first line must contain a single integer *m*, representing the maximum number of groups he can get. Each of the next *m* lines must contain two integers β the numbers of apples in the current group.
If there are several optimal answers you can print any of them. | [
"6\n",
"9\n",
"2\n"
] | [
"2\n6 3\n2 4\n",
"3\n9 3\n2 4\n6 8\n",
"0\n"
] | none | [
{
"input": "6",
"output": "2\n6 3\n2 4"
},
{
"input": "9",
"output": "3\n9 3\n2 4\n6 8"
},
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4\n2 4\n6 8\n10 5\n9 3"
},
{
"input": "100",
"output": "44\n33 27\n22 11\n25 5\n64 66\n42 44\n31 62\n58 29\n43 86\n15 21\n6 99\n8 12\n85 65\n7 49\n23 46\n16 14\n20 18\n90 92\n48 50\n40 36\n74 37\n35 55\n10 95\n56 60\n47 94\n45 39\n93 87\n88 84\n72 76\n28 24\n75 81\n78 80\n54 52\n38 19\n3 9\n32 30\n91 77\n70 68\n63 69\n2 4\n57 51\n82 41\n17 34\n13 26\n96 98"
},
{
"input": "99998",
"output": "47769\n10206 10208\n14044 14046\n35813 35459\n19084 19086\n46543 46529\n48953 97906\n18356 18358\n6951 6957\n22625 22645\n2922 2924\n60109 60067\n90806 45403\n48005 48025\n21063 21069\n12939 12945\n17975 17995\n5972 5974\n27957 27951\n5039 10078\n18683 18641\n55447 55489\n49694 24847\n58015 57995\n49711 99422\n52053 52047\n49718 24859\n84277 84703\n5373 5367\n20303 20777\n23032 23030\n9897 9891\n22008 22004\n78729 78723\n60003 60009\n63 69\n84698 42349\n2797 5594\n71459 71497\n70225 70205\n25896 25898\n387..."
},
{
"input": "100000",
"output": "47770\n10204 10206\n14042 14044\n35341 34987\n19082 19084\n46501 46487\n48947 97894\n18354 18356\n6951 6957\n22595 22615\n2920 2922\n60053 60011\n90778 45389\n47975 47995\n21063 21069\n12939 12945\n17945 17965\n5970 5972\n27957 27951\n5023 10046\n18613 18599\n55391 55433\n49682 24841\n57985 57965\n49697 99394\n52053 52047\n49702 24851\n83141 83851\n5373 5367\n19039 19829\n23030 23028\n9897 9891\n22004 22002\n78729 78723\n60003 60009\n63 69\n84674 42337\n2791 5582\n71117 71231\n70195 70175\n25894 25896\n387..."
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "5",
"output": "1\n2 4"
},
{
"input": "98765",
"output": "47178\n11612 11616\n15444 15448\n23249 22579\n20478 20480\n54061 54047\n950 948\n19768 19770\n6951 6957\n25685 25705\n4360 4362\n67613 67571\n96386 48193\n51065 51085\n21063 21069\n12939 12945\n21035 21055\n7392 7396\n27957 27951\n7247 14494\n26173 26159\n62951 62993\n54874 27437\n61075 61055\n1296 1292\n52053 52047\n54914 27457\n26311 27473\n5373 5367\n80723 81079\n24424 24420\n9897 9891\n23390 23388\n78729 78723\n60003 60009\n63 69\n90122 45061\n4933 9866\n17503 17687\n73285 73265\n27286 27288\n46291 462..."
},
{
"input": "52999",
"output": "25250\n27561 27555\n37761 37755\n21774 21776\n51237 51231\n35158 17579\n52848 52844\n49353 49347\n6951 6957\n9083 9517\n8517 8511\n40294 20147\n51414 51416\n16279 16571\n21063 21069\n12939 12945\n5713 5771\n16569 16563\n27957 27951\n33484 33480\n24974 12487\n19333 38666\n42692 42696\n17113 16459\n735 741\n52053 52047\n42702 42704\n23540 23538\n5373 5367\n24134 24132\n22835 22855\n9897 9891\n15995 16015\n19789 19747\n17495 17515\n63 69\n50156 50158\n32300 32298\n13130 13128\n1622 811\n42355 42335\n32182 160..."
},
{
"input": "99524",
"output": "47542\n10736 10738\n14574 14576\n7991 7747\n19618 19620\n49441 49427\n68 66\n18900 18902\n6951 6957\n23795 23815\n3476 3478\n62993 62951\n92942 46471\n49175 49195\n21063 21069\n12939 12945\n19145 19165\n6510 6512\n27957 27951\n5849 11698\n21553 21539\n58331 58373\n51598 25799\n59185 59165\n396 392\n52053 52047\n51638 25819\n71759 72343\n5373 5367\n16019 16351\n23552 23550\n9897 9891\n22538 22536\n78729 78723\n60003 60009\n63 69\n86638 43319\n3571 7142\n87343 87419\n71395 71375\n26432 26436\n41671 41657\n68..."
},
{
"input": "99994",
"output": "47766\n10216 10218\n14052 14056\n36403 36167\n19092 19096\n46613 46571\n48973 97946\n18366 18368\n6951 6957\n22625 22645\n2930 2932\n60151 60137\n90826 45413\n48005 48025\n21063 21069\n12939 12945\n17975 17995\n5980 5982\n27957 27951\n5051 10102\n18739 18697\n55517 55531\n49702 24851\n58015 57995\n49727 99454\n52053 52047\n49754 24877\n85271 86123\n5373 5367\n21251 21409\n23042 23040\n9897 9891\n22016 22014\n78729 78723\n60003 60009\n63 69\n84718 42359\n2801 5602\n71573 71611\n70225 70205\n25904 25908\n388..."
},
{
"input": "5249",
"output": "2466\n5049 5043\n4286 2143\n274 137\n5054 5056\n2925 2919\n5015 5035\n4470 4472\n4235 4255\n1786 1784\n192 196\n2815 2795\n4125 4119\n1407 1413\n1978 1976\n673 1346\n1152 1150\n3640 3642\n4628 4630\n2111 4222\n4192 4194\n1655 1675\n2923 2701\n1585 1565\n3401 3439\n2632 2634\n4717 4399\n1040 1038\n295 275\n1724 1722\n1217 2434\n2329 2227\n4429 4601\n1684 1686\n1611 1617\n2407 2581\n3609 3603\n1181 2362\n1904 1902\n3763 3551\n2718 2720\n3309 3303\n3452 3450\n229 458\n4644 4646\n4232 4230\n2353 2483\n4620 461..."
},
{
"input": "99999",
"output": "47769\n10204 10206\n14042 14044\n35341 34987\n19082 19084\n46501 46487\n48947 97894\n18354 18356\n6951 6957\n22595 22615\n2920 2922\n60053 60011\n90778 45389\n47975 47995\n21063 21069\n12939 12945\n17945 17965\n5970 5972\n27957 27951\n5023 10046\n18613 18599\n55391 55433\n49682 24841\n57985 57965\n49697 99394\n52053 52047\n49702 24851\n83141 83851\n5373 5367\n19039 19829\n23030 23028\n9897 9891\n22004 22002\n78729 78723\n60003 60009\n63 69\n84674 42337\n2791 5582\n71117 71231\n70195 70175\n25894 25896\n387..."
},
{
"input": "10007",
"output": "4723\n6404 6408\n765 759\n7056 7060\n1519 1477\n2670 2672\n5263 5339\n6625 6605\n6951 6957\n8416 8414\n7186 3593\n3910 3912\n8701 8687\n6135 6141\n4699 4847\n7325 7345\n7746 7744\n2500 2502\n6382 3191\n947 1894\n304 306\n3604 3600\n7282 7284\n925 905\n9389 9553\n8260 8262\n7364 7366\n9198 9196\n5373 5367\n9812 9810\n2411 4822\n9897 9891\n809 1618\n8509 7571\n3723 3729\n1763 1927\n133 119\n4189 4307\n2593 5186\n7133 7091\n1828 1830\n2314 2316\n128 126\n4890 4888\n1342 1344\n1803 1809\n6850 6848\n496 494\n10..."
},
{
"input": "30011",
"output": "14259\n25676 25678\n29464 29466\n25123 25109\n12057 12051\n22390 22392\n15250 15248\n10209 10203\n6951 6957\n6770 6768\n18568 18570\n23530 23532\n13826 13828\n10608 10604\n21063 21069\n12939 12945\n6066 6064\n21580 21582\n27957 27951\n5689 11378\n20016 20020\n23146 23144\n4970 4972\n12112 12114\n15656 15654\n25399 25289\n4994 4996\n2041 2119\n5373 5367\n18629 18707\n23271 23277\n9897 9891\n20559 20565\n10394 5197\n16721 16859\n15380 15378\n12660 12662\n3559 7118\n25095 25101\n13952 13956\n2965 2945\n21730 ..."
},
{
"input": "60013",
"output": "28599\n55344 55348\n59120 59122\n13854 13856\n11049 11043\n8698 4349\n45020 45018\n9165 9159\n6951 6957\n39689 39793\n48304 48306\n13162 6581\n43586 43588\n16399 16537\n21063 21069\n12939 12945\n20267 20371\n51224 51226\n27957 27951\n25612 25610\n614 307\n5821 11642\n34854 34856\n2573 2449\n45344 45342\n52053 52047\n34864 34866\n15644 15642\n5373 5367\n16232 16230\n21951 21957\n9897 9891\n19215 19221\n46795 46775\n60003 60009\n63 69\n42322 42324\n24404 24402\n5130 5128\n13631 13459\n29757 29751\n6274 3137\n..."
},
{
"input": "99991",
"output": "47765\n10218 10220\n14056 14058\n36403 36167\n19096 19098\n46613 46571\n48973 97946\n18368 18370\n6951 6957\n22625 22645\n2932 2934\n60151 60137\n90826 45413\n48005 48025\n21063 21069\n12939 12945\n17975 17995\n5982 5984\n27957 27951\n5051 10102\n18739 18697\n55517 55531\n49702 24851\n58015 57995\n49727 99454\n52053 52047\n49754 24877\n85271 86123\n5373 5367\n21251 21409\n23044 23042\n9897 9891\n22018 22016\n78729 78723\n60003 60009\n63 69\n84718 42359\n2801 5602\n71573 71611\n70225 70205\n25908 25910\n388..."
}
] | 546 | 3,379,200 | 3 | 57,451 |
|
509 | Restoring Numbers | [
"constructive algorithms",
"math"
] | null | null | Vasya had two arrays consisting of non-negative integers: *a* of size *n* and *b* of size *m*. Vasya chose a positive integer *k* and created an *n*<=Γ<=*m* matrix *v* using the following formula:
Vasya wrote down matrix *v* on a piece of paper and put it in the table.
A year later Vasya was cleaning his table when he found a piece of paper containing an *n*<=Γ<=*m* matrix *w*. He remembered making a matrix one day by the rules given above but he was not sure if he had found the paper with the matrix *v* from those days. Your task is to find out if the matrix *w* that you've found could have been obtained by following these rules and if it could, then for what numbers *k*,<=*a*1,<=*a*2,<=...,<=*a**n*,<=*b*1,<=*b*2,<=...,<=*b**m* it is possible. | The first line contains integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100), separated by a space β the number of rows and columns in the found matrix, respectively.
The *i*-th of the following lines contains numbers *w**i*,<=1,<=*w**i*,<=2,<=...,<=*w**i*,<=*m* (0<=β€<=*w**i*,<=*j*<=β€<=109), separated by spaces β the elements of the *i*-th row of matrix *w*. | If the matrix *w* could not have been obtained in the manner described above, print "NO" (without quotes) in the single line of output.
Otherwise, print four lines.
In the first line print "YES" (without quotes).
In the second line print an integer *k* (1<=β€<=*k*<=β€<=1018). Note that each element of table *w* should be in range between 0 and *k*<=-<=1 inclusively.
In the third line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=1018), separated by spaces.
In the fourth line print *m* integers *b*1,<=*b*2,<=...,<=*b**m* (0<=β€<=*b**i*<=β€<=1018), separated by spaces. | [
"2 3\n1 2 3\n2 3 4\n",
"2 2\n1 2\n2 0\n",
"2 2\n1 2\n2 1\n"
] | [
"YES\n1000000007\n0 1 \n1 2 3 ",
"YES\n3\n0 1 \n1 2 ",
"NO\n"
] | By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e4ee2bc16f1508a982cfc739e1c7ddc442223116.png" style="max-width: 100.0%;max-height: 100.0%;"/> we denote the remainder of integer division of *b* by *c*.
It is guaranteed that if there exists some set of numbers *k*,β*a*<sub class="lower-index">1</sub>,β...,β*a*<sub class="lower-index">*n*</sub>,β*b*<sub class="lower-index">1</sub>,β...,β*b*<sub class="lower-index">*m*</sub>, that you could use to make matrix *w*, then there also exists a set of numbers that meets the limits 1ββ€β*k*ββ€β10<sup class="upper-index">18</sup>, 1ββ€β*a*<sub class="lower-index">*i*</sub>ββ€β10<sup class="upper-index">18</sup>, 1ββ€β*b*<sub class="lower-index">*i*</sub>ββ€β10<sup class="upper-index">18</sup> in the output format. In other words, these upper bounds are introduced only for checking convenience purposes. | [
{
"input": "2 3\n1 2 3\n2 3 4",
"output": "YES\n1000000007\n0 1 \n1 2 3 "
},
{
"input": "2 2\n1 2\n2 0",
"output": "YES\n3\n0 1 \n1 2 "
},
{
"input": "2 2\n1 2\n2 1",
"output": "NO"
},
{
"input": "2 2\n2 3\n1 2",
"output": "YES\n1000000007\n0 1000000006 \n2 3 "
},
{
"input": "2 2\n2 0\n1 2",
"output": "YES\n3\n0 2 \n2 0 "
},
{
"input": "2 2\n2 1\n0 2",
"output": "YES\n3\n0 1 \n2 1 "
},
{
"input": "2 2\n0 2\n2 1",
"output": "YES\n3\n0 2 \n0 2 "
},
{
"input": "2 3\n1 3 3\n3 0 1",
"output": "NO"
},
{
"input": "3 2\n1 3\n3 0\n3 1",
"output": "NO"
},
{
"input": "2 3\n3 0 1\n1 3 3",
"output": "NO"
},
{
"input": "3 2\n3 0\n3 1\n1 3",
"output": "NO"
},
{
"input": "3 2\n3 1\n3 0\n1 3",
"output": "NO"
},
{
"input": "3 2\n3 0\n1 3\n3 1",
"output": "NO"
},
{
"input": "2 2\n0 1000000000\n1000000000 0",
"output": "YES\n2000000000\n0 1000000000 \n0 1000000000 "
},
{
"input": "2 2\n0 1000000000\n1000000000 57",
"output": "YES\n1999999943\n0 1000000000 \n0 1000000000 "
},
{
"input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "YES\n1000000007\n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5\n65 65 63 66 63\n86 86 84 87 84\n92 92 90 93 90\n75 75 73 76 73\n67 67 65 68 65",
"output": "YES\n1000000007\n0 21 27 10 2 \n65 65 63 66 63 "
},
{
"input": "5 5\n260683318 260683321 260683319 260683318 260683319\n207210837 207210840 207210838 207210837 207210838\n83257083 83257086 83257084 83257083 83257084\n142444898 142444901 142444899 142444898 142444899\n129630806 129630809 129630807 129630806 129630807",
"output": "YES\n1000000007\n0 946527526 822573772 881761587 868947495 \n260683318 260683321 260683319 260683318 260683319 "
},
{
"input": "1 1\n3",
"output": "YES\n1000000007\n0 \n3 "
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "YES\n1000000007\n0 0 0 \n0 0 0 0 0 "
},
{
"input": "4 1\n42\n23\n77\n19",
"output": "YES\n1000000007\n0 999999988 35 999999984 \n42 "
}
] | 46 | 614,400 | 3 | 57,454 |
|
17 | Balance | [
"dp"
] | C. Balance | 3 | 128 | Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations:
- to take two adjacent characters and replace the second character with the first one, - to take two adjacent characters and replace the first character with the second one
To understand these actions better, let's take a look at a string Β«abcΒ». All of the following strings can be obtained by performing one of the described operations on Β«abcΒ»: Β«bbcΒ», Β«abbΒ», Β«accΒ». Let's denote the frequency of a character for each of the characters a, b and c as the number of occurrences of this character in the string. For example, for string Β«abcΒ»: |*a*| = 1, |*b*| = 1, |*c*| = 1, and for string Β«bbcΒ»: |*a*| = 0, |*b*| = 2, |*c*| = 1.
While performing the described operations, Nick sometimes got balanced strings. Let's say that a string is balanced, if the frequencies of each character differ by at most 1. That is <=-<=1<=β€<=|*a*|<=-<=|*b*|<=β€<=1, <=-<=1<=β€<=|*a*|<=-<=|*c*|<=β€<=1 ΠΈ <=-<=1<=β€<=|*b*|<=-<=|*c*|<=β€<=1.
Would you help Nick find the number of different balanced strings that can be obtained by performing the operations described above, perhaps multiple times, on the given string *s*. This number should be calculated modulo 51123987. | The first line contains integer *n* (1<=β€<=*n*<=β€<=150) β the length of the given string *s*. Next line contains the given string *s*. The initial string can be balanced as well, in this case it should be counted too. The given string *s* consists only of characters a, b and c. | Output the only number β the number of different balanced strings that can be obtained by performing the described operations, perhaps multiple times, on the given string *s*, modulo 51123987. | [
"4\nabca\n",
"4\nabbc\n",
"2\nab\n"
] | [
"7\n",
"3\n",
"1\n"
] | In the first sample it is possible to get 51 different strings through the described operations, but only 7 of them are balanced: Β«abcaΒ», Β«bbcaΒ», Β«bccaΒ», Β«bcaaΒ», Β«abccΒ», Β«abbcΒ», Β«aabcΒ». In the second sample: Β«abbcΒ», Β«aabcΒ», Β«abccΒ». In the third sample there is only one balanced string β Β«abΒ» itself. | [] | 92 | 0 | 0 | 57,638 |
314 | Sereja and Periods | [
"binary search",
"dfs and similar",
"strings"
] | null | null | Let's introduce the designation , where *x* is a string, *n* is a positive integer and operation "<=+<=" is the string concatenation operation. For example, [*abc*,<=2]<==<=*abcabc*.
We'll say that string *s* can be obtained from string *t*, if we can remove some characters from string *t* and obtain string *s*. For example, strings *ab* and *aΡba* can be obtained from string *xacbac*, and strings *bx* and *aaa* cannot be obtained from it.
Sereja has two strings, *w*<==<=[*a*,<=*b*] and *q*<==<=[*c*,<=*d*]. He wants to find such maximum integer *p* (*p*<=><=0), that [*q*,<=*p*] can be obtained from string *w*. | The first line contains two integers *b*, *d* (1<=β€<=*b*,<=*d*<=β€<=107). The second line contains string *a*. The third line contains string *c*. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100. | In a single line print an integer β the largest number *p*. If the required value of *p* doesn't exist, print 0. | [
"10 3\nabab\nbab\n"
] | [
"3\n"
] | none | [
{
"input": "10 3\nabab\nbab",
"output": "3"
},
{
"input": "841 7\nqjqhrksmvedtqldrqgchhsofokfcovut\nqhtmothoulodshrfejterjlguvooccsvqrrdfqfvkqhtecuhhuqhshthrkusrc",
"output": "5"
},
{
"input": "901 8\nkikjbkgkkjeeficiigjjidfhkfdckjdkkbkfhkhdcjidjbfdfkbhbfjeiffkfgcaigck\ngcjifhjjfedbfbdhickjbkkghfhbigkeff",
"output": "28"
},
{
"input": "933 5\nabaabdcbbabacbdddadbbb\nbabbadbaaadbbbbaabbaabccbbdbadbbbbbbdbcbdbaaadbdbdbbbbdcbbdcbdaadbd",
"output": "15"
},
{
"input": "875 10\nhjeaiemqfliohlicmhndhbfdmlmcnjjgbg\nhojqhmbgjlfmlliimlhahfeihgmhhhnbmebhgnfhgmhfjqhmlnnddgmqldelnhebi",
"output": "4"
},
{
"input": "262 6\nidoprkilgmrjqiaieqgfpdflbdjrelpgrqekdmbiqfgeiokslonhrrljoabpfgohp\ngfiolaoiprdpe",
"output": "21"
},
{
"input": "585 5\nbedhdhddadchgchfhdbfgcgfhcghfbgfgebabcebefbhhggdfagadababdaccbeahbhaafcbf\nzbabbgbhhffcdaeeggfhbhhbhaafbdfbafcfaaghbdafecgddagbaeghfdfagbhafbabgghdhbehdcadhdcfgadhabeg",
"output": "0"
},
{
"input": "541 9\nbxhwcmunbdxcatppdsw\nshbppncwbnsxxnxunwsbncpdchcbcspdcppdchmbbcuapphpdxbpcswcxpxpdscxpddbcppdxhpxbuxxdbpdpuudb",
"output": "1"
},
{
"input": "894 7\nrpphclsbplntekrdqffisrbminmnabdopfojhopdckpaqccjiudrq\ndpfrdonoknolipbedqicfppccmcrmsbobphqof",
"output": "11"
},
{
"input": "978 7\nibaddieiabfebdhdfifgjaijdgagjhijebfggggghbeagbcbejfcdebfcdbgiichhbcgaejegadgcefiibcbejicef\nebbefcgacccbadceefgjegejejfbcfiifgegfgaiebijgijjhfhgd",
"output": "27"
},
{
"input": "2980676 3\nemedsmsifhaqiklmcgggkjihdchleppcffrkgnscqskqbmopqprnaaf\nqcnradhfncpsaaromkdhgflrrmddckshcfqklpreiegqbpbaqmrkgalgfpecpfcsiihflllqmsfbr",
"output": "55197"
},
{
"input": "6557487 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaa",
"output": "11172014"
},
{
"input": "4098112 3\ntgprnsjwwfbrccucogpxmxeutcrkhibmudbinkilrkwdjqsdrpnghaoxilnghdokpallikfxdripqkkymrhdcttticwhk\nfithllrrr",
"output": "683018"
},
{
"input": "745524 1\ncaalfoghakfrhfmebkjmmepnhenjaqnopl\noopkpnamhhjlnefafhmakhaajfmofogfmnmamehfgnhrheapjaohpegclheeaahjmpfhfclcloklnn",
"output": "32414"
},
{
"input": "8116900 2\nbbjbegeabfiikbhhkhagdkgdfdkgeefeficegbhehffkfcefcddfadaaaffbcjikkjjiejgahebkikbifhbfbecjehjhec\nfbkiebakhjabhjbjeffcbcfjhfiekfkfghkicaghbeadfiiekeehfcfjeikgefhfhgbegefgfkbbegfefek",
"output": "450938"
},
{
"input": "1748016 1\nmnrnsfijnamfrfoibjilgkjflcieialoskehqjodkasncimicqfhljbcqjshraqlmhimi\nlsnkkhanlsmimlnsmlrcnialrismmjhcfldkaemghsko",
"output": "174801"
},
{
"input": "6266081 2\neccfbahaaddcfebadebbeahcdgfcaacafccchhbhhadhbhfbebbfdcfdegg\naachbfbhccbadbdheeaddfaechgbfdaeacbbbhafceacb",
"output": "522173"
},
{
"input": "320672 1\nwyyojuothwmlvrglfzdzdbtubxuoffvncrswsaznmoijoi\nttvlvzxcvczuagwzgbfuwmmt",
"output": "40084"
},
{
"input": "5608475 1\ngbagadghfaedhddefgbehbbdedefbaaeddachgebhbcgahfdchffhbhfahhdegdhdfbccgefhcdhhcdfgdgfhcdffaacch\nfgfadaaecdgabeahcacadcbfhhe",
"output": "1869491"
},
{
"input": "1263204 1\ndcbabceabbaebddaaecbddaceaedacddadadcbbadbdccdecdacdcaadbceeddccbceaade\nabddbccbdca",
"output": "1894805"
},
{
"input": "6387150 3\ngrlqvotdxnwkxqxvlcidkkgqxmluvqucmxeotdjdgooes\nqkoeldlicvkdlxlqvqrnggl",
"output": "425809"
},
{
"input": "5654408 3\nacbbedadcdaedcdbacccbdacadbdbeabbabaecdadbabcbceeedaabdaadecdadabecdbbbdadbacbacdd\ncbcaeacedacbeababdedadbcccbdeadaedbeaccbbecadbbaaccaaacb",
"output": "628267"
},
{
"input": "9777605 2\nkaecbhbjejamhkjcmmgcikkklmdlfkgjjgaidlakldlecekibekklfifddlgghchllfjcjfflbglgmmbiagaggahbdgbaclm\neeibmalcemfdikjkkagaajefbhldcfmkhmlcbclcfkjbkkaagmhcebbmidmcfhh",
"output": "543200"
},
{
"input": "5723830 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "9444319"
},
{
"input": "2218633 3\nrmsjbustjajqilaeqktslspjordmefdusghkorhggcjpcltrrscioedblqmdqcgjedt\nsaoseotdjusdmkhdiqrlbfghcjqurjegedh",
"output": "105649"
},
{
"input": "9973868 3\nfhballjkkj\nkfjkhkllkhklbhklahffflffkkjljhlkfkjjkjjjjfjakfajjlbfllajjhkjhhkjalfjhfkbbjkjkkkjaf",
"output": "81088"
},
{
"input": "9447267 1\ncbdcbdbcdacbcabddbaabcbacbabcaacbabaccddcbbdbbaddcbcbaaadc\nbbbbdbcbbbdbdbcdcacccbdcadadbacbcccc",
"output": "4723633"
},
{
"input": "6647453 1\ndnccjbmkdlmabcckikqiqkieohnkphinffqojnedo\nincmnmbhdofjncmonodedikbddjkef",
"output": "738605"
},
{
"input": "6568966 2\nhyujabtqwwtbkdog\nwtdubaqqyqw",
"output": "821120"
},
{
"input": "3459996 3\ntomnkbosggldihteenpeochhfggjarktsqrdcalfdpq\nahtcoldeklhlddee",
"output": "288332"
},
{
"input": "1099044 2\ncdccbdbcaacbbcbbabddcbddadbbcaadbabbbddbddbacacaacdbadccbacdcbdaaddddcbcbdbaddabb\naadddbccdcdacaccbbdaccbccbbca",
"output": "274761"
},
{
"input": "3887919 3\nefdkclohoddlpggqjljpcmknepebeindejdkdebkdmfdgilcnmrroeclgebopdliojkhokbroqlbnqrpqdlcogn\njdjhdjdnelonqejdepfjohoggebl",
"output": "259194"
},
{
"input": "2723752 1\nsjbkpbmpllbbgcnokempfjhckcohscaknpbjldhbenskfadpfkbsroldgmfcjoercarjcorsakqqmlifgsrsrnbjbaaeqa\ncsossphdodrbblajpafmbqfaglhhcmqem",
"output": "453958"
},
{
"input": "2308056 3\ngabbfdehcegkmjicakkfhfahllalmkhhhjejfibdhgldjcbfmkfbmileigdmlhajfcciemfcbg\nm",
"output": "4616112"
},
{
"input": "9148326 1\ncddcecc\ncccdecdecccccccdcddcccccedcdcdcccccddcccccdceddccccccccceddcccedddccddcccecccdccdcddd",
"output": "351858"
},
{
"input": "8058035 2\nrioqrqetkzfbldjiemsfzbhzfnwywmxxgdpyl\ngfmhefhyyndzmsbfnefmwmpxfxfhflzplgoxfrrdxilibzlephlezisfztsfitnrzrilzmtipzofkrwlmhnifdzwexzzxjpy",
"output": "125906"
},
{
"input": "1181362 3\nfckmaalkicfakhcbiglkekajmadjkj\nzfkjkjgkmjhfkackkhhjalgkkclcklabggk",
"output": "0"
},
{
"input": "10000000 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\na",
"output": "1000000000"
},
{
"input": "10000000 10000000\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "10000000 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "10000000"
},
{
"input": "10000000 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nz",
"output": "0"
},
{
"input": "1 1\na\nb",
"output": "0"
},
{
"input": "1 1\na\na",
"output": "1"
},
{
"input": "1000000 1\na\na",
"output": "1000000"
},
{
"input": "1 1000000\na\na",
"output": "0"
},
{
"input": "1000 1\nbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nab",
"output": "999"
},
{
"input": "10000000 1\nbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab\na",
"output": "980000000"
}
] | 124 | 2,252,800 | 0 | 57,774 |
|
711 | Directed Roads | [
"combinatorics",
"dfs and similar",
"graphs",
"math"
] | null | null | ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of *n* towns numbered from 1 to *n*.
There are *n* directed roads in the Udayland. *i*-th of them goes from town *i* to some other town *a**i* (*a**i*<=β <=*i*). ZS the Coder can flip the direction of any road in Udayland, i.e. if it goes from town *A* to town *B* before the flip, it will go from town *B* to town *A* after.
ZS the Coder considers the roads in the Udayland confusing, if there is a sequence of distinct towns *A*1,<=*A*2,<=...,<=*A**k* (*k*<=><=1) such that for every 1<=β€<=*i*<=<<=*k* there is a road from town *A**i* to town *A**i*<=+<=1 and another road from town *A**k* to town *A*1. In other words, the roads are confusing if some of them form a directed cycle of some towns.
Now ZS the Coder wonders how many sets of roads (there are 2*n* variants) in initial configuration can he choose to flip such that after flipping each road in the set exactly once, the resulting network will not be confusing.
Note that it is allowed that after the flipping there are more than one directed road from some town and possibly some towns with no roads leading out of it, or multiple roads between any pair of cities. | The first line of the input contains single integer *n* (2<=β€<=*n*<=β€<=2Β·105)Β β the number of towns in Udayland.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*,<=*a**i*<=β <=*i*), *a**i* denotes a road going from town *i* to town *a**i*. | Print a single integerΒ β the number of ways to flip some set of the roads so that the resulting whole set of all roads is not confusing. Since this number may be too large, print the answer modulo 109<=+<=7. | [
"3\n2 3 1\n",
"4\n2 1 1 1\n",
"5\n2 4 2 5 3\n"
] | [
"6\n",
"8\n",
"28\n"
] | Consider the first sample case. There are 3 towns and 3 roads. The towns are numbered from 1 to 3 and the roads are <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/030fc9181b578c2d906254d38dc56da5554323eb.png" style="max-width: 100.0%;max-height: 100.0%;"/> initially. Number the roads 1 to 3 in this order.
The sets of roads that ZS the Coder can flip (to make them not confusing) are {1},β{2},β{3},β{1,β2},β{1,β3},β{2,β3}. Note that the empty set is invalid because if no roads are flipped, then towns 1,β2,β3 is form a directed cycle, so it is confusing. Similarly, flipping all roads is confusing too. Thus, there are a total of 6 possible sets ZS the Coder can flip.
The sample image shows all possible ways of orienting the roads from the first sample such that the network is not confusing.
<img class="tex-graphics" src="https://espresso.codeforces.com/2e275877797bea4817665ce9cfb5274b837194bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "3\n2 3 1",
"output": "6"
},
{
"input": "4\n2 1 1 1",
"output": "8"
},
{
"input": "5\n2 4 2 5 3",
"output": "28"
},
{
"input": "4\n2 1 4 3",
"output": "4"
},
{
"input": "7\n2 3 4 1 6 5 4",
"output": "56"
},
{
"input": "20\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1",
"output": "1048574"
},
{
"input": "2\n2 1",
"output": "2"
},
{
"input": "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81 14 19 48 80 73 69 78 39 6 76 46 75 72 84 29 58 59 13 17 82 9 83 4 36 56 53 7 64 44",
"output": "428380105"
}
] | 62 | 7,168,000 | 0 | 57,847 |
|
311 | Interval Cubing | [
"data structures",
"math"
] | null | null | While learning Computational Geometry, Tiny is simultaneously learning a useful data structure called segment tree or interval tree. He has scarcely grasped it when comes out a strange problem:
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n*. You should run *q* queries of two types:
1. Given two integers *l* and *r* (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), ask the sum of all elements in the sequence *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*. 1. Given two integers *l* and *r* (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), let each element *x* in the sequence *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* becomes *x*3. In other words, apply an assignments *a**l*<==<=*a**l*3,<=*a**l*<=+<=1<==<=*a**l*<=+<=13,<=...,<=*a**r*<==<=*a**r*3.
For every query of type 1, output the answer to it.
Tiny himself surely cannot work it out, so he asks you for help. In addition, Tiny is a prime lover. He tells you that because the answer may be too huge, you should only output it modulo 95542721 (this number is a prime number). | The first line contains an integer *n* (1<=β€<=*n*<=β€<=105), representing the length of the sequence. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=109).
The third line contains an integer *q* (1<=β€<=*q*<=β€<=105), representing the number of queries. Then follow *q* lines. Each line contains three integers *t**i* (1<=β€<=*t**i*<=β€<=2), *l**i*, *r**i* (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*), where *t**i* stands for the type of the query while *l**i* and *r**i* is the parameters of the query, correspondingly. | For each 1-type query, print the answer to it per line.
You should notice that each printed number should be non-negative and less than 95542721. | [
"8\n1 2 3 4 5 6 7 8\n5\n1 2 5\n2 2 5\n1 2 5\n2 3 6\n1 4 7\n"
] | [
"14\n224\n2215492\n"
] | none | [] | 6,000 | 14,131,200 | 0 | 57,854 |
|
333 | Characteristics of Rectangles | [
"binary search",
"bitmasks",
"brute force",
"implementation",
"sortings"
] | null | null | Gerald found a table consisting of *n* rows and *m* columns. As a prominent expert on rectangular tables, he immediately counted the table's properties, that is, the minimum of the numbers in the corners of the table (minimum of four numbers). However, he did not like the final value β it seemed to be too small. And to make this value larger, he decided to crop the table a little: delete some columns on the left and some on the right, as well as some rows from the top and some from the bottom. Find what the maximum property of the table can be after such cropping. Note that the table should have at least two rows and at least two columns left in the end. The number of cropped rows or columns from each of the four sides can be zero. | The first line contains two space-separated integers *n* and *m* (2<=β€<=*n*,<=*m*<=β€<=1000). The following *n* lines describe the table. The *i*-th of these lines lists the space-separated integers *a**i*,<=1,<=*a**i*,<=2,<=...,<=*a**i*,<=*m* (0<=β€<=*a**i*,<=*j*<=β€<=109) β the *m* numbers standing in the *i*-th row of the table. | Print the answer to the problem. | [
"2 2\n1 2\n3 4\n",
"3 3\n1 0 0\n0 1 1\n1 0 0\n"
] | [
"1\n",
"0\n"
] | In the first test case Gerald cannot crop the table β table contains only two rows and only two columns.
In the second test case if we'll crop the table, the table will contain zero in some corner cell. Also initially it contains two zeros in the corner cells, so the answer is 0. | [
{
"input": "2 2\n1 2\n3 4",
"output": "1"
},
{
"input": "3 3\n1 0 0\n0 1 1\n1 0 0",
"output": "0"
},
{
"input": "2 2\n0 0\n0 0",
"output": "0"
},
{
"input": "2 2\n1000000000 1000000000\n1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 2\n1 20\n19 2\n3 18\n17 4\n5 16\n15 6\n7 14\n13 8\n9 12\n11 10",
"output": "9"
},
{
"input": "2 5\n10 10 10 10 10\n11 10 11 10 11",
"output": "10"
},
{
"input": "4 4\n1 0 1 0\n0 1 0 1\n1 0 0 1\n0 1 1 0",
"output": "0"
}
] | 60 | 0 | 0 | 57,876 |
|
630 | Game | [
"games",
"math"
] | null | null | There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of *n*<=Γ<=*n* cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.
The professor have chosen the field size *n* and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally. | The only line of the input contains one integer *n* (1<=β€<=*n*<=β€<=1018) β the size of the field. | Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2. | [
"1\n",
"2\n"
] | [
"1",
"2"
] | none | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "1"
},
{
"input": "1000000000000000000",
"output": "2"
},
{
"input": "999999999999999999",
"output": "1"
},
{
"input": "321392715309062180",
"output": "2"
},
{
"input": "95451113283177888",
"output": "2"
},
{
"input": "25496382240130775",
"output": "1"
}
] | 0 | 0 | -1 | 57,885 |
|
295 | Greg and Friends | [
"combinatorics",
"dp",
"graphs",
"shortest paths"
] | null | null | One day Greg and his friends were walking in the forest. Overall there were *n* people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold people with the total weight of at most *k* kilograms.
Greg immediately took a piece of paper and listed there the weights of all people in his group (including himself). It turned out that each person weights either 50 or 100 kilograms. Now Greg wants to know what minimum number of times the boat needs to cross the river to transport the whole group to the other bank. The boat needs at least one person to navigate it from one bank to the other. As the boat crosses the river, it can have any non-zero number of passengers as long as their total weight doesn't exceed *k*.
Also Greg is wondering, how many ways there are to transport everybody to the other side in the minimum number of boat rides. Two ways are considered distinct if during some ride they have distinct sets of people on the boat.
Help Greg with this problem. | The first line contains two integers *n*, *k* (1<=β€<=*n*<=β€<=50,<=1<=β€<=*k*<=β€<=5000) β the number of people, including Greg, and the boat's weight limit. The next line contains *n* integers β the people's weights. A person's weight is either 50 kilos or 100 kilos.
You can consider Greg and his friends indexed in some way. | In the first line print an integer β the minimum number of rides. If transporting everyone to the other bank is impossible, print an integer -1.
In the second line print the remainder after dividing the number of ways to transport the people in the minimum number of rides by number 1000000007 (109<=+<=7). If transporting everyone to the other bank is impossible, print integer 0. | [
"1 50\n50\n",
"3 100\n50 50 100\n",
"2 50\n50 50\n"
] | [
"1\n1\n",
"5\n2\n",
"-1\n0\n"
] | In the first test Greg walks alone and consequently, he needs only one ride across the river.
In the second test you should follow the plan:
1. transport two 50 kg. people; 1. transport one 50 kg. person back; 1. transport one 100 kg. person; 1. transport one 50 kg. person back; 1. transport two 50 kg. people.
That totals to 5 rides. Depending on which person to choose at step 2, we can get two distinct ways. | [
{
"input": "1 50\n50",
"output": "1\n1"
},
{
"input": "3 100\n50 50 100",
"output": "5\n2"
},
{
"input": "2 50\n50 50",
"output": "-1\n0"
},
{
"input": "5 258\n100 100 50 50 50",
"output": "3\n72"
},
{
"input": "8 191\n50 100 50 100 50 100 100 50",
"output": "11\n19318272"
},
{
"input": "3 121\n100 100 50",
"output": "-1\n0"
},
{
"input": "8 271\n100 50 100 50 50 50 100 50",
"output": "5\n78090"
},
{
"input": "2 233\n50 100",
"output": "1\n1"
},
{
"input": "2 153\n100 50",
"output": "1\n1"
},
{
"input": "5 257\n50 50 50 50 50",
"output": "1\n1"
},
{
"input": "49 290\n100 100 100 100 100 100 100 100 50 100 50 100 100 100 50 50 100 50 50 100 100 100 100 100 100 50 100 100 50 100 50 50 100 100 100 50 50 50 50 50 100 100 100 50 100 50 100 50 50",
"output": "39\n99624366"
},
{
"input": "29 129\n50 50 50 100 100 100 50 100 50 50 50 100 50 100 100 100 50 100 100 100 50 50 50 50 50 50 50 50 50",
"output": "77\n37050209"
},
{
"input": "32 121\n100 100 100 100 100 50 100 100 50 100 50 100 50 100 50 100 50 50 50 100 100 50 100 100 100 100 50 100 50 100 100 50",
"output": "101\n245361086"
},
{
"input": "3 118\n100 100 100",
"output": "-1\n0"
},
{
"input": "10 4894\n100 50 50 50 100 50 50 100 50 100",
"output": "1\n1"
},
{
"input": "36 250\n50 100 100 50 100 100 100 50 50 100 50 50 50 50 50 50 100 50 100 100 100 100 100 100 100 50 50 100 50 50 100 100 100 100 100 50",
"output": "27\n77447096"
},
{
"input": "31 291\n50 100 100 50 100 100 100 50 100 100 100 100 50 50 50 100 100 100 50 100 100 50 50 50 50 100 100 50 50 100 100",
"output": "23\n393964729"
},
{
"input": "31 161\n100 50 50 50 50 100 50 100 50 100 100 50 50 100 100 50 100 50 50 100 50 100 100 50 50 100 50 50 100 50 100",
"output": "43\n670669365"
},
{
"input": "5 123\n50 100 50 50 50",
"output": "9\n4536"
},
{
"input": "43 293\n50 50 100 100 50 100 100 50 100 100 50 100 50 100 50 50 50 50 50 100 100 100 50 50 100 50 100 100 100 50 100 100 100 50 50 50 100 50 100 100 50 100 50",
"output": "31\n658920847"
},
{
"input": "23 100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "43\n689584957"
},
{
"input": "41 218\n50 50 100 50 100 100 50 100 100 50 50 100 50 50 50 50 100 50 100 50 50 50 100 50 50 50 50 100 100 100 100 100 100 50 100 50 100 100 100 50 50",
"output": "39\n298372053"
},
{
"input": "11 4668\n50 100 100 100 50 100 50 50 100 100 100",
"output": "1\n1"
},
{
"input": "43 178\n50 50 100 100 100 50 100 100 50 100 100 100 50 100 50 100 50 50 100 100 50 100 100 50 50 50 100 50 50 50 100 50 100 100 100 50 100 50 50 50 50 100 100",
"output": "63\n503334985"
},
{
"input": "33 226\n50 50 50 50 50 100 100 100 100 50 100 50 100 50 100 50 100 100 50 50 50 100 100 50 50 100 50 100 50 100 50 50 50",
"output": "31\n370884215"
},
{
"input": "1 2994\n100",
"output": "1\n1"
},
{
"input": "1 204\n50",
"output": "1\n1"
},
{
"input": "33 123\n50 100 100 100 50 100 50 50 50 50 50 100 100 50 100 50 100 50 50 50 50 50 50 50 100 100 50 50 100 100 100 100 100",
"output": "93\n337243149"
},
{
"input": "34 2964\n50 50 50 50 50 100 50 100 50 100 100 50 50 50 50 50 50 100 100 100 50 50 100 100 50 50 50 100 50 100 100 50 100 50",
"output": "1\n1"
},
{
"input": "27 200\n50 50 50 50 100 100 50 50 100 100 100 50 100 50 100 50 50 100 100 100 50 100 100 50 50 50 100",
"output": "25\n271877303"
},
{
"input": "31 197\n50 100 50 50 100 50 100 100 100 50 50 100 50 100 50 50 50 50 100 100 50 50 100 50 50 50 50 50 100 50 100",
"output": "41\n24368657"
},
{
"input": "28 183\n50 100 100 50 100 50 100 100 50 100 50 100 100 100 50 50 100 50 50 50 100 50 100 50 50 100 100 100",
"output": "41\n844409785"
},
{
"input": "48 204\n100 100 100 50 50 50 50 100 100 50 100 100 50 100 50 50 50 100 100 100 50 100 50 50 50 100 50 100 50 100 100 100 50 50 100 100 100 50 100 50 50 50 50 50 100 50 50 50",
"output": "45\n538567333"
},
{
"input": "5 188\n50 50 50 50 50",
"output": "3\n30"
},
{
"input": "29 108\n100 50 100 100 100 100 100 50 50 100 100 100 50 100 50 50 100 50 100 50 50 100 100 50 50 50 100 100 50",
"output": "87\n417423429"
},
{
"input": "50 125\n50 50 50 100 100 50 100 100 50 50 100 100 100 100 100 100 50 50 100 50 100 100 50 50 50 100 100 50 100 100 100 100 100 100 100 50 50 50 100 50 50 50 50 100 100 100 100 100 50 50",
"output": "153\n971933773"
},
{
"input": "50 2263\n50 100 50 100 50 100 100 100 50 50 50 100 100 100 100 100 100 50 50 100 50 100 50 50 100 50 50 100 100 50 100 100 100 50 50 50 100 50 100 50 50 50 50 50 100 100 50 50 100 50",
"output": "3\n211048352"
},
{
"input": "50 110\n50 100 100 50 50 50 50 50 50 50 100 100 50 100 50 50 50 50 100 50 100 100 100 100 50 100 100 100 100 50 50 50 50 50 100 100 50 100 50 100 100 50 50 100 50 100 50 50 100 100",
"output": "143\n105841088"
},
{
"input": "50 185\n100 50 50 50 50 50 100 50 100 50 100 100 50 50 100 100 100 50 50 100 50 100 50 50 100 100 100 100 100 50 50 100 100 100 50 100 50 100 50 50 100 50 100 50 50 100 50 50 100 100",
"output": "73\n930170107"
},
{
"input": "50 207\n50 100 100 100 100 50 100 100 100 50 100 100 100 50 100 100 50 100 50 100 50 100 100 100 50 100 50 50 100 50 100 100 50 100 100 100 100 50 100 100 100 100 50 50 50 100 100 50 100 100",
"output": "55\n833060250"
},
{
"input": "3 49\n50 50 50",
"output": "-1\n0"
},
{
"input": "3 50\n50 50 50",
"output": "-1\n0"
},
{
"input": "3 99\n100 50 50",
"output": "-1\n0"
},
{
"input": "4 100\n100 100 100 50",
"output": "-1\n0"
}
] | 0 | 0 | -1 | 57,911 |
|
535 | Tavas and Malekas | [
"greedy",
"hashing",
"string suffix structures",
"strings"
] | null | null | Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string *s* of length *n* comes out from Tavas' mouth instead.
Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on *s*. Malekas has a favorite string *p*. He determined all positions *x*1<=<<=*x*2<=<<=...<=<<=*x**k* where *p* matches *s*. More formally, for each *x**i* (1<=β€<=*i*<=β€<=*k*) he condition *s**x**i**s**x**i*<=+<=1... *s**x**i*<=+<=|*p*|<=-<=1<==<=*p* is fullfilled.
Then Malekas wrote down one of subsequences of *x*1,<=*x*2,<=... *x**k* (possibly, he didn't write anything) on a piece of paper. Here a sequence *b* is a subsequence of sequence *a* if and only if we can turn *a* into *b* by removing some of its elements (maybe no one of them or all).
After Tavas woke up, Malekas told him everything. He couldn't remember string *s*, but he knew that both *p* and *s* only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.
Tavas wonders, what is the number of possible values of *s*? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.
Answer can be very large, so Tavas wants you to print the answer modulo 109<=+<=7. | The first line contains two integers *n* and *m*, the length of *s* and the length of the subsequence Malekas wrote down (1<=β€<=*n*<=β€<=106 and 0<=β€<=*m*<=β€<=*n*<=-<=|*p*|<=+<=1).
The second line contains string *p* (1<=β€<=|*p*|<=β€<=*n*).
The next line contains *m* space separated integers *y*1,<=*y*2,<=...,<=*y**m*, Malekas' subsequence (1<=β€<=*y*1<=<<=*y*2<=<<=...<=<<=*y**m*<=β€<=*n*<=-<=|*p*|<=+<=1). | In a single line print the answer modulo 1000<=000<=007. | [
"6 2\nioi\n1 3\n",
"5 2\nioi\n1 2\n"
] | [
"26\n",
"0\n"
] | In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.
Here |*x*| denotes the length of string x.
Please note that it's possible that there is no such string (answer is 0). | [
{
"input": "6 2\nioi\n1 3",
"output": "26"
},
{
"input": "5 2\nioi\n1 2",
"output": "0"
},
{
"input": "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacbabcaccccccaacacabbbbbacabbaaacbcbbaccaccabbbbaabbacacbabccaabcabbbcacaaccbabbcaaaaaabccbbcabcacbcbcabcbcbbaabacaaccccabacaaaccacaaabbacacabbcccacbaabcacacbbaaaccaccbaccccccbccaabcacaacabaccababacabcccbcbbacbabacbcbabacbbaccaabcabcbbbaaabbacbbbcacccbaaacacbaccbbcccccabaaa\n110876 118837 169880 171013 172546 173196",
"output": "375252451"
},
{
"input": "35324 4\nrpcshyyhtvyylyxcqrqonzvlrghvjdejzdtovqichwiavbxztdrtrczhcxtzojlisqwwzvnwrhimmfopazliutcgjslcmyddvxtwueqqzlsgrgjflyihwzncyikncikiutscfbmylgbkoinyvvqsthzmkwehrgliyoxafstviahfiyfwoeahynfhbdjkrlzabuvshcczucihqvtsuzqbyjdwzwv\n2944 22229 25532 34932",
"output": "318083188"
},
{
"input": "631443 15\nyyrcventdoofxaioiixfzpeivudpsc\n581542 593933 597780 610217 618513 628781 629773 630283 630688 630752 630967 631198 631310 631382 631412",
"output": "649825044"
},
{
"input": "1 1\na\n1",
"output": "1"
},
{
"input": "10 4\ne\n1 2 9 10",
"output": "308915776"
},
{
"input": "10 5\naa\n1 2 3 7 9",
"output": "676"
},
{
"input": "10 5\nab\n1 3 4 6 9",
"output": "0"
},
{
"input": "1 0\na",
"output": "26"
},
{
"input": "100000 0\njlasosafuywefgwefdyktfwydugewdefwdulewdopqywgdwqdiuhdbcxxiuhfiehfewhfoewihfwoiefewiugwefgiuwgfiwefuiwgefwefwppoollmmzzqaayudgsufzxcvbnmasdfghjklqwertyuiop",
"output": "834294302"
},
{
"input": "1000000 0\nqwertyuiopasdfghjklzxcvbnmmmqwertyuioplkjhgfdsazxccccvbnmqazwsxedcrfvtgbyhnujmikolp",
"output": "217018478"
},
{
"input": "10 0\naaa",
"output": "94665207"
},
{
"input": "100 2\nbaabbaabbbbbbbbabaabbbabbbabbabbaababbbbbbab\n1 23",
"output": "0"
},
{
"input": "20 2\nabababab\n1 6",
"output": "0"
},
{
"input": "20 2\nabracadabra\n1 10",
"output": "0"
}
] | 2,000 | 268,390,400 | 0 | 57,956 |
|
1,000 | One Occurrence | [
"data structures",
"divide and conquer"
] | null | null | You are given an array $a$ consisting of $n$ integers, and $q$ queries to it. $i$-th query is denoted by two integers $l_i$ and $r_i$. For each query, you have to find any integer that occurs exactly once in the subarray of $a$ from index $l_i$ to index $r_i$ (a subarray is a contiguous subsegment of an array). For example, if $a = [1, 1, 2, 3, 2, 4]$, then for query $(l_i = 2, r_i = 6)$ the subarray we are interested in is $[1, 2, 3, 2, 4]$, and possible answers are $1$, $3$ and $4$; for query $(l_i = 1, r_i = 2)$ the subarray we are interested in is $[1, 1]$, and there is no such element that occurs exactly once.
Can you answer all of the queries? | The first line contains one integer $n$ ($1 \le n \le 5 \cdot 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 5 \cdot 10^5$).
The third line contains one integer $q$ ($1 \le q \le 5 \cdot 10^5$).
Then $q$ lines follow, $i$-th line containing two integers $l_i$ and $r_i$ representing $i$-th query ($1 \le l_i \le r_i \le n$). | Answer the queries as follows:
If there is no integer such that it occurs in the subarray from index $l_i$ to index $r_i$ exactly once, print $0$. Otherwise print any such integer. | [
"6\n1 1 2 3 2 4\n2\n2 6\n1 2\n"
] | [
"4\n0\n"
] | none | [
{
"input": "6\n1 1 2 3 2 4\n2\n2 6\n1 2",
"output": "4\n0"
},
{
"input": "10\n5 9 6 4 8 7 4 9 7 6\n10\n4 9\n4 7\n4 7\n4 8\n9 10\n4 9\n4 8\n1 5\n4 4\n2 5",
"output": "8\n8\n8\n8\n6\n8\n8\n8\n4\n9"
}
] | 3,000 | 41,062,400 | 0 | 58,017 |
|
379 | New Year Letter | [
"bitmasks",
"brute force",
"dp"
] | null | null | Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, *s*1 anf *s*2, consisting of uppercase English letters. Then the boy makes string *s**k*, using a recurrent equation *s**n*<==<=*s**n*<=-<=2<=+<=*s**n*<=-<=1, operation '+' means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string *s**k* on a piece of paper, puts it in the envelope and sends in to Santa.
Vasya is absolutely sure that Santa will bring him the best present if the resulting string *s**k* has exactly *x* occurrences of substring AC (the short-cut reminds him ΠΎf accepted problems). Besides, Vasya decided that string *s*1 should have length *n*, and string *s*2 should have length *m*. Vasya hasn't decided anything else.
At the moment Vasya's got urgent New Year business, so he asks you to choose two strings for him, *s*1 and *s*2 in the required manner. Help Vasya. | The first line contains four integers *k*,<=*x*,<=*n*,<=*m* (3<=β€<=*k*<=β€<=50;Β 0<=β€<=*x*<=β€<=109;Β 1<=β€<=*n*,<=*m*<=β€<=100). | In the first line print string *s*1, consisting of *n* uppercase English letters. In the second line print string *s*2, consisting of *m* uppercase English letters. If there are multiple valid strings, print any of them.
If the required pair of strings doesn't exist, print "Happy new year!" without the quotes. | [
"3 2 2 2\n",
"3 3 2 2\n",
"3 0 2 2\n",
"4 3 2 1\n",
"4 2 2 1\n"
] | [
"AC\nAC\n",
"Happy new year!\n",
"AA\nAA\n",
"Happy new year!\n",
"Happy new year!\n"
] | none | [
{
"input": "3 2 2 2",
"output": "AC\nAC"
},
{
"input": "3 3 2 2",
"output": "Happy new year!"
},
{
"input": "3 0 2 2",
"output": "AA\nAA"
},
{
"input": "4 3 2 1",
"output": "Happy new year!"
},
{
"input": "4 2 2 1",
"output": "Happy new year!"
},
{
"input": "3 0 1 1",
"output": "A\nA"
},
{
"input": "50 0 100 100",
"output": "AZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nAZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA"
},
{
"input": "50 1 100 100",
"output": "Happy new year!"
},
{
"input": "4 32 23 32",
"output": "ACACZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA"
},
{
"input": "5 45 23 32",
"output": "AZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA"
},
{
"input": "6 54 23 32",
"output": "ACACACZZZZZZZZZZZZZZZZA\nACACACACACACACACACZZZZZZZZZZZZZA"
},
{
"input": "7 120 23 32",
"output": "AZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA"
},
{
"input": "8 664 100 100",
"output": "ACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACZZZA"
},
{
"input": "8 661 100 99",
"output": "ACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACA"
},
{
"input": "8 704 99 100",
"output": "ACACACACACACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACZZZA"
},
{
"input": "10 189 44 100",
"output": "ACACACACACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZA\nAZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA"
},
{
"input": "3 1 1 6",
"output": "A\nACZZZA"
},
{
"input": "3 1 6 1",
"output": "ACZZZA\nA"
},
{
"input": "50 1000000000 100 100",
"output": "Happy new year!"
},
{
"input": "6 4 3 2",
"output": "AZA\nCA"
},
{
"input": "5 4 3 2",
"output": "ACA\nCB"
},
{
"input": "3 3 3 3",
"output": "ACA\nCAC"
},
{
"input": "48 512559680 100 100",
"output": "Happy new year!"
},
{
"input": "3 1 1 1",
"output": "A\nC"
},
{
"input": "5 4 2 3",
"output": "CA\nACA"
},
{
"input": "3 2 3 1",
"output": "ACA\nC"
},
{
"input": "5 2 1 1",
"output": "A\nC"
},
{
"input": "10 143 4 6",
"output": "CACA\nCACACA"
},
{
"input": "7 3 1 3",
"output": "B\nCZA"
},
{
"input": "5 1 10 10",
"output": "AZZZZZZZZB\nCZZZZZZZZA"
},
{
"input": "6 4 2 2",
"output": "AA\nCA"
},
{
"input": "9 33 2 2",
"output": "CA\nCA"
},
{
"input": "5 1 2 2",
"output": "AB\nCA"
},
{
"input": "5 4 2 2",
"output": "CA\nCA"
},
{
"input": "5 1 1 1",
"output": "C\nA"
},
{
"input": "4 4 3 3",
"output": "ACA\nCAC"
},
{
"input": "33 100034454 87 58",
"output": "Happy new year!"
},
{
"input": "7 4 1 2",
"output": "C\nAA"
},
{
"input": "6 7 3 2",
"output": "ACA\nCA"
},
{
"input": "7 12 2 2",
"output": "CA\nCA"
},
{
"input": "48 512559680 2 2",
"output": "Happy new year!"
},
{
"input": "6 1 2 2",
"output": "AB\nCA"
},
{
"input": "6 3 1 1",
"output": "A\nC"
},
{
"input": "4 6 3 5",
"output": "ACA\nCACAC"
},
{
"input": "13 6325 61 51",
"output": "Happy new year!"
},
{
"input": "8 7 1 1",
"output": "Happy new year!"
}
] | 46 | 0 | 0 | 58,246 |
|
101 | Castle | [
"dp",
"greedy",
"probabilities",
"sortings",
"trees"
] | D. Castle | 2 | 256 | Gerald is positioned in an old castle which consists of *n* halls connected with *n*<=-<=1 corridors. It is exactly one way to go from any hall to any other one. Thus, the graph is a tree. Initially, at the moment of time 0, Gerald is positioned in hall 1. Besides, some other hall of the castle contains the treasure Gerald is looking for. The treasure's position is not known; it can equiprobably be in any of other *n*<=-<=1 halls. Gerald can only find out where the treasure is when he enters the hall with the treasure. That very moment Gerald sees the treasure and the moment is regarded is the moment of achieving his goal.
The corridors have different lengths. At that, the corridors are considered long and the halls are considered small and well lit. Thus, it is possible not to take the time Gerald spends in the halls into consideration. The castle is very old, that's why a corridor collapses at the moment when somebody visits it two times, no matter in which direction.
Gerald can move around the castle using the corridors; he will go until he finds the treasure. Naturally, Gerald wants to find it as quickly as possible. In other words, he wants to act in a manner that would make the average time of finding the treasure as small as possible. Each corridor can be used no more than two times. That's why Gerald chooses the strategy in such a way, so he can visit every hall for sure.
More formally, if the treasure is located in the second hall, then Gerald will find it the moment he enters the second hall for the first time β let it be moment *t*2. If the treasure is in the third hall, then Gerald will find it the moment he enters the third hall for the first time. Let it be the moment of time *t*3. And so on. Thus, the average time of finding the treasure will be equal to . | The first line contains the only integer *n* (2<=β€<=*n*<=β€<=105) β the number of halls in the castle. Next *n*<=-<=1 lines each contain three integers. The *i*-th line contains numbers *a**i*, *b**i* and *t**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*, 1<=β€<=*t**i*<=β€<=1000) β the numbers of halls connected with the *i*-th corridor and the time needed to go along the corridor. Initially Gerald is in the hall number 1. It is guaranteed that one can get from any hall to any other one using corridors. | Print the only real number: the sought expectation of time needed to find the treasure. The answer should differ from the right one in no less than 10<=-<=6. | [
"2\n1 2 1\n",
"4\n1 3 2\n4 2 1\n3 2 3\n",
"5\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n"
] | [
"1.0\n",
"4.333333333333334\n",
"4.0\n"
] | In the first test the castle only has two halls which means that the treasure is located in the second hall. Gerald will only need one minute to go to the second hall from the first one.
In the second test Gerald can only go from the first hall to the third one. He can get from the third room to the first one or to the second one, but he has already visited the first hall and can get nowhere from there. Thus, he needs to go to the second hall. He should go to hall 4 from there, because all other halls have already been visited. If the treasure is located in the third hall, Gerald will find it in a minute, if the treasure is located in the second hall, Gerald finds it in two minutes, if the treasure is in the fourth hall, Gerald will find it in three minutes. The average time makes 2 minutes.
In the third test Gerald needs to visit 4 halls: the second, third, fourth and fifth ones. All of them are only reachable from the first hall. Thus, he needs to go to those 4 halls one by one and return. Gerald will enter the first of those halls in a minute, in the second one β in three minutes, in the third one - in 5 minutes, in the fourth one - in 7 minutes. The average time is 4 minutes. | [] | 124 | 0 | 0 | 58,304 |
986 | Petr and Permutations | [
"combinatorics",
"math"
] | null | null | Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements $7n+1$ times instead of $3n$ times. Because it is more random, OK?!
You somehow get a test from one of these problems and now you want to know from which one. | In the first line of input there is one integer $n$ ($10^{3} \le n \le 10^{6}$).
In the second line there are $n$ distinct integers between $1$ and $n$Β β the permutation of size $n$ from the test.
It is guaranteed that all tests except for sample are generated this way: First we choose $n$Β β the size of the permutation. Then we randomly choose a method to generate a permutationΒ β the one of Petr or the one of Alex. Then we generate a permutation using chosen method. | If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes). | [
"5\n2 4 5 1 3\n"
] | [
"Petr\n"
] | Please note that the sample is not a valid test (because of limitations for $n$) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.
Due to randomness of input hacks in this problem are forbidden. | [
{
"input": "5\n2 4 5 1 3",
"output": "Petr"
}
] | 217 | 22,323,200 | -1 | 58,499 |
|
778 | Peterson Polyglot | [
"brute force",
"dfs and similar",
"dsu",
"hashing",
"strings",
"trees"
] | null | null | Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters.
Peterson makes new language every morning. It is difficult task to store the whole language, so Peterson have invented new data structure for storing his languages which is called broom. Broom is rooted tree with edges marked with letters. Initially broom is represented by the only vertexΒ β the root of the broom. When Peterson wants to add new word to the language he stands at the root and processes the letters of new word one by one. Consider that Peterson stands at the vertex *u*. If there is an edge from *u* marked with current letter, Peterson goes through this edge. Otherwise Peterson adds new edge from *u* to the new vertex *v*, marks it with the current letter and goes through the new edge. Size of broom is the number of vertices in it.
In the evening after working day Peterson can't understand the language he made this morning. It is too difficult for bored Peterson and he tries to make it simpler. Simplification of the language is the process of erasing some letters from some words of this language. Formally, Peterson takes some positive integer *p* and erases *p*-th letter from all the words of this language having length at least *p*. Letters in words are indexed starting by 1. Peterson considers that simplification should change at least one word, i.e. there has to be at least one word of length at least *p*. Peterson tries to make his language as simple as possible, so he wants to choose *p* such that the size of the broom for his simplified language is as small as possible.
Peterson is pretty annoyed with this task so he asks you for help. Write a program to find the smallest possible size of the broom and integer *p*. | The first line of input contains integer *n* (2<=β€<=*n*<=β€<=3Β·105)Β β the size of the broom.
Next *n*<=-<=1 lines describe the broom: *i*-th of them contains integers *u**i*, *v**i* and letter *x**i*Β β describing the edge from *u**i* to *v**i* marked with letter *x**i*.
Vertices are numbered from 1 to *n*. All *x**i* are lowercase latin letters. Vertex 1 is the root of the broom.
Edges describe correct broom which is made from Peterson's language. | The first line of output should contain the minimum possible size of the broom after its simplification. The second line of output should contain integer *p* to choose. If there are several suitable *p* values, print the smallest one. | [
"5\n1 2 c\n2 3 a\n3 4 t\n2 5 t\n",
"16\n1 2 o\n2 3 f\n1 4 p\n4 5 i\n5 6 e\n6 7 c\n7 8 e\n4 9 r\n9 10 e\n10 11 t\n11 12 t\n12 13 y\n10 14 f\n14 15 i\n15 16 x\n"
] | [
"3\n2\n",
"12\n2\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/4b46644a485274790bd64830c23320ae20be3097.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Broom from the second sample test can be built using language "piece", "of", "pie", "pretty", "prefix". Its simplification with *p*β=β2 obtains the language of words "pece", "o", "pe", "petty", "pefix". This language gives us the broom with minimum possible size. | [
{
"input": "5\n1 2 c\n2 3 a\n3 4 t\n2 5 t",
"output": "3\n2"
},
{
"input": "16\n1 2 o\n2 3 f\n1 4 p\n4 5 i\n5 6 e\n6 7 c\n7 8 e\n4 9 r\n9 10 e\n10 11 t\n11 12 t\n12 13 y\n10 14 f\n14 15 i\n15 16 x",
"output": "12\n2"
},
{
"input": "2\n1 2 o",
"output": "1\n1"
},
{
"input": "3\n2 3 w\n1 2 o",
"output": "2\n1"
},
{
"input": "3\n1 3 g\n1 2 o",
"output": "1\n1"
},
{
"input": "5\n1 2 s\n1 5 p\n5 4 w\n2 3 a",
"output": "3\n1"
},
{
"input": "5\n1 2 m\n1 4 v\n4 5 x\n2 3 x",
"output": "2\n1"
}
] | 4,000 | 24,780,800 | 0 | 58,552 |
|
0 | none | [
"none"
] | null | null | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than *k* characters, it will be very suspicious.
Find the least number of distinct characters that can remain in the string after no more than *k* characters are deleted. You also have to find any possible way to delete the characters. | The first input data line contains a string whose length is equal to *n* (1<=β€<=*n*<=β€<=105). The string consists of lowercase Latin letters. The second line contains the number *k* (0<=β€<=*k*<=β€<=105). | Print on the first line the only number *m* β the least possible number of different characters that could remain in the given string after it loses no more than *k* characters.
Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly *m* distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly *m* distinct characters, print any of them. | [
"aaaaa\n4\n",
"abacaba\n4\n",
"abcdefgh\n10\n"
] | [
"1\naaaaa\n",
"1\naaaa\n",
"0\n\n"
] | In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.
In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.
In the third sample you are given a line whose length is equal to 8, and *k*β=β10, so that the whole line can be deleted. The correct answer is 0 and an empty string. | [
{
"input": "aaaaa\n4",
"output": "1\naaaaa"
},
{
"input": "abacaba\n4",
"output": "1\naaaa"
},
{
"input": "abcdefgh\n10",
"output": "0"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa\n19",
"output": "1\naaaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdefghijjihgedcba\n0",
"output": "10\nabcdefghijjihgedcba"
},
{
"input": "aababcabcdabcde\n9",
"output": "2\naabababab"
},
{
"input": "xyzuvwxyz\n4",
"output": "3\nxyzxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n99",
"output": "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n0",
"output": "1\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n17",
"output": "9\nrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n0",
"output": "26\nabcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrsttsrqponmlkjihgfedcba\n0",
"output": "20\nabcdefghijklmnopqrsttsrqponmlkjihgfedcba"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeeeeee\n20",
"output": "1\naaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xyxjvqrbehasypiekxwjhurlrnegtkiplbogkgxwubzhlyvjwj\n24",
"output": "8\nxyxjrhykxwjhrlrklkxwhlyjwj"
},
{
"input": "clpdaxnimfkubdxtpjwtjkqh\n21",
"output": "2\nxxtt"
},
{
"input": "jeliuewohkqtghdneuuhcputwiddnmkbhhnlxxbfjunhcd\n50",
"output": "0"
},
{
"input": "zgwmpjfeiwtfagp\n62",
"output": "0"
},
{
"input": "halasouqgfxfcrwhqgllaqiphaxekljz\n87",
"output": "0"
},
{
"input": "zimxucbrzojfqvizcopkplrpnvihveqpgvzszkubftoozrydxijokjxfhdfjracjonqupmnhadtsotxrxmwgno\n51",
"output": "7\nzxrzojvzopprpvvpvzzoozrxjojxjrjopoxrxo"
},
{
"input": "geovcaxzjyhxbpnbkbsxfpkyofopxquzzxeigdflfumisevzsjdywehxconimkkbvjyxbqlnmaphvnngcjqoefqkfzmiruubbcmv\n24",
"output": "16\neovxzjyxbpnbkbxfpkyofopxquzzxeiffumievzjyexonimkkbvjyxbqnmpvnnjqoefqkfzmiuubbmv"
},
{
"input": "jsreqtehsewsiwzqbpniwuhbgcrrkxlgbhuobphjigfuinffvvatrcxnzbcxjazrrxyiwxncuiifzndpvqahwpdfo\n67",
"output": "4\nrwiwiwrrxiirxxrrxiwxiiw"
},
{
"input": "uwvkcydkhbmbqyfjuryqnxcxhoanwnjubuvpgfipdeserodhh\n65",
"output": "0"
},
{
"input": "xclfxmeqhfjwurwmazpysafoxepb\n26",
"output": "1\nxxx"
},
{
"input": "hlhugwawagrnpojcmzfiqtffrzuqfovcmxnfqukgzxilglfbtsqgtsweblymqrdskcxjtuytodzujgtivkmiktvskvoqpegoiw\n27",
"output": "15\nlugwwgomzfiqtffzuqfovmxfqukgzxilglftsqgtswlmqskxtutozugtivkmiktvskvoqgoiw"
},
{
"input": "cky\n79",
"output": "0"
},
{
"input": "oodcvb\n16",
"output": "0"
},
{
"input": "lfbfwdoeggorzdsxqnpophbcjcatphjsewamrgzjszf\n20",
"output": "8\nffwoggozspopjpjswgzjszf"
},
{
"input": "ksnizygvqy\n42",
"output": "0"
},
{
"input": "myenljgyxkwcfyzjcpffsucstschcevbzh\n44",
"output": "0"
},
{
"input": "yumufcicodkpuhvifnvi\n36",
"output": "0"
},
{
"input": "fntrmjfquczybyjllywsqwllsxdmqynmyfcqhakftitvvfbxtqktbfsvvvanjbkqubyxu\n63",
"output": "1\nyyyyyy"
},
{
"input": "smiclwubkoobnapkkletsnbbsvihqbvikochzteaewjonkzvsqrbjkywsfcvczwretmhscowapcraof\n45",
"output": "6\nscwbkoobkksbbsbkocwoksbkwsccwscowco"
},
{
"input": "lwkjydpagifuvbhifryskegmzuexfksazfurlsnzfrgvuxcazitfchimmvomdnbdirzccstmuvlpghwskinayvucodiwn\n16",
"output": "17\nlwkydagifuvifryskgmzufksazfurlsnzfrgvucazifcimmvmdndirzccsmuvlgwskinayvucdiwn"
},
{
"input": "a\n0",
"output": "1\na"
},
{
"input": "bbb\n100000",
"output": "0"
},
{
"input": "aa\n2",
"output": "0"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "aaaa\n4",
"output": "0"
}
] | 404 | 512,000 | 3 | 58,553 |
|
149 | Coloring Brackets | [
"dp"
] | null | null | Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.
You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a correct mathematical expression from it, inserting numbers and operators between the brackets. For example, such sequences as "(())()" and "()" are correct bracket sequences and such sequences as ")()" and "(()" are not.
In a correct bracket sequence each bracket corresponds to the matching bracket (an opening bracket corresponds to the matching closing bracket and vice versa). For example, in a bracket sequence shown of the figure below, the third bracket corresponds to the matching sixth one and the fifth bracket corresponds to the fourth one.
You are allowed to color some brackets in the bracket sequence so as all three conditions are fulfilled:
- Each bracket is either not colored any color, or is colored red, or is colored blue. - For any pair of matching brackets exactly one of them is colored. In other words, for any bracket the following is true: either it or the matching bracket that corresponds to it is colored. - No two neighboring colored brackets have the same color.
Find the number of different ways to color the bracket sequence. The ways should meet the above-given conditions. Two ways of coloring are considered different if they differ in the color of at least one bracket. As the result can be quite large, print it modulo 1000000007 (109<=+<=7). | The first line contains the single string *s* (2<=β€<=|*s*|<=β€<=700) which represents a correct bracket sequence. | Print the only number β the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109<=+<=7). | [
"(())\n",
"(()())\n",
"()\n"
] | [
"12\n",
"40\n",
"4\n"
] | Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below.
The two ways of coloring shown below are incorrect. | [
{
"input": "(())",
"output": "12"
},
{
"input": "(()())",
"output": "40"
},
{
"input": "()",
"output": "4"
},
{
"input": "((()))",
"output": "36"
},
{
"input": "()(())",
"output": "42"
},
{
"input": "()()()",
"output": "48"
},
{
"input": "(())(())",
"output": "126"
},
{
"input": "()()()()()()()()()()()(())",
"output": "9085632"
},
{
"input": "()(())()((()))",
"output": "4428"
},
{
"input": "()()(())()(())",
"output": "5040"
},
{
"input": "()()()()()()()()()()()()()()()()",
"output": "411525376"
},
{
"input": "(()()())",
"output": "136"
},
{
"input": "()(()())()",
"output": "480"
},
{
"input": "(())()(())()",
"output": "1476"
},
{
"input": "()()(()())(())()()()",
"output": "195840"
},
{
"input": "()()()((((())))())()()()()()((()))()()(())()(((())))()(()())((())())((()())(((((()()()())()()())))))",
"output": "932124942"
},
{
"input": "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))",
"output": "90824888"
},
{
"input": "((()))((())())((()()))()(())(()())(())()()()((()(((()())))()())()((((()((()((())))(())(()(())())))((()())()()()((())()))()(())(())))()(((((()())))))))",
"output": "100627207"
},
{
"input": "()(((()((((()())))())(())(((((()(()()))))()()))((())))()())((())))(())()((()())())()(()(()())())(()())()(()(((((()))()((()()(())()(())(()((()((()))))()(())()()(()()()((((()())()))))()(((()(((((()()((((())(())))()())(()))(((())((()())(()))())(((()()()(()(())())())(()()()))))())))()((()(()()(()))())((())(()()()(())()))()()(((())))((()))(()((()(((()))((((()())))())(((())()(()((())))))))))))))))))))))",
"output": "306199947"
},
{
"input": "(())(((((()()()()())(())))(()()((()(()(((((())(()())))())(()()(()((())()(()()))))))(())()())))()((()()())))()()(()(())())()())()(())(((((()(()()(((()())()))((())((((()()()))())(((())(((())))))))))))))",
"output": "270087235"
},
{
"input": "()()()((()))(())(((())()(())(())))()()(((()((()()()))(()()(())(())))(()()((()((())(()()(()(())))))))(((())()((((()())))()(((()()())))()))()())))()(()(()())((()((()))))())(((((()())()((((()))(((((()())()))(((()()()((((((()()(())(()))((()(()(()((()((((()(((()(()()(()()((((()))()()()(()((((()(((())(((()()()(())()))((()()()(()))))())()))))(((((((()))())))(((()(()())(())))())))((((())(())())(((()()()))((()()))())(()))(())((()(()))(()()((()(()((()(())(()))()()))))))))))))))))))))))))))))))))))))))))))",
"output": "461776571"
},
{
"input": "()()(((((()((()(())()(()))(()(()(()(()(())(())(())(()(()((())))()))())((()((()(()(((()(()))()(()())(()()()()(((((()(((()))((((())())(((()((((()((((((())())))()))))))))(())())))(((()((()))))((())(()()))()(()(()((()())())()))))((()))))()((())())(()())()())))())())())())()((()((())((()()())()())())()(())()))(()(()))())))(()()()())()())))))))((((()())))((((()()()))())((()(())))))()((()(((())()()()(()()()()()))))(((()())()))()()(((())(()())(()()))))))",
"output": "66338682"
},
{
"input": "(()())()()()((((()(()()(())()((())(((()((()()(()))()))()()))))()(()(())(()))))))",
"output": "639345575"
},
{
"input": "()((()))((((()((())((()()((((()))()()((())((()(((((()(()))((())()))((((())()(()(()))()))))))))))))))))))",
"output": "391997323"
},
{
"input": "(((((()())))))()()()()()(())()()()((()()))()()()()()(((()(())))())(((()())))",
"output": "422789312"
},
{
"input": "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()",
"output": "140121189"
},
{
"input": "()()",
"output": "14"
}
] | 310 | 4,300,800 | 3 | 58,728 |
|
420 | Bug in Code | [
"data structures",
"graphs",
"implementation",
"two pointers"
] | null | null | Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the *n* coders on the meeting said: 'I know for sure that either *x* or *y* did it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least *p* of *n* coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting. | The first line contains integers *n* and *p* (3<=β€<=*n*<=β€<=3Β·105;Β 0<=β€<=*p*<=β€<=*n*) β the number of coders in the F company and the minimum number of agreed people.
Each of the next *n* lines contains two integers *x**i*, *y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*) β the numbers of coders named by the *i*-th coder. It is guaranteed that *x**i*<=β <=*i*,<=Β *y**i*<=β <=*i*,<=Β *x**i*<=β <=*y**i*. | Print a single integer ββ the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1,<=2) ΠΈ (2,<=1) are considered identical. | [
"4 2\n2 3\n1 4\n1 4\n2 1\n",
"8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4\n"
] | [
"6\n",
"1\n"
] | none | [
{
"input": "4 2\n2 3\n1 4\n1 4\n2 1",
"output": "6"
},
{
"input": "8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4",
"output": "1"
},
{
"input": "3 2\n2 3\n3 1\n2 1",
"output": "3"
},
{
"input": "4 1\n3 2\n4 1\n4 2\n1 2",
"output": "6"
},
{
"input": "4 2\n3 4\n4 3\n4 2\n3 1",
"output": "6"
},
{
"input": "4 3\n3 2\n4 3\n2 4\n3 2",
"output": "5"
},
{
"input": "4 4\n2 3\n3 4\n2 4\n2 1",
"output": "2"
},
{
"input": "5 1\n4 2\n4 5\n5 1\n5 1\n4 2",
"output": "10"
},
{
"input": "5 2\n4 3\n1 3\n4 2\n1 2\n1 4",
"output": "10"
},
{
"input": "5 3\n5 3\n5 1\n2 1\n5 3\n1 4",
"output": "9"
},
{
"input": "5 5\n3 2\n3 4\n2 5\n3 2\n4 3",
"output": "3"
},
{
"input": "10 1\n4 9\n8 9\n7 6\n1 5\n3 6\n4 3\n4 6\n10 1\n1 8\n7 9",
"output": "45"
},
{
"input": "10 2\n10 2\n9 3\n9 4\n7 2\n4 6\n10 1\n9 2\n3 10\n7 1\n5 1",
"output": "43"
},
{
"input": "10 3\n6 3\n6 10\n2 5\n5 7\n6 2\n9 2\n8 1\n10 5\n5 10\n7 6",
"output": "34"
},
{
"input": "10 4\n8 7\n1 5\n7 4\n7 8\n3 2\n10 8\n3 6\n9 7\n8 7\n4 1",
"output": "19"
},
{
"input": "8 8\n6 5\n1 6\n1 6\n1 6\n1 6\n1 2\n1 3\n6 4",
"output": "1"
},
{
"input": "5 5\n3 2\n3 4\n1 2\n1 2\n1 2",
"output": "3"
},
{
"input": "8 7\n7 8\n7 8\n1 6\n1 6\n1 2\n1 3\n6 4\n6 5",
"output": "0"
},
{
"input": "6 5\n5 6\n5 6\n5 6\n5 6\n1 2\n3 4",
"output": "8"
},
{
"input": "10 10\n5 6\n1 4\n1 4\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 4",
"output": "2"
},
{
"input": "6 4\n2 3\n3 1\n1 2\n5 6\n6 4\n4 5",
"output": "9"
},
{
"input": "5 5\n4 5\n4 5\n4 5\n1 2\n1 2",
"output": "4"
},
{
"input": "5 3\n3 4\n3 4\n1 2\n1 2\n1 2",
"output": "7"
},
{
"input": "4 4\n3 4\n3 4\n1 2\n1 2",
"output": "4"
},
{
"input": "4 4\n3 4\n4 3\n1 2\n2 1",
"output": "4"
},
{
"input": "4 3\n3 4\n3 4\n1 2\n1 2",
"output": "4"
},
{
"input": "8 5\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4",
"output": "5"
},
{
"input": "6 6\n5 6\n5 6\n5 6\n1 2\n1 3\n3 4",
"output": "0"
},
{
"input": "4 4\n2 3\n4 3\n2 1\n2 3",
"output": "3"
}
] | 1,000 | 54,681,600 | 0 | 58,891 |
|
961 | Partitions | [
"combinatorics",
"math",
"number theory"
] | null | null | You are given a set of *n* elements indexed from 1 to *n*. The weight of *i*-th element is *w**i*. The weight of some subset of a given set is denoted as . The weight of some partition *R* of a given set into *k* subsets is (recall that a partition of a given set is a set of its subsets such that every element of the given set belongs to exactly one subset in partition).
Calculate the sum of weights of all partitions of a given set into exactly *k* non-empty subsets, and print it modulo 109<=+<=7. Two partitions are considered different iff there exist two elements *x* and *y* such that they belong to the same set in one of the partitions, and to different sets in another partition. | The first line contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=2Β·105) β the number of elements and the number of subsets in each partition, respectively.
The second line contains *n* integers *w**i* (1<=β€<=*w**i*<=β€<=109)β weights of elements of the set. | Print one integer β the sum of weights of all partitions of a given set into *k* non-empty subsets, taken modulo 109<=+<=7. | [
"4 2\n2 3 2 3\n",
"5 2\n1 2 3 4 5\n"
] | [
"160\n",
"645\n"
] | Possible partitions in the first sample:
1. {{1,β2,β3},β{4}}, *W*(*R*)β=β3Β·(*w*<sub class="lower-index">1</sub>β+β*w*<sub class="lower-index">2</sub>β+β*w*<sub class="lower-index">3</sub>)β+β1Β·*w*<sub class="lower-index">4</sub>β=β24; 1. {{1,β2,β4},β{3}}, *W*(*R*)β=β26; 1. {{1,β3,β4},β{2}}, *W*(*R*)β=β24; 1. {{1,β2},β{3,β4}}, *W*(*R*)β=β2Β·(*w*<sub class="lower-index">1</sub>β+β*w*<sub class="lower-index">2</sub>)β+β2Β·(*w*<sub class="lower-index">3</sub>β+β*w*<sub class="lower-index">4</sub>)β=β20; 1. {{1,β3},β{2,β4}}, *W*(*R*)β=β20; 1. {{1,β4},β{2,β3}}, *W*(*R*)β=β20; 1. {{1},β{2,β3,β4}}, *W*(*R*)β=β26;
Possible partitions in the second sample:
1. {{1,β2,β3,β4},β{5}}, *W*(*R*)β=β45; 1. {{1,β2,β3,β5},β{4}}, *W*(*R*)β=β48; 1. {{1,β2,β4,β5},β{3}}, *W*(*R*)β=β51; 1. {{1,β3,β4,β5},β{2}}, *W*(*R*)β=β54; 1. {{2,β3,β4,β5},β{1}}, *W*(*R*)β=β57; 1. {{1,β2,β3},β{4,β5}}, *W*(*R*)β=β36; 1. {{1,β2,β4},β{3,β5}}, *W*(*R*)β=β37; 1. {{1,β2,β5},β{3,β4}}, *W*(*R*)β=β38; 1. {{1,β3,β4},β{2,β5}}, *W*(*R*)β=β38; 1. {{1,β3,β5},β{2,β4}}, *W*(*R*)β=β39; 1. {{1,β4,β5},β{2,β3}}, *W*(*R*)β=β40; 1. {{2,β3,β4},β{1,β5}}, *W*(*R*)β=β39; 1. {{2,β3,β5},β{1,β4}}, *W*(*R*)β=β40; 1. {{2,β4,β5},β{1,β3}}, *W*(*R*)β=β41; 1. {{3,β4,β5},β{1,β2}}, *W*(*R*)β=β42. | [
{
"input": "4 2\n2 3 2 3",
"output": "160"
},
{
"input": "5 2\n1 2 3 4 5",
"output": "645"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "2 1\n6042 8885",
"output": "29854"
},
{
"input": "2 2\n8224 8138",
"output": "16362"
},
{
"input": "3 1\n2403 4573 3678",
"output": "31962"
},
{
"input": "3 2\n1880 3827 5158",
"output": "54325"
},
{
"input": "3 3\n4062 8888 5423",
"output": "18373"
},
{
"input": "4 1\n1867 5670 374 4815",
"output": "50904"
},
{
"input": "4 2\n4049 2220 6447 3695",
"output": "262576"
},
{
"input": "4 3\n3526 1473 9416 2974",
"output": "156501"
},
{
"input": "4 4\n9900 6535 5489 1853",
"output": "23777"
},
{
"input": "5 1\n6740 1359 1663 8074 5686",
"output": "117610"
},
{
"input": "5 2\n3113 612 440 2761 6970",
"output": "597528"
},
{
"input": "5 3\n9887 7162 3409 8937 3662",
"output": "1619793"
},
{
"input": "5 4\n9364 2224 2185 920 7650",
"output": "312802"
},
{
"input": "5 5\n1546 1477 962 7095 8934",
"output": "20014"
},
{
"input": "6 1\n3100 7048 8360 9845 7229 5331",
"output": "245478"
},
{
"input": "6 2\n2578 6301 8624 6020 8513 9486",
"output": "4401332"
},
{
"input": "6 3\n4759 5555 7401 8003 2501 6345",
"output": "7431260"
},
{
"input": "6 4\n8429 7912 6178 6883 9193 501",
"output": "4496040"
},
{
"input": "6 5\n7906 9870 6443 6162 477 4656",
"output": "710280"
},
{
"input": "6 6\n7384 9123 5220 849 7169 1516",
"output": "31261"
}
] | 280 | 36,761,600 | 0 | 59,146 |
|
870 | Paths | [
"data structures",
"number theory"
] | null | null | You are given a positive integer *n*. Let's build a graph on vertices 1,<=2,<=...,<=*n* in such a way that there is an edge between vertices *u* and *v* if and only if . Let *d*(*u*,<=*v*) be the shortest distance between *u* and *v*, or 0 if there is no path between them. Compute the sum of values *d*(*u*,<=*v*) over all 1<=β€<=*u*<=<<=*v*<=β€<=*n*.
The *gcd* (greatest common divisor) of two positive integers is the maximum positive integer that divides both of the integers. | Single integer *n* (1<=β€<=*n*<=β€<=107). | Print the sum of *d*(*u*,<=*v*) over all 1<=β€<=*u*<=<<=*v*<=β€<=*n*. | [
"6\n",
"10\n"
] | [
"8\n",
"44\n"
] | All shortest paths in the first example:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7b7a110945393c2b47718b811aadf12cbe125f3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e9af98cb64a31b6dae850dbfb30429b9a091c123.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d43a3ea9a040a07b650cc4d74a5f6a69395d0005.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1725357f3b9d9284226b8c2848aab916720da24f.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9e05d0e132bba9db531dc61149062e6f9f5ff34a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/043fdd1108540c9fbac49c9177d6ec0021cbd896.png" style="max-width: 100.0%;max-height: 100.0%;"/>
There are no paths between other pairs of vertices.
The total distance is 2β+β1β+β1β+β2β+β1β+β1β=β8. | [] | 31 | 0 | 0 | 59,219 |
|
1,010 | Store | [
"data structures"
] | null | null | Natasha was already going to fly back to Earth when she remembered that she needs to go to the Martian store to buy Martian souvenirs for her friends.
It is known, that the Martian year lasts $x_{max}$ months, month lasts $y_{max}$ days, day lasts $z_{max}$ seconds. Natasha also knows that this store works according to the following schedule: 2 months in a year were selected: $x_l$ and $x_r$ ($1\le x_l\le x_r\le x_{max}$), 2 days in a month: $y_l$ and $y_r$ ($1\le y_l\le y_r\le y_{max}$) and 2 seconds in a day: $z_l$ and $z_r$ ($1\le z_l\le z_r\le z_{max}$). The store works at all such moments (month $x$, day $y$, second $z$), when simultaneously $x_l\le x\le x_r$, $y_l\le y\le y_r$ and $z_l\le z\le z_r$.
Unfortunately, Natasha does not know the numbers $x_l,x_r,y_l,y_r,z_l,z_r$.
One Martian told Natasha: "I went to this store $(n+m)$ times. $n$ times of them it was opened, and $m$ timesΒ β closed." He also described his every trip to the store: the month, day, second of the trip and whether the store was open or closed at that moment.
Natasha can go to the store $k$ times. For each of them, determine whether the store at the time of the trip is open, closed, or this information is unknown. | The first line contains $6$ integers $x_{max}$, $y_{max}$, $z_{max}$, $n$, $m$, $k$ ($1\le x_{max},y_{max},z_{max}\le 10^5$, $1\le n\le 10^5$, $0\le m\le 10^5$, $1\le k\le 10^5$)Β β number of months in a year, days in a month, seconds in a day, times when the store (according to a Martian) was opened, when it was closed and Natasha's queries.
The $i$-th of the next $n$ lines contains $3$ integers $x_i$, $y_i$, $z_i$ ($1\le x_i\le x_{max}$, $1\le y_i\le y_{max}$, $1\le z_i\le z_{max}$)Β β month, day and second of $i$-th time, when the store, according to the Martian, was opened.
The $i$-th of the next $m$ lines contains $3$ integers $x_i$, $y_i$, $z_i$ ($1\le x_i\le x_{max}$, $1\le y_i\le y_{max}$, $1\le z_i\le z_{max}$)Β β month, day and second of $i$-th time, when the store, according to the Martian, was closed.
The $i$-th of the next $k$ lines contains $3$ integers $x_i$, $y_i$, $z_i$ ($1\le x_i\le x_{max}$, $1\le y_i\le y_{max}$, $1\le z_i\le z_{max}$)Β β month, day and second of $i$-th Natasha's query. | If the Martian was mistaken and his information about when the store is open and when it is closed is inconsistent, print a single line "INCORRECT" (without quotes).
Otherwise, print the first line "CORRECT" (without quotes). Next output $k$ lines: in $i$-th of them, output an answer to $i$-th Natasha's query: "OPEN" (without quotes), if the store was opened at the moment of this query, "CLOSED" (without quotes), if it was closed, or "UNKNOWN" (without quotes), if this information can not be determined on the basis of available data. | [
"10 10 10 3 1 3\n2 6 2\n4 2 4\n6 4 6\n9 9 9\n3 3 3\n10 10 10\n8 8 8\n",
"10 10 10 1 1 1\n2 5 7\n2 5 7\n8 9 10\n"
] | [
"CORRECT\nOPEN\nCLOSED\nUNKNOWN\n",
"INCORRECT\n"
] | Consider the first test case.
There are $10$ months in a year, $10$ days in a month, and $10$ seconds in a day.
The store was opened in $3$ moments:
- month $2$, day $6$, second $2$;- month $4$, day $2$, second $4$;- month $6$, day $4$, second $6$.
The store was closed at the time: month $9$, day $9$, second $9$.
Queries:
- month $3$, day $3$, second $3$Β β open ("OPEN") (since the store opens no later than month $2$, day $2$, second $2$ and closes no earlier than in month $6$, day $6$, second $6$); - month $10$, day $10$, second $10$Β β closed ("CLOSED") (since it is closed even in the month $9$, day $9$, second $9$);- month $8$, day $8$, second $8$Β β unknown ("UNKNOWN") (because the schedule in which the store is open at this moment exists, and the schedule in which the store is closed at this moment exists as well).
In the second test case, the store was closed and opened at the same timeΒ β contradiction ("INCORRECT"). | [] | 108 | 0 | 0 | 59,302 |
|
630 | A rectangle | [
"math"
] | null | null | Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.
More formally, if a game designer selected cells having coordinates (*x*1,<=*y*1) and (*x*2,<=*y*2), where *x*1<=β€<=*x*2 and *y*1<=β€<=*y*2, then all cells having center coordinates (*x*,<=*y*) such that *x*1<=β€<=*x*<=β€<=*x*2 and *y*1<=β€<=*y*<=β€<=*y*2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to *OX* axis, all hexagon centers have integer coordinates and for each integer *x* there are cells having center with such *x* coordinate and for each integer *y* there are cells having center with such *y* coordinate. It is guaranteed that difference *x*2<=-<=*x*1 is divisible by 2.
Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.
Help him implement counting of these units before painting. | The only line of input contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=109<=β€<=*x*1<=β€<=*x*2<=β€<=109,<=<=-<=109<=β€<=*y*1<=β€<=*y*2<=β€<=109) β the coordinates of the centers of two cells. | Output one integer β the number of cells to be filled. | [
"1 1 5 5\n"
] | [
"13"
] | none | [
{
"input": "1 1 5 5",
"output": "13"
},
{
"input": "-1 -3 1 3",
"output": "11"
},
{
"input": "-2 -2 2 2",
"output": "13"
},
{
"input": "0 0 2 2",
"output": "5"
},
{
"input": "0 0 2 0",
"output": "2"
},
{
"input": "0 0 0 0",
"output": "1"
},
{
"input": "0 -2 0 2",
"output": "3"
},
{
"input": "-2 -2 -2 0",
"output": "2"
},
{
"input": "-1000000000 -1000000000 1000000000 1000000000",
"output": "2000000002000000001"
},
{
"input": "-999999999 -999999999 999999999 999999999",
"output": "1999999998000000001"
},
{
"input": "-999999999 -999999999 -1 -1",
"output": "499999999000000001"
},
{
"input": "-411495869 33834653 -234317741 925065545",
"output": "78953311064369599"
},
{
"input": "-946749893 -687257665 -539044455 -443568671",
"output": "49676664342971903"
},
{
"input": "-471257905 -685885153 782342299 909511043",
"output": "999994499807710193"
},
{
"input": "-26644507 -867720841 975594569 264730225",
"output": "567493356068872580"
},
{
"input": "-537640548 -254017710 62355638 588691834",
"output": "252811256874252458"
},
{
"input": "309857887 -687373065 663986893 403321751",
"output": "193123336242128360"
},
{
"input": "-482406510 -512306894 412844236 -168036050",
"output": "154104365578285608"
},
{
"input": "-330513944 -970064382 500608496 369852884",
"output": "556817654843544374"
},
{
"input": "-157778763 218978791 976692563 591093087",
"output": "211076500156631060"
},
{
"input": "1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1 0 5 6",
"output": "18"
},
{
"input": "-1 -4 1 4",
"output": "14"
},
{
"input": "-2 -3 2 3",
"output": "18"
},
{
"input": "0 -1 2 3",
"output": "8"
},
{
"input": "0 -1 2 1",
"output": "5"
},
{
"input": "0 -1 0 1",
"output": "2"
},
{
"input": "0 -3 0 3",
"output": "4"
},
{
"input": "-2 -3 -2 1",
"output": "3"
},
{
"input": "-1000000000 -999999999 1000000000 999999999",
"output": "2000000000000000000"
},
{
"input": "-999999999 -1000000000 999999999 1000000000",
"output": "2000000000000000000"
},
{
"input": "-999999999 -1000000000 -1 0",
"output": "500000000000000000"
},
{
"input": "-411495869 33834652 -234317741 925065546",
"output": "78953311241547728"
},
{
"input": "-946749893 -687257666 -539044455 -443568670",
"output": "49676664750677342"
},
{
"input": "-471257905 -685885154 782342299 909511044",
"output": "999994501061310398"
},
{
"input": "-26644507 -867720842 975594569 264730226",
"output": "567493357071111657"
},
{
"input": "-537640548 -254017711 62355638 588691835",
"output": "252811257474248645"
},
{
"input": "309857887 -687373066 663986893 403321752",
"output": "193123336596257367"
},
{
"input": "-482406510 -512306895 412844236 -168036049",
"output": "154104366473536355"
},
{
"input": "-330513944 -970064383 500608496 369852885",
"output": "556817655674666815"
},
{
"input": "-157778763 218978790 976692563 591093088",
"output": "211076501291102387"
},
{
"input": "1000000000 999999999 1000000000 999999999",
"output": "1"
}
] | 31 | 0 | 0 | 59,308 |
|
659 | Fence Divercity | [
"combinatorics",
"dp",
"number theory"
] | null | null | Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of *n* consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the *i*-th board to the left is *h**i*.
Today Vasily decided to change the design of the fence he had built, by cutting his top connected part so that the fence remained good. The cut part should consist of only the upper parts of the boards, while the adjacent parts must be interconnected (share a non-zero length before cutting out of the fence).
You, as Vasily's curious neighbor, will count the number of possible ways to cut exactly one part as is described above. Two ways to cut a part are called distinct, if for the remaining fences there is such *i*, that the height of the *i*-th boards vary.
As Vasily's fence can be very high and long, get the remainder after dividing the required number of ways by 1<=000<=000<=007 (109<=+<=7). | The first line contains integer *n* (1<=β€<=*n*<=β€<=1<=000<=000)Β β the number of boards in Vasily's fence.
The second line contains *n* space-separated numbers *h*1,<=*h*2,<=...,<=*h**n* (1<=β€<=*h**i*<=β€<=109), where *h**i* equals the height of the *i*-th board to the left. | Print the remainder after dividing *r* by 1<=000<=000<=007, where *r* is the number of ways to cut exactly one connected part so that the part consisted of the upper parts of the boards and the remaining fence was good. | [
"2\n1 1\n",
"3\n3 4 2\n"
] | [
"0\n",
"13\n"
] | From the fence from the first example it is impossible to cut exactly one piece so as the remaining fence was good.
All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part): | [
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 4 2",
"output": "13"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "999999999"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "2\n2 3",
"output": "4"
},
{
"input": "5\n1 4 2 1 1",
"output": "5"
},
{
"input": "15\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34",
"output": "944598823"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1",
"output": "391882076"
},
{
"input": "8\n1 870540358 821874877 223725489 367257956 1 105870869 267059674",
"output": "945207649"
},
{
"input": "5\n483078839 692549116 1 458438081 1",
"output": "723940136"
},
{
"input": "6\n1 1 423308752 1 1 1",
"output": "423308751"
},
{
"input": "7\n150616203 306436158 391126478 164096410 558820207 878798937 310121836",
"output": "650844459"
},
{
"input": "50\n1 3083990 976356336 922018335 1 170272482 1 547248035 1 1 1 1 1 928379588 1 1 1 270052499 315045369 1 1 556091215 1 655608230 424079072 1 1 185387009 77360256 1 1 942696777 228860271 1 487787709 1 437229749 167886535 1 1 904578415 319694007 1 313704390 1 1 957736320 771147030 458205965 497342117",
"output": "768215804"
},
{
"input": "96\n1 1 1 1 1 1 1 943302667 1 1 1 1 1 1 1 1 422145309 1 1 848134211 1 1 1 1 182511245 1 1 1 1 826044915 1 1 1 1 778749310 1 1 1 1 1 1 1 1 1 1 1 1 1 274149110 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291019191 1 1 1 1 1 1 1 1 1 1 1 532064146 1 1 1 1 1 1 772234680 1 1 1 1 1 1 1",
"output": "870354739"
}
] | 2,000 | 137,318,400 | 0 | 59,374 |
|
268 | Wall Bars | [
"dp"
] | null | null | Manao is working for a construction company. Recently, an order came to build wall bars in a children's park. Manao was commissioned to develop a plan of construction, which will enable the company to save the most money.
After reviewing the formal specifications for the wall bars, Manao discovered a number of controversial requirements and decided to treat them to the company's advantage. His resulting design can be described as follows:
- Let's introduce some unit of length. The construction center is a pole of height *n*. - At heights 1,<=2,<=...,<=*n* exactly one horizontal bar sticks out from the pole. Each bar sticks in one of four pre-fixed directions. - A child can move from one bar to another if the distance between them does not exceed *h* and they stick in the same direction. If a child is on the ground, he can climb onto any of the bars at height between 1 and *h*. In Manao's construction a child should be able to reach at least one of the bars at heights *n*<=-<=*h*<=+<=1,<=*n*<=-<=*h*<=+<=2,<=...,<=*n* if he begins at the ground.
Manao is wondering how many distinct construction designs that satisfy his requirements exist. As this number can be rather large, print the remainder after dividing it by 1000000009Β (109<=+<=9). Two designs are considered distinct if there is such height *i*, that the bars on the height *i* in these designs don't stick out in the same direction. | A single line contains two space-separated integers, *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=*min*(*n*,<=30)). | In a single line print the remainder after dividing the number of designs by 1000000009Β (109<=+<=9). | [
"5 1\n",
"4 2\n",
"4 3\n",
"5 2\n"
] | [
"4\n",
"148\n",
"256\n",
"376\n"
] | Consider several designs for *h*β=β2. A design with the first bar sticked out in direction *d*<sub class="lower-index">1</sub>, the second β in direction *d*<sub class="lower-index">2</sub> and so on (1ββ€β*d*<sub class="lower-index">*i*</sub>ββ€β4) is denoted as string *d*<sub class="lower-index">1</sub>*d*<sub class="lower-index">2</sub>...*d*<sub class="lower-index">*n*</sub>.
Design "1231" (the first three bars are sticked out in different directions, the last one β in the same as first). A child can reach neither the bar at height 3 nor the bar at height 4.
Design "414141". A child can reach the bar at height 5. To do this, he should first climb at the first bar, then at the third and then at the fifth one. He can also reach bar at height 6 by the route second βββ fourth βββ sixth bars.
Design "123333". The child can't reach the upper two bars.
Design "323323". The bar at height 6 can be reached by the following route: first βββ third βββ fourth βββ sixth bars. | [] | 60 | 0 | 0 | 59,411 |
|
460 | Little Victor and Set | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers *S* that has the following properties:
- for all *x* the following inequality holds *l*<=β€<=*x*<=β€<=*r*; - 1<=β€<=|*S*|<=β€<=*k*; - lets denote the *i*-th element of the set *S* as *s**i*; value must be as small as possible.
Help Victor find the described set. | The first line contains three space-separated integers *l*,<=*r*,<=*k* (1<=β€<=*l*<=β€<=*r*<=β€<=1012;Β 1<=β€<=*k*<=β€<=*min*(106,<=*r*<=-<=*l*<=+<=1)). | Print the minimum possible value of *f*(*S*). Then print the cardinality of set |*S*|. Then print the elements of the set in any order.
If there are multiple optimal sets, you can print any of them. | [
"8 15 3\n",
"8 30 7\n"
] | [
"1\n2\n10 11\n",
"0\n5\n14 9 28 11 16\n"
] | Operation <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b364f2e04c665b78b924ec10666327a4ef4635bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> represents the operation of bitwise exclusive OR. In other words, it is the XOR operation. | [
{
"input": "8 15 3",
"output": "1\n2\n10 11"
},
{
"input": "8 30 7",
"output": "0\n5\n14 9 28 11 16"
},
{
"input": "1 1 1",
"output": "1\n1\n1 "
},
{
"input": "3 987654321502 1",
"output": "3\n1\n3"
},
{
"input": "15603259690 63210239992 2",
"output": "1\n2\n15603259690 15603259691"
},
{
"input": "1023 9874156513 999999",
"output": "0\n4\n1024 1025 1026 1027"
},
{
"input": "262143 393216 3",
"output": "0\n3\n262143 393215 393216"
},
{
"input": "524287 786432 3",
"output": "0\n3\n524287 786431 786432"
},
{
"input": "10 1000000 100000",
"output": "0\n4\n10 11 12 13"
},
{
"input": "1 2 2",
"output": "1\n1\n1 "
},
{
"input": "1023 1024 2",
"output": "1023\n1\n1023 "
},
{
"input": "1023 1026 4",
"output": "1\n2\n1024 1025 "
},
{
"input": "1 1000000000000 1000000",
"output": "0\n4\n2 3 4 5"
},
{
"input": "3 6 4",
"output": "0\n3\n3 5 6 "
},
{
"input": "1 3 3",
"output": "0\n3\n1 2 3 "
},
{
"input": "2 1000000000 3",
"output": "0\n3\n3 5 6"
},
{
"input": "808290922549 808290922551 3",
"output": "1\n2\n808290922550 808290922551 "
},
{
"input": "3 6 3",
"output": "0\n3\n3 5 6 "
},
{
"input": "827528862516 827528862519 3",
"output": "1\n2\n827528862516 827528862517 "
},
{
"input": "1023 1536 3",
"output": "0\n3\n1023 1535 1536"
},
{
"input": "67108863 100663296 3",
"output": "0\n3\n67108863 100663295 100663296"
},
{
"input": "34359738367 51539607552 3",
"output": "0\n3\n34359738367 51539607551 51539607552"
},
{
"input": "549755813887 824633720832 3",
"output": "0\n3\n549755813887 824633720831 824633720832"
},
{
"input": "216252181447 527422131971 3",
"output": "0\n3\n274877906943 412316860415 412316860416"
},
{
"input": "2097152 12582911 3",
"output": "0\n3\n4194303 6291455 6291456"
},
{
"input": "25676809216 942956612465 3",
"output": "0\n3\n34359738367 51539607551 51539607552"
},
{
"input": "17179869183 103079215104 3",
"output": "0\n3\n17179869183 25769803775 25769803776"
},
{
"input": "1 1000000000000 3",
"output": "0\n3\n1 2 3"
},
{
"input": "274877906944 824633720831 3",
"output": "1\n2\n274877906944 274877906945"
},
{
"input": "137438953473 412316860414 3",
"output": "1\n2\n137438953474 137438953475"
},
{
"input": "4294967297 12884901887 3",
"output": "1\n2\n4294967298 4294967299"
},
{
"input": "788605408896 987573504326 3",
"output": "1\n2\n788605408896 788605408897"
},
{
"input": "1 1 1",
"output": "1\n1\n1 "
},
{
"input": "435074698045 435074698045 1",
"output": "435074698045\n1\n435074698045 "
},
{
"input": "842310243287 842310243288 1",
"output": "842310243287\n1\n842310243287 "
},
{
"input": "306146510877 306146510879 1",
"output": "306146510877\n1\n306146510877 "
},
{
"input": "176104075742 176104075745 1",
"output": "176104075742\n1\n176104075742 "
},
{
"input": "991450161441 991450161445 1",
"output": "991450161441\n1\n991450161441 "
},
{
"input": "628920636140 628920636145 1",
"output": "628920636140\n1\n628920636140"
},
{
"input": "462032569851 462032569852 2",
"output": "7\n2\n462032569851 462032569852 "
},
{
"input": "594093765558 594093765559 2",
"output": "1\n2\n594093765558 594093765559 "
},
{
"input": "280336416328 280336416330 2",
"output": "1\n2\n280336416328 280336416329 "
},
{
"input": "414141414141 414141414143 2",
"output": "1\n2\n414141414142 414141414143 "
},
{
"input": "727182873292 727182873295 2",
"output": "1\n2\n727182873292 727182873293 "
},
{
"input": "1 4 2",
"output": "1\n1\n1 "
},
{
"input": "495378827677 495378827681 2",
"output": "1\n2\n495378827678 495378827679 "
},
{
"input": "646762942896 646762942900 2",
"output": "1\n2\n646762942896 646762942897 "
},
{
"input": "459818793694 459818793699 2",
"output": "1\n2\n459818793694 459818793695"
},
{
"input": "258301936323 258301936328 2",
"output": "1\n2\n258301936324 258301936325"
},
{
"input": "549755813887 549755813888 2",
"output": "549755813887\n1\n549755813887 "
},
{
"input": "123452348785 123452348786 2",
"output": "3\n2\n123452348785 123452348786 "
},
{
"input": "34359738365 34359738368 4",
"output": "1\n2\n34359738366 34359738367 "
},
{
"input": "720858922694 720858922697 4",
"output": "0\n4\n720858922694 720858922695 720858922696 720858922697 "
},
{
"input": "287823578576 287823578579 4",
"output": "0\n4\n287823578576 287823578577 287823578578 287823578579 "
},
{
"input": "548222439830 548222439834 4",
"output": "0\n4\n548222439830 548222439831 548222439832 548222439833 "
},
{
"input": "884429359576 884429359580 4",
"output": "0\n4\n884429359576 884429359577 884429359578 884429359579 "
},
{
"input": "149740783265 149740783269 4",
"output": "0\n4\n149740783266 149740783267 149740783268 149740783269 "
},
{
"input": "3 7 4",
"output": "0\n3\n3 5 6 "
},
{
"input": "453615794657 453615794662 4",
"output": "0\n4\n453615794658 453615794659 453615794660 453615794661"
},
{
"input": "250479992247 250479992252 4",
"output": "0\n4\n250479992248 250479992249 250479992250 250479992251"
},
{
"input": "950041445904 950041447193 4",
"output": "0\n4\n950041445904 950041445905 950041445906 950041445907"
},
{
"input": "247946756425 247986106627 4",
"output": "0\n4\n247946756426 247946756427 247946756428 247946756429"
},
{
"input": "886657651282 989457651027 4",
"output": "0\n4\n886657651282 886657651283 886657651284 886657651285"
},
{
"input": "686725578739 886731078724 4",
"output": "0\n4\n686725578740 686725578741 686725578742 686725578743"
},
{
"input": "1 5 5",
"output": "0\n3\n1 2 3 "
},
{
"input": "9879456 324987645100 5",
"output": "0\n4\n9879456 9879457 9879458 9879459"
},
{
"input": "100000000000 900000000000 5",
"output": "0\n4\n100000000000 100000000001 100000000002 100000000003"
},
{
"input": "999999999996 1000000000000 5",
"output": "0\n4\n999999999996 999999999997 999999999998 999999999999 "
},
{
"input": "164985732640 164986732640 1000000",
"output": "0\n4\n164985732640 164985732641 164985732642 164985732643"
},
{
"input": "137765364256 267196143745 72414",
"output": "0\n4\n137765364256 137765364257 137765364258 137765364259"
},
{
"input": "424 518 34",
"output": "0\n4\n424 425 426 427"
},
{
"input": "93593884958 917491772445 660",
"output": "0\n4\n93593884958 93593884959 93593884960 93593884961"
},
{
"input": "846876302 846876302 1",
"output": "846876302\n1\n846876302 "
},
{
"input": "100000000000 1000000000000 3",
"output": "0\n3\n137438953471 206158430207 206158430208"
},
{
"input": "274877906944 549755813887 3",
"output": "1\n2\n274877906944 274877906945"
}
] | 61 | 2,867,200 | -1 | 59,497 |
|
314 | Sereja and Contest | [
"implementation"
] | null | null | During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants.
Let's assume that *n* people took part in the contest. Let's assume that the participant who got the first place has rating *a*1, the second place participant has rating *a*2, ..., the *n*-th place participant has rating *a**n*. Then changing the rating on the Codesecrof site is calculated by the formula .
After the round was over, the Codesecrof management published the participants' results table. They decided that if for a participant *d**i*<=<<=*k*, then the round can be considered unrated for him. But imagine the management's surprise when they found out that the participants' rating table is dynamic. In other words, when some participant is removed from the rating, he is removed from the results' table and the rating is recalculated according to the new table. And of course, all applications for exclusion from the rating are considered in view of the current table.
We know that among all the applications for exclusion from the rating the first application to consider is from the participant with the best rank (the rank with the minimum number), for who *d**i*<=<<=*k*. We also know that the applications for exclusion from rating were submitted by all participants.
Now Sereja wonders, what is the number of participants to be excluded from the contest rating, and the numbers of the participants in the original table in the order of their exclusion from the rating. Pay attention to the analysis of the first test case for a better understanding of the statement. | The first line contains two integers *n*, *k* (1<=β€<=*n*<=β€<=2Β·105,<=<=-<=109<=β€<=*k*<=β€<=0). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β ratings of the participants in the initial table. | Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table. | [
"5 0\n5 3 4 1 2\n",
"10 -10\n5 5 1 7 5 1 2 4 9 2\n"
] | [
"2\n3\n4\n",
"2\n4\n5\n7\n8\n9\n"
] | Consider the first test sample.
1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be considered first.1. As soon as the second place winner is out from the ratings, the participants' rating sequence will equal [5, 4, 1, 2]. By this sequence you can count the new sequence of rating changes: [0, -8, 2, 6]. According to the problem statement, the application of the participant who won the second place will be considered. Initially this participant won third place.1. The new rating sequence equals [5, 1, 2], the new sequence of rating changes equals [0, -1, 1]. The second place participant's application is taken into consideration, initially this participant won the fourth place.1. The new rating sequence equals [5, 2], the new sequence of rating changes equals [0, 0]. No more applications will be considered.
Thus, you should print 2, 3, 4. | [
{
"input": "5 0\n5 3 4 1 2",
"output": "2\n3\n4"
},
{
"input": "10 -10\n5 5 1 7 5 1 2 4 9 2",
"output": "2\n4\n5\n7\n8\n9"
}
] | 2,000 | 17,715,200 | 0 | 59,507 |
|
363 | Renting Bikes | [
"binary search",
"greedy"
] | null | null | A group of *n* schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.
The renting site offered them *m* bikes. The renting price is different for different bikes, renting the *j*-th bike costs *p**j* rubles.
In total, the boys' shared budget is *a* rubles. Besides, each of them has his own personal money, the *i*-th boy has *b**i* personal rubles. The shared budget can be spent on any schoolchildren arbitrarily, but each boy's personal money can be spent on renting only this boy's bike.
Each boy can rent at most one bike, one cannot give his bike to somebody else.
What maximum number of schoolboys will be able to ride bikes? What minimum sum of personal money will they have to spend in total to let as many schoolchildren ride bikes as possible? | The first line of the input contains three integers *n*, *m* and *a* (1<=β€<=*n*,<=*m*<=β€<=105; 0<=β€<=*a*<=β€<=109). The second line contains the sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=β€<=*b**i*<=β€<=104), where *b**i* is the amount of the *i*-th boy's personal money. The third line contains the sequence of integers *p*1,<=*p*2,<=...,<=*p**m* (1<=β€<=*p**j*<=β€<=109), where *p**j* is the price for renting the *j*-th bike. | Print two integers *r* and *s*, where *r* is the maximum number of schoolboys that can rent a bike and *s* is the minimum total personal money needed to rent *r* bikes. If the schoolchildren cannot rent any bikes, then *r*<==<=*s*<==<=0. | [
"2 2 10\n5 5\n7 6\n",
"4 5 2\n8 1 1 2\n6 3 7 5 2\n"
] | [
"2 3\n",
"3 8\n"
] | In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal money. This way of distribution of money minimizes the amount of spent personal money. | [
{
"input": "2 2 10\n5 5\n7 6",
"output": "2 3"
},
{
"input": "4 5 2\n8 1 1 2\n6 3 7 5 2",
"output": "3 8"
},
{
"input": "1 1 2\n1\n2",
"output": "1 0"
},
{
"input": "4 1 1\n3 2 3 2\n3",
"output": "1 2"
},
{
"input": "1 4 1\n3\n2 4 5 5",
"output": "1 1"
},
{
"input": "3 3 3\n1 1 2\n3 5 6",
"output": "1 0"
},
{
"input": "4 5 6\n5 1 7 2\n8 7 3 9 8",
"output": "3 12"
},
{
"input": "4 8 10\n2 1 2 2\n10 12 10 8 7 9 10 9",
"output": "1 0"
},
{
"input": "8 4 18\n9 4 2 2 7 5 1 1\n11 12 8 9",
"output": "4 22"
},
{
"input": "6 6 2\n6 1 5 3 10 1\n11 4 7 8 11 7",
"output": "3 16"
},
{
"input": "10 10 7\n6 7 15 1 3 1 14 6 7 4\n15 3 13 17 11 19 20 14 8 17",
"output": "5 42"
},
{
"input": "14 14 22\n23 1 3 16 23 1 7 5 18 7 3 6 17 8\n22 14 22 18 12 11 7 24 20 27 10 22 16 7",
"output": "10 115"
},
{
"input": "10 20 36\n12 4 7 18 4 4 2 7 4 10\n9 18 7 7 30 19 26 27 16 20 30 25 23 17 5 30 22 7 13 6",
"output": "10 69"
},
{
"input": "20 10 31\n17 27 2 6 11 12 5 3 12 4 2 10 4 8 2 10 7 9 12 1\n24 11 18 10 30 16 20 18 24 24",
"output": "7 86"
},
{
"input": "40 40 61\n28 59 8 27 45 67 33 32 61 3 42 2 3 37 8 8 10 61 1 5 65 28 34 27 8 35 45 49 31 49 13 23 23 53 20 48 14 74 16 6\n69 56 34 66 42 73 45 49 29 70 67 77 73 26 78 11 50 69 64 72 78 66 66 29 80 40 50 75 68 47 78 63 41 70 52 52 69 22 69 66",
"output": "22 939"
},
{
"input": "10 10 0\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1001 1001 1001 1001 1001 1001 1001 1001 1001 1001",
"output": "0 0"
},
{
"input": "9 8 0\n1 2 3 4 5 6 7 8 9\n2 3 4 5 6 7 8 9",
"output": "8 44"
},
{
"input": "9 8 0\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8",
"output": "8 36"
}
] | 30 | 0 | 0 | 59,560 |
|
733 | Drivers Dissatisfaction | [
"data structures",
"dsu",
"graphs",
"trees"
] | null | null | In one kingdom there are *n* cities and *m* two-way roads. Each road connects a pair of cities, and for each road we know the level of drivers dissatisfactionΒ β the value *w**i*.
For each road we know the value *c**i*Β β how many lamziks we should spend to reduce the level of dissatisfaction with this road by one. Thus, to reduce the dissatisfaction with the *i*-th road by *k*, we should spend *k*Β·*c**i* lamziks. And it is allowed for the dissatisfaction to become zero or even negative.
In accordance with the king's order, we need to choose *n*<=-<=1 roads and make them the main roads. An important condition must hold: it should be possible to travel from any city to any other by the main roads.
The road ministry has a budget of *S* lamziks for the reform. The ministry is going to spend this budget for repair of some roads (to reduce the dissatisfaction with them), and then to choose the *n*<=-<=1 main roads.
Help to spend the budget in such a way and then to choose the main roads so that the total dissatisfaction with the main roads will be as small as possible. The dissatisfaction with some roads can become negative. It is not necessary to spend whole budget *S*.
It is guaranteed that it is possible to travel from any city to any other using existing roads. Each road in the kingdom is a two-way road. | The first line contains two integers *n* and *m* (2<=β€<=*n*<=β€<=2Β·105, *n*<=-<=1<=β€<=*m*<=β€<=2Β·105)Β β the number of cities and the number of roads in the kingdom, respectively.
The second line contains *m* integers *w*1,<=*w*2,<=...,<=*w**m* (1<=β€<=*w**i*<=β€<=109), where *w**i* is the drivers dissatisfaction with the *i*-th road.
The third line contains *m* integers *c*1,<=*c*2,<=...,<=*c**m* (1<=β€<=*c**i*<=β€<=109), where *c**i* is the cost (in lamziks) of reducing the dissatisfaction with the *i*-th road by one.
The next *m* lines contain the description of the roads. The *i*-th of this lines contain a pair of integers *a**i* and *b**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*, *a**i*<=β <=*b**i*) which mean that the *i*-th road connects cities *a**i* and *b**i*. All roads are two-way oriented so it is possible to move by the *i*-th road from *a**i* to *b**i*, and vice versa. It is allowed that a pair of cities is connected by more than one road.
The last line contains one integer *S* (0<=β€<=*S*<=β€<=109)Β β the number of lamziks which we can spend for reforms. | In the first line print *K*Β β the minimum possible total dissatisfaction with main roads.
In each of the next *n*<=-<=1 lines print two integers *x*,<=*v**x*, which mean that the road *x* is among main roads and the road *x*, after the reform, has the level of dissatisfaction *v**x*.
Consider that roads are numbered from 1 to *m* in the order as they are given in the input data. The edges can be printed in arbitrary order. If there are several answers, print any of them. | [
"6 9\n1 3 1 1 3 1 2 2 2\n4 1 4 2 2 5 3 1 6\n1 2\n1 3\n2 3\n2 4\n2 5\n3 5\n3 6\n4 5\n5 6\n7\n",
"3 3\n9 5 1\n7 7 2\n2 1\n3 1\n3 2\n2\n"
] | [
"0\n1 1\n3 1\n6 1\n7 2\n8 -5\n",
"5\n3 0\n2 5\n"
] | none | [
{
"input": "6 9\n1 3 1 1 3 1 2 2 2\n4 1 4 2 2 5 3 1 6\n1 2\n1 3\n2 3\n2 4\n2 5\n3 5\n3 6\n4 5\n5 6\n7",
"output": "0\n1 1\n3 1\n6 1\n7 2\n8 -5"
},
{
"input": "3 3\n9 5 1\n7 7 2\n2 1\n3 1\n3 2\n2",
"output": "5\n3 0\n2 5"
},
{
"input": "7 6\n8 10 4 8 4 4\n45 51 13 13 37 26\n2 7\n7 1\n6 3\n3 1\n5 4\n1 4\n4",
"output": "38\n3 4\n5 4\n6 4\n1 8\n4 8\n2 10"
},
{
"input": "9 8\n2 8 2 10 2 2 5 8\n31 29 17 16 31 22 10 13\n5 2\n8 2\n7 3\n3 1\n6 8\n4 7\n1 2\n9 2\n69",
"output": "33\n1 2\n3 2\n5 2\n6 2\n7 -1\n2 8\n8 8\n4 10"
},
{
"input": "20 24\n197 80 213 112 390 387 286 280 307 200 334 337 330 178 354 231 134 14 6 297 12 341 248 115\n13 1 3 12 14 1 17 5 11 24 17 8 13 2 21 10 16 4 21 18 13 15 11 3\n1 18\n7 2\n11 2\n2 13\n12 3\n14 3\n7 4\n15 5\n7 6\n6 10\n18 6\n7 14\n8 18\n20 8\n11 9\n14 9\n9 18\n11 17\n15 14\n19 14\n16 15\n20 15\n19 16\n20 17\n19",
"output": "3701\n19 6\n21 12\n18 14\n2 61\n4 112\n24 115\n17 134\n14 178\n1 197\n10 200\n3 213\n16 231\n23 248\n8 280\n7 286\n9 307\n13 330\n6 387\n5 390"
},
{
"input": "10 10\n1 2 1 2 1 1 2 2 1 1\n3 3 2 2 2 2 2 2 1 2\n9 10\n1 7\n6 5\n4 10\n8 9\n2 6\n10 2\n3 8\n9 1\n5 3\n5",
"output": "7\n1 1\n3 1\n5 1\n6 1\n9 -4\n10 1\n2 2\n4 2\n7 2"
},
{
"input": "10 10\n2 1 1 1 2 2 2 1 1 1\n2 1 2 1 2 5 2 1 3 3\n1 3\n6 2\n9 7\n10 1\n4 5\n6 3\n3 6\n5 10\n2 9\n8 4\n1",
"output": "11\n2 0\n3 1\n4 1\n8 1\n9 1\n10 1\n1 2\n5 2\n6 2"
},
{
"input": "2 1\n6\n3\n1 2\n1000000000",
"output": "-333333327\n1 -333333327"
},
{
"input": "2 1\n1\n1\n1 2\n317856227",
"output": "-317856226\n1 -317856226"
},
{
"input": "2 1\n1\n1\n1 2\n1000000000",
"output": "-999999999\n1 -999999999"
},
{
"input": "2 1\n1000000000\n1000000000\n1 2\n1000000000",
"output": "999999999\n1 999999999"
},
{
"input": "5 4\n1 5 5 5\n1 5 5 5\n1 2\n2 3\n3 4\n4 5\n100",
"output": "-84\n1 -99\n2 5\n3 5\n4 5"
}
] | 78 | 0 | 0 | 59,604 |
|
35 | Warehouse | [
"implementation"
] | B. Warehouse | 2 | 64 | Once upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero DravDe worked. He couldnβt program or make up problems (in fact, few people saw a computer those days) but he was nevertheless happy. He worked in a warehouse where a magical but non-alcoholic drink Ogudar-Olok was kept. We wonβt describe his work in detail and take a better look at a simplified version of the warehouse.
The warehouse has one set of shelving. It has *n* shelves, each of which is divided into *m* sections. The shelves are numbered from top to bottom starting from 1 and the sections of each shelf are numbered from left to right also starting from 1. Each section can contain exactly one box of the drink, and try as he might, DravDe can never put a box in a section that already has one. In the course of his work DravDe frequently notices that he has to put a box in a filled section. In that case his solution is simple. DravDe ignores that section and looks at the next one to the right. If it is empty, he puts the box there. Otherwise he keeps looking for the first empty section to the right. If no empty section is found by the end of the shelf, he looks at the shelf which is under it, then the next one, etc. Also each time he looks at a new shelf he starts from the shelfβs beginning. If DravDe still canβt find an empty section for the box, he immediately drinks it all up and throws the empty bottles away not to be caught.
After one great party with a lot of Ogudar-Olok drunk DravDe asked you to help him. Unlike him, you can program and therefore modeling the process of counting the boxes in the warehouse will be easy work for you.
The process of counting contains two types of query messages:
- Β«+1 x y idΒ» (where *x*, *y* are integers, 1<=β€<=*x*<=β€<=*n*, 1<=β€<=*y*<=β€<=*m*, and *id* is a string of lower case Latin letters β from 1 to 10 characters long). That query means that the warehouse got a box identified as *id*, which should be put in the section *y* on the shelf *x*. If the section is full, use the rules described above. It is guaranteed that every moment of the process the identifiers of all the boxes in the warehouse are different. You donβt have to answer this query. - Β«-1 idΒ» (where *id* is a string of lower case Latin letters β from 1 to 10 characters long). That query means that a box identified as *id* is removed from the warehouse. You have to answer this query (see output format). | The first input line contains integers *n*, *m* and *k* (1<=β€<=*n*,<=*m*<=β€<=30, 1<=β€<=*k*<=β€<=2000) β the height, the width of shelving and the amount of the operations in the warehouse that you need to analyze. In the following *k* lines the queries are given in the order of appearance in the format described above. | For each query of the Β«-1 idΒ» type output two numbers in a separate line β index of the shelf and index of the section where the box with this identifier lay. If there was no such box in the warehouse when the query was made, output Β«-1 -1Β» without quotes. | [
"2 2 9\n+1 1 1 cola\n+1 1 1 fanta\n+1 1 1 sevenup\n+1 1 1 whitekey\n-1 cola\n-1 fanta\n-1 sevenup\n-1 whitekey\n-1 cola\n",
"2 2 8\n+1 1 1 cola\n-1 cola\n+1 1 1 fanta\n-1 fanta\n+1 1 1 sevenup\n-1 sevenup\n+1 1 1 whitekey\n-1 whitekey\n"
] | [
"1 1\n1 2\n2 1\n2 2\n-1 -1\n",
"1 1\n1 1\n1 1\n1 1\n"
] | none | [
{
"input": "2 2 9\n+1 1 1 cola\n+1 1 1 fanta\n+1 1 1 sevenup\n+1 1 1 whitekey\n-1 cola\n-1 fanta\n-1 sevenup\n-1 whitekey\n-1 cola",
"output": "1 1\n1 2\n2 1\n2 2\n-1 -1"
},
{
"input": "2 2 8\n+1 1 1 cola\n-1 cola\n+1 1 1 fanta\n-1 fanta\n+1 1 1 sevenup\n-1 sevenup\n+1 1 1 whitekey\n-1 whitekey",
"output": "1 1\n1 1\n1 1\n1 1"
},
{
"input": "2 2 5\n-1 ywesjzsdk\n-1 aaew\n+1 1 2 wk\n-1 wk\n-1 wk",
"output": "-1 -1\n-1 -1\n1 2\n-1 -1"
},
{
"input": "3 5 5\n-1 vpotlzzxu\n-1 ucdpqnechl\n-1 ykphisxph\n-1 buppgmurvz\n-1 rjhowqxmv",
"output": "-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1"
},
{
"input": "4 6 7\n+1 2 3 psj\n+1 4 5 vpjghrat\n+1 1 2 edvffw\n+1 4 2 lvmfvxowzz\n+1 3 6 hqiyvevtll\n+1 4 4 unfpiingsi\n-1 unfpiingsi",
"output": "4 4"
},
{
"input": "6 5 10\n+1 2 5 gw\n+1 3 4 mbgrh\n-1 gw\n+1 3 3 abcs\n-1 mbgrh\n+1 4 1 yna\n+1 3 3 fmhjovjklc\n+1 1 3 mcdspppmrv\n+1 2 4 ohiefjcq\n+1 3 1 jpk",
"output": "2 5\n3 4"
},
{
"input": "7 6 10\n-1 e\n-1 kzbdpeckem\n-1 esi\n-1 jgsokv\n-1 serkq\n-1 ipczknkye\n-1 bawktukez\n-1 wvw\n-1 jm\n+1 5 2 i",
"output": "-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1"
},
{
"input": "8 9 20\n+1 1 5 dsszh\n+1 6 3 xggbssovef\n+1 8 4 ura\n+1 8 4 l\n+1 6 6 jxszipfobb\n-1 l\n+1 6 7 ib\n+1 3 1 sxwnv\n+1 7 2 zattgyj\n+1 4 7 kvzatjkftd\n-1 dsszh\n+1 3 1 wsqbde\n+1 5 9 otwlz\n+1 2 3 hpaatle\n+1 2 9 evp\n+1 5 6 v\n-1 hpaatle\n-1 hpaatle\n-1 ura\n-1 otwlz",
"output": "8 5\n1 5\n2 3\n-1 -1\n8 4\n5 9"
},
{
"input": "5 1 10\n+1 2 1 t\n-1 t\n-1 t\n+1 5 1 prcle\n-1 t\n+1 3 1 epkbtyjk\n+1 3 1 kwqzwt\n-1 epkbtyjk\n+1 3 1 v\n+1 2 1 xib",
"output": "2 1\n-1 -1\n-1 -1\n3 1"
},
{
"input": "1 7 25\n-1 rwej\n+1 1 5 v\n-1 v\n-1 aoqq\n-1 ekyqnk\n-1 qhsguruyme\n-1 hnaro\n-1 xccmrodgx\n-1 t\n-1 oasftssp\n-1 hvacacmdff\n-1 wjmti\n-1 s\n-1 pekyyriywk\n-1 vxnz\n+1 1 7 xgfcnftep\n+1 1 7 vexyo\n-1 xgfcnftep\n-1 vexyo\n-1 fxygf\n+1 1 5 yyklyiul\n-1 yyklyiul\n-1 tknmop\n-1 dch\n-1 m",
"output": "-1 -1\n1 5\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n-1 -1\n1 7\n-1 -1\n-1 -1\n1 5\n-1 -1\n-1 -1\n-1 -1"
},
{
"input": "2 10 27\n+1 1 1 axxhgy\n+1 2 2 vhhmrgppzf\n+1 2 5 bvycznpbx\n-1 bvycznpbx\n+1 1 6 kdfmydiy\n+1 2 8 qad\n+1 1 7 mvvyza\n+1 1 6 i\n-1 mvvyza\n-1 vhhmrgppzf\n-1 axxhgy\n-1 qad\n-1 i\n-1 kdfmydiy\n+1 2 3 bjust\n+1 2 1 f\n-1 f\n-1 bjust\n+1 2 5 mrgryhbg\n+1 1 1 eaonus\n-1 eaonus\n+1 2 2 zavxcoam\n-1 mrgryhbg\n-1 zavxcoam\n+1 2 3 mqrwhwdbzg\n+1 2 9 rwby\n+1 2 2 wfgkuiapxq",
"output": "2 5\n1 7\n2 2\n1 1\n2 8\n1 8\n1 6\n2 1\n2 3\n1 1\n2 5\n2 2"
},
{
"input": "1 30 10\n+1 1 16 kqqpjfkhg\n-1 kqqpjfkhg\n+1 1 26 jmvcacxdc\n+1 1 16 xh\n-1 jmvcacxdc\n-1 xh\n+1 1 23 gbra\n+1 1 25 k\n+1 1 22 nctorw\n-1 gbra",
"output": "1 16\n1 26\n1 16\n1 23"
},
{
"input": "30 5 20\n+1 30 2 drzlg\n-1 drzlg\n+1 20 3 e\n+1 18 2 tip\n+1 1 5 jap\n-1 jap\n+1 19 2 jadnylbug\n+1 12 3 fcuhloenmz\n-1 tip\n+1 2 1 ut\n+1 26 2 unts\n+1 5 2 vbep\n+1 28 4 anacba\n-1 ut\n+1 23 1 urrmf\n+1 10 3 atbqvnlcg\n-1 unts\n-1 jadnylbug\n+1 25 2 kwzhnqzwuc\n+1 9 3 ppyzv",
"output": "30 2\n1 5\n18 2\n2 1\n26 2\n19 2"
}
] | 530 | 20,787,200 | 3.712623 | 59,634 |
196 | Infinite Maze | [
"dfs and similar",
"graphs"
] | null | null | We've got a rectangular *n*<=Γ<=*m*-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (*x*,<=*y*) is a wall if and only if cell is a wall.
In this problem is a remainder of dividing number *a* by number *b*.
The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell (*x*,<=*y*) he can go to one of the following cells: (*x*,<=*y*<=-<=1), (*x*,<=*y*<=+<=1), (*x*<=-<=1,<=*y*) and (*x*<=+<=1,<=*y*), provided that the cell he goes to is not a wall. | The first line contains two space-separated integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1500) β the height and the width of the maze that the boy used to cyclically tile the plane.
Each of the next *n* lines contains *m* characters β the description of the labyrinth. Each character is either a "#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point.
The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input. | Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes). | [
"5 4\n##.#\n##S#\n#..#\n#.##\n#..#\n",
"5 4\n##.#\n##S#\n#..#\n..#.\n#.##\n"
] | [
"Yes\n",
"No\n"
] | In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
In the second sample the vertical path is blocked. The path to the left doesn't work, too β the next "copy" of the maze traps the boy. | [] | 716 | 18,124,800 | -1 | 59,969 |
|
466 | Information Graph | [
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null | There are *n* employees working in company "X" (let's number them from 1 to *n* for convenience). Initially the employees didn't have any relationships among each other. On each of *m* next days one of the following events took place:
- either employee *y* became the boss of employee *x* (at that, employee *x* didn't have a boss before); - or employee *x* gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive); - or comes a request of type "determine whether employee *x* signs certain documents".
Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies. | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=105) β the number of employees and the number of events.
Each of the next *m* lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event *t* (1<=β€<=*t*<=β€<=3).
- If *t*<==<=1, then next follow two integers *x* and *y* (1<=β€<=*x*,<=*y*<=β€<=*n*) β numbers of the company employees. It is guaranteed that employee *x* doesn't have the boss currently. - If *t*<==<=2, then next follow integer *x* (1<=β€<=*x*<=β€<=*n*) β the number of the employee who got a document packet. - If *t*<==<=3, then next follow two integers *x* and *i* (1<=β€<=*x*<=β€<=*n*;Β 1<=β€<=*i*<=β€<=[number of packets that have already been given]) β the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order.
It is guaranteed that the input has at least one query of the third type. | For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes. | [
"4 9\n1 4 3\n2 4\n3 3 1\n1 2 3\n2 2\n3 1 2\n1 3 1\n2 2\n3 1 3\n"
] | [
"YES\nNO\nYES\n"
] | none | [] | 31 | 0 | 0 | 60,021 |
|
467 | Fedor and Essay | [
"dfs and similar",
"dp",
"graphs",
"hashing",
"strings"
] | null | null | After you had helped Fedor to find friends in the Β«Call of Soldiers 3Β» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.
Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.
As a result, Fedor wants to get an essay which contains as little letters Β«RΒ» (the case doesn't matter) as possible. If there are multiple essays with minimum number of Β«RΒ»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.
Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG. | The first line contains a single integer *m* (1<=β€<=*m*<=β€<=105) β the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 105 characters.
The next line contains a single integer *n* (0<=β€<=*n*<=β€<=105) β the number of pairs of words in synonym dictionary. The *i*-th of the next *n* lines contains two space-separated non-empty words *x**i* and *y**i*. They mean that word *x**i* can be replaced with word *y**i* (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed 5Β·105 characters.
All the words at input can only consist of uppercase and lowercase letters of the English alphabet. | Print two integers β the minimum number of letters Β«RΒ» in an optimal essay and the minimum length of an optimal essay. | [
"3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y\n",
"2\nRuruRu fedya\n1\nruruRU fedor\n"
] | [
"2 6\n",
"1 10\n"
] | none | [
{
"input": "3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y",
"output": "2 6"
},
{
"input": "2\nRuruRu fedya\n1\nruruRU fedor",
"output": "1 10"
},
{
"input": "1\nffff\n1\nffff r",
"output": "0 4"
},
{
"input": "2\nYURA YUrA\n1\nyura fedya",
"output": "0 10"
},
{
"input": "5\nhello my name is fedya\n2\nhello hi\nis i",
"output": "0 14"
},
{
"input": "5\nawiuegjsrkjshegkjshegseg g soeigjseg www s\n3\nwww s\nawiuegjsrkjshegkjshegseg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww www",
"output": "0 13"
},
{
"input": "5\naa bb cc ee ff\n5\naa a\nbb aa\ncc bb\nee cc\nff bb",
"output": "0 5"
},
{
"input": "7\nraki vezde est awjgkawkgjn ttttt raki raks\n4\nraks rks\nrks raks\nraki raks\nvezde pss",
"output": "3 31"
},
{
"input": "5\nfedor fedya www awwwwwww a\n5\nr a\nfedor fedr\nwww a\nawwwwwww www\na r",
"output": "1 12"
},
{
"input": "1\nYURA\n1\nyura lesha",
"output": "0 5"
},
{
"input": "2\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBA ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA\n2\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA neuzaiheshi\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBA ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA",
"output": "0 22"
},
{
"input": "10\nlalka lolka yura lesha fedya bredor tourist www qqq gruihdrkgjp\n11\nlalka lolka\nlolka lalka\nyura lolka\nlalka poka\nfedya bredor\nbredor yura\ntourist bredor\nwww qqq\nqqq w\nw g\ngruihdrkgjp bredor",
"output": "0 35"
},
{
"input": "1\nR\n0",
"output": "1 1"
},
{
"input": "3\nreka greka rak\n11\nrek rak\nrak grek\nreka rak\ngreka reka\nrak reka\nrak greka\ngreka rak\nlol rek\nlol rak\nLO lol\nABA BA",
"output": "3 9"
},
{
"input": "3\nreka greka rak\n13\nrek rak\nrak grek\nreka rak\ngreka reka\nrak reka\nrak greka\ngreka rak\nlol rek\nlol rak\nlol LO\nABA BA\nLOLKA rak\nrak lol",
"output": "0 6"
},
{
"input": "1\nr\n0",
"output": "1 1"
},
{
"input": "5\nfEdOR Is A bAd BoY\n2\nboy boYy\nFeDor fedyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0 70"
},
{
"input": "1\nyrwlqadsfw\n2\nmnqdxczpyo a\na mnqdxczpyo",
"output": "1 10"
},
{
"input": "4\nr rr rrr rrrr\n9\nrr rrr\nrrrr rr\nr rr\nr rrrr\nrrr rr\nrrr rrr\nrr rrr\nrr r\nr r",
"output": "4 4"
}
] | 30 | 0 | 0 | 60,081 |
|
679 | Bear and Bad Powers of 42 | [
"data structures"
] | null | null | Limak, a bear, isn't good at handling queries. So, he asks you to do it.
We say that powers of 42 (numbers 1,<=42,<=1764,<=...) are bad. Other numbers are good.
You are given a sequence of *n* good integers *t*1,<=*t*2,<=...,<=*t**n*. Your task is to handle *q* queries of three types:
1. 1 iΒ β print *t**i* in a separate line. 1. 2 a b xΒ β for set *t**i* to *x*. It's guaranteed that *x* is a good number. 1. 3 a b xΒ β for increase *t**i* by *x*. After this repeat the process while at least one *t**i* is bad.
You can note that after each query all *t**i* are good. | The first line of the input contains two integers *n* and *q* (1<=β€<=*n*,<=*q*<=β€<=100<=000)Β β the size of Limak's sequence and the number of queries, respectively.
The second line of the input contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (2<=β€<=*t**i*<=β€<=109)Β β initial elements of Limak's sequence. All *t**i* are good.
Then, *q* lines follow. The *i*-th of them describes the *i*-th query. The first number in the line is an integer *type**i* (1<=β€<=*type**i*<=β€<=3)Β β the type of the query. There is at least one query of the first type, so the output won't be empty.
In queries of the second and the third type there is 1<=β€<=*a*<=β€<=*b*<=β€<=*n*.
In queries of the second type an integer *x* (2<=β€<=*x*<=β€<=109) is guaranteed to be good.
In queries of the third type an integer *x* (1<=β€<=*x*<=β€<=109) may be bad. | For each query of the first type, print the answer in a separate line. | [
"6 12\n40 1700 7 1672 4 1722\n3 2 4 42\n1 2\n1 3\n3 2 6 50\n1 2\n1 4\n1 6\n2 3 4 41\n3 1 5 1\n1 1\n1 3\n1 5\n"
] | [
"1742\n49\n1842\n1814\n1822\n43\n44\n107\n"
] | After a query 3 2 4 42 the sequence is 40,β1742,β49,β1714,β4,β1722.
After a query 3 2 6 50 the sequence is 40,β1842,β149,β1814,β104,β1822.
After a query 2 3 4 41 the sequence is 40,β1842,β41,β41,β104,β1822.
After a query 3 1 5 1 the sequence is 43,β1845,β44,β44,β107,β1822. | [] | 0 | 0 | -1 | 60,134 |
|
883 | Downloading B++ | [
"binary search",
"implementation"
] | null | null | Only *T* milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is *f* bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per *t*0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages:
- download *a*1 bytes at the rate of one byte per *t*1 milliseconds, paying *p*1 burles for the package; - download *a*2 bytes at the rate of one byte per *t*2 milliseconds, paying *p*2 burles for the package.
Polycarp can buy any package many times. When buying a package, its price (*p*1 or *p*2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Find the minimum amount of money Polycarp has to spend to download an *f* bytes file no more than in *T* milliseconds.
Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages. | The first line contains three integer numbers *f*, *T* and *t*0 (1<=β€<=*f*,<=*T*,<=*t*0<=β€<=107) β size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of the first additional package. The line contains three integer numbers *a*1, *t*1 and *p*1 (1<=β€<=*a*1,<=*t*1,<=*p*1<=β€<=107), where *a*1 is maximal sizes of downloaded data (in bytes), *t*1 is time to download one byte (in milliseconds), *p*1 is price of the package (in burles).
The third line contains a description of the second additional package. The line contains three integer numbers *a*2, *t*2 and *p*2 (1<=β€<=*a*2,<=*t*2,<=*p*2<=β€<=107), where *a*2 is maximal sizes of downloaded data (in bytes), *t*2 is time to download one byte (in milliseconds), *p*2 is price of the package (in burles).
Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff. | Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in *T* milliseconds. If there is no solution, print the only integer -1. | [
"120 964 20\n26 8 8\n13 10 4\n",
"10 200 20\n1 1 1\n2 2 3\n",
"8 81 11\n4 10 16\n3 10 12\n",
"8 79 11\n4 10 16\n3 10 12\n"
] | [
"40\n",
"0\n",
"28\n",
"-1\n"
] | In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26Β·5β=β130 bytes) in 120Β·8β=β960 milliseconds (960ββ€β964). He spends 8Β·5β=β40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. It takes 10Β·20β=β200 milliseconds which equals to upper constraint on download time.
In the third example Polycarp has to buy one first additional package and one second additional package.
In the fourth example Polycarp has no way to download the file on time. | [
{
"input": "120 964 20\n26 8 8\n13 10 4",
"output": "40"
},
{
"input": "10 200 20\n1 1 1\n2 2 3",
"output": "0"
},
{
"input": "8 81 11\n4 10 16\n3 10 12",
"output": "28"
},
{
"input": "8 79 11\n4 10 16\n3 10 12",
"output": "-1"
},
{
"input": "62 10000 209\n95 106 79\n84 92 57",
"output": "57"
},
{
"input": "705 100000 157\n31 123 36\n37 111 10",
"output": "70"
},
{
"input": "5848 10000000 3431\n85 1154 19\n92 1093 35",
"output": "1004"
},
{
"input": "66983 1000000 19\n34 10 96\n5 7 7",
"output": "31815"
},
{
"input": "455314 1000000 5\n1 2 42\n57 2 60",
"output": "447960"
},
{
"input": "3982256 10000000 6\n34 2 11\n80 1 83",
"output": "1123749"
},
{
"input": "97 10000 229\n76 64 67\n38 75 21",
"output": "63"
},
{
"input": "804 100000 190\n13 115 24\n86 91 65",
"output": "438"
},
{
"input": "6794 10000000 1720\n63 1386 3\n46 1367 90",
"output": "243"
},
{
"input": "66287 1000000 44\n4 15 88\n66 14 63",
"output": "60984"
},
{
"input": "482426 1000000 2\n82 1 34\n10 1 16",
"output": "0"
},
{
"input": "3601769 10000000 6\n16 2 87\n37 2 42",
"output": "3294942"
},
{
"input": "86 10000 283\n46 86 59\n99 65 80",
"output": "80"
},
{
"input": "985 100000 203\n90 93 12\n48 66 21",
"output": "132"
},
{
"input": "9177 10000000 3121\n45 600 95\n3 1018 54",
"output": "15675"
},
{
"input": "59251 1000000 24\n85 16 76\n20 8 18",
"output": "23742"
},
{
"input": "674801 1000000 1\n60 1 19\n64 1 71",
"output": "0"
},
{
"input": "3919525 10000000 3\n85 1 79\n91 1 98",
"output": "817255"
},
{
"input": "96 10000 184\n28 76 43\n49 92 36",
"output": "72"
},
{
"input": "902 100000 265\n72 87 100\n2 78 80",
"output": "1100"
},
{
"input": "8622 10000000 2094\n18 967 79\n57 1021 9",
"output": "1188"
},
{
"input": "65359 1000000 24\n63 11 60\n73 10 78",
"output": "41676"
},
{
"input": "867175 1000000 1\n33 1 11\n25 1 31",
"output": "0"
},
{
"input": "4825706 10000000 5\n63 2 67\n45 2 53",
"output": "5008543"
},
{
"input": "99 10000 173\n5 78 35\n10 89 91",
"output": "560"
},
{
"input": "912 100000 206\n42 102 92\n55 76 44",
"output": "572"
},
{
"input": "8249 10000000 1757\n92 1030 67\n14 970 65",
"output": "4556"
},
{
"input": "67872 1000000 39\n45 13 52\n31 12 33",
"output": "64944"
},
{
"input": "789332 1000000 2\n7 1 99\n75 1 86",
"output": "663576"
},
{
"input": "3215535 10000000 8\n40 2 55\n10 1 9",
"output": "2021697"
},
{
"input": "85 10000 217\n83 66 23\n64 108 51",
"output": "23"
},
{
"input": "975 100000 231\n19 96 76\n17 77 99",
"output": "3724"
},
{
"input": "7683 10000000 2221\n70 902 59\n76 1138 24",
"output": "2064"
},
{
"input": "64431 1000000 18\n22 14 40\n84 14 89",
"output": "42355"
},
{
"input": "530692 1000000 3\n85 1 87\n37 1 41",
"output": "303016"
},
{
"input": "4121717 10000000 4\n18 2 43\n64 1 68",
"output": "2297448"
},
{
"input": "80 10000 344\n53 87 11\n18 63 10",
"output": "21"
},
{
"input": "952 100000 283\n97 52 64\n66 71 58",
"output": "506"
},
{
"input": "6584 10000000 4115\n51 1248 43\n29 1290 80",
"output": "5031"
},
{
"input": "66326 1000000 20\n88 13 20\n46 12 60",
"output": "10620"
},
{
"input": "788404 1000000 2\n66 1 75\n90 1 1",
"output": "6409"
},
{
"input": "4857625 10000000 6\n100 2 35\n21 2 24",
"output": "1675275"
},
{
"input": "92 10000 275\n34 73 99\n83 77 66",
"output": "66"
},
{
"input": "666 100000 397\n75 102 56\n28 123 18",
"output": "396"
},
{
"input": "9951 10000000 2037\n29 545 35\n79 794 35",
"output": "3675"
},
{
"input": "79855 1000000 20\n69 11 8\n100 9 15",
"output": "7694"
},
{
"input": "636673 1000000 1\n44 1 63\n44 1 56",
"output": "0"
},
{
"input": "2827186 10000000 9\n69 3 19\n75 2 91",
"output": "708814"
},
{
"input": "1 1 1\n1 1 1\n1 1 1",
"output": "0"
},
{
"input": "10000000 10000000 10000000\n10000000 10000000 10000000\n10000000 10000000 10000000",
"output": "-1"
},
{
"input": "10000000 10000000 10000000\n1 1 10000000\n1 1 10000000",
"output": "100000000000000"
},
{
"input": "49266 10000000 10000000\n2 120 48\n3 193 90",
"output": "1182384"
},
{
"input": "49038 10000000 10000000\n2 142 69\n3 170 73",
"output": "1193258"
},
{
"input": "49470 10000000 10000000\n1 114 51\n2 141 56",
"output": "1385160"
},
{
"input": "543948 10000000 10000000\n1 14 52\n2 16 75",
"output": "20398050"
},
{
"input": "2400000 10000000 7\n7 3 5\n19 5 2",
"output": "861658"
},
{
"input": "6666666 10000000 4\n1 1 3\n1 2 2",
"output": "16666664"
},
{
"input": "2860000 9360000 65\n5 2 47\n7 5 6",
"output": "16518696"
},
{
"input": "4614000 9997000 6\n2 1 70\n3 3 5",
"output": "71773335"
},
{
"input": "6666666 8888888 4\n1 1 3\n1 2 2",
"output": "17777776"
},
{
"input": "6666666 7777777 4\n1 1 3\n1 2 2",
"output": "18888887"
},
{
"input": "6000000 10000000 3\n2 1 5\n3 2 2",
"output": "7666668"
},
{
"input": "76050 76050 1000000\n101 1 101\n313 1 313",
"output": "76050"
},
{
"input": "152380 152380 1000000\n277 1 277\n229 1 229",
"output": "152380"
},
{
"input": "160702 160702 1000000\n223 1 223\n347 1 347",
"output": "160702"
},
{
"input": "60632 60632 1000000\n269 1 269\n109 1 109",
"output": "60632"
},
{
"input": "152118 152118 1000000\n199 1 199\n167 1 167",
"output": "152118"
},
{
"input": "191864 191864 1000000\n137 1 137\n499 1 499",
"output": "191864"
},
{
"input": "161084 161084 1000000\n443 1 443\n317 1 317",
"output": "161084"
},
{
"input": "204520 204520 1000000\n211 1 211\n337 1 337",
"output": "204520"
},
{
"input": "124908 124908 1000000\n173 1 173\n157 1 157",
"output": "124908"
},
{
"input": "123510 123510 1000000\n263 1 263\n251 1 251",
"output": "123510"
},
{
"input": "2000000 10000000 9\n3 3 5\n5 7 2",
"output": "2066668"
},
{
"input": "7000000 10000000 9\n3 1 5\n5 2 2",
"output": "7866670"
},
{
"input": "7000000 10000000 5\n3 1 5\n5 3 2",
"output": "9766670"
},
{
"input": "10 12 14\n19 2 4\n8 1 10",
"output": "14"
},
{
"input": "4 5 6\n7 2 2\n3 1 7",
"output": "9"
},
{
"input": "9 39 22\n7 9 13\n8 3 22",
"output": "35"
},
{
"input": "5 15 2\n21 11 9\n15 2 6",
"output": "0"
},
{
"input": "15 464 32\n65 28 96\n33 93 48",
"output": "96"
},
{
"input": "15 419 32\n65 28 96\n33 93 48",
"output": "-1"
},
{
"input": "8581 3000000 3019\n2151 140 4553\n5920 883 9170",
"output": "18212"
},
{
"input": "8581 1201339 3019\n2151 140 4553\n5920 883 9170",
"output": "-1"
},
{
"input": "31 530 58\n12 16 35\n8 92 1",
"output": "105"
},
{
"input": "31 830 58\n12 16 35\n8 92 1",
"output": "70"
},
{
"input": "31 490 58\n12 16 35\n8 92 1",
"output": "-1"
},
{
"input": "3 14 5\n2 4 9\n7 6 11",
"output": "9"
},
{
"input": "3 15 5\n2 4 9\n7 6 11",
"output": "0"
},
{
"input": "3 12 5\n2 4 9\n7 6 11",
"output": "18"
},
{
"input": "3 11 5\n2 4 9\n7 6 11",
"output": "-1"
},
{
"input": "343 50397 187\n735 732 357\n147 864 838",
"output": "-1"
},
{
"input": "23 264 90\n66 99 60\n80 12 94",
"output": "-1"
},
{
"input": "68 1034 84\n78 59 3\n5 9 29",
"output": "351"
},
{
"input": "68 734 84\n78 59 3\n5 9 29",
"output": "406"
},
{
"input": "68 534 84\n78 59 3\n5 9 29",
"output": "-1"
},
{
"input": "65 649 24\n90 9 5\n23 92 71",
"output": "5"
},
{
"input": "65 580 24\n90 9 5\n23 92 71",
"output": "-1"
},
{
"input": "20 30 21\n9 6 14\n6 1 21",
"output": "77"
},
{
"input": "1 2 2\n2 2 2\n1 2 1",
"output": "0"
},
{
"input": "2 1 3\n3 3 2\n2 2 2",
"output": "-1"
},
{
"input": "3 1 1\n3 3 2\n2 3 1",
"output": "-1"
},
{
"input": "4 1 5\n4 3 5\n4 5 5",
"output": "-1"
},
{
"input": "5 2 2\n6 6 5\n4 3 2",
"output": "-1"
},
{
"input": "4 3 2\n6 3 5\n2 4 3",
"output": "-1"
},
{
"input": "3 3 3\n1 1 5\n7 3 7",
"output": "15"
},
{
"input": "9 3 8\n1 2 1\n8 2 6",
"output": "-1"
},
{
"input": "8 8 1\n1 1 2\n7 7 8",
"output": "0"
},
{
"input": "6 2 1\n9 6 2\n8 8 11",
"output": "-1"
},
{
"input": "2 7 6\n7 12 7\n10 7 1",
"output": "-1"
},
{
"input": "3 2 5\n2 4 9\n7 6 11",
"output": "-1"
},
{
"input": "4 4 1\n6 9 7\n4 3 6",
"output": "0"
},
{
"input": "1 14 3\n5 1 14\n2 7 8",
"output": "0"
},
{
"input": "6 16 1\n5 10 2\n11 15 7",
"output": "0"
},
{
"input": "17 1 3\n10 1 3\n16 16 5",
"output": "-1"
},
{
"input": "6 9 2\n18 18 16\n3 3 14",
"output": "-1"
},
{
"input": "11 3 17\n11 15 5\n2 10 3",
"output": "-1"
},
{
"input": "20 4 1\n20 10 14\n14 10 4",
"output": "-1"
}
] | 46 | 0 | 0 | 60,153 |
|
723 | Text Document Analysis | [
"expression parsing",
"implementation",
"strings"
] | null | null | Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of:
- uppercase and lowercase English letters, - underscore symbols (they are used as separators), - parentheses (both opening and closing).
It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.
For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".
Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds:
- the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), - the number of words inside the parentheses (print 0, if there is no word inside the parentheses). | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=255)Β β the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols. | Print two space-separated integers:
- the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), - the number of words inside the parentheses (print 0, if there is no word inside the parentheses). | [
"37\n_Hello_Vasya(and_Petya)__bye_(and_OK)\n",
"37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__\n",
"27\n(LoooonG)__shOrt__(LoooonG)\n",
"5\n(___)\n"
] | [
"5 4",
"2 6",
"5 2",
"0 0\n"
] | In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer. | [
{
"input": "37\n_Hello_Vasya(and_Petya)__bye_(and_OK)",
"output": "5 4"
},
{
"input": "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__",
"output": "2 6"
},
{
"input": "27\n(LoooonG)__shOrt__(LoooonG)",
"output": "5 2"
},
{
"input": "5\n(___)",
"output": "0 0"
},
{
"input": "254\n()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()",
"output": "0 0"
},
{
"input": "14\nQ(___)_u(_U)HG",
"output": "2 1"
},
{
"input": "50\n_F_()___(____q)H_(__)__(_____p________o_)__Bz()___",
"output": "2 3"
},
{
"input": "10\ndJ_R_____K",
"output": "2 0"
},
{
"input": "20\nm(_)jzay()s()d()T(M)",
"output": "4 1"
},
{
"input": "50\n()()W()g_(EEX)UADba(R)()TD(L)X(Aub)DN(a)(YYJXNgyK)",
"output": "5 6"
},
{
"input": "80\n_____(_____k_____q____N)(e___sM__pf___)_(___g_____)__V_n___________z(__)__(___)U",
"output": "1 7"
},
{
"input": "100\nFE_i_UhQF_oIh(v__qf)WVa_gND___caHkdU(_WP_Kxm__WEIn_KZLBS)_XDwNnR_c(_Pv_A)LXO__GEd_R_bTP_hAnZ_____sDL",
"output": "6 8"
},
{
"input": "150\njUcWddnQOXvZcdiQm_ngFnpbXyQCIzHHwU(KHNQPMDPFkoihdhZAthjelfgAHS_tco_JwgEFu)q_WLbNsZgQLJFFX_vAOClrvJQm_XWhHDOP_aMT_RuCFsegLgwQbI_FTJPfIHwmpr_jrtbiTsiIaX",
"output": "17 3"
},
{
"input": "200\n()()()()()(_)()()()()()()()_()()()()()()()()(_)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()y()()()()()()()()()()()(_)()_()()()()()()()(_)()()()()()()()()()()()()(B)()()N_()()()()()()()()",
"output": "1 1"
},
{
"input": "250\nST()jw()()()(c)()()s_(bB)()q()()()()()()()(_)()()()()()()()(u)()()(e)()()()()()()()()()(_)()()()()()_(B_)()()()()n(_)(A)()()()()(M)I()P()(VT)o(_)q()()()()(f)()()()()()()a(Du)()()()k(Q)()(_)()()()()(U)Z()(d)()_(D)()y()()i(i)(O)_b()()()(__M)()()()()()w",
"output": "2 17"
},
{
"input": "255\nMSGxEfof_UkcbUrRTEUgYLoWoVjuQJbqbBBmvUPLU_BXTXNjysGvgZqtwh_snLtUPhFGJMnyRvF_lG_eEu_J__qI_wrADYbAKZjhJuYVC_etLQgvmVaeqJ_a(Xh_Z_zkWmHxSQYvBOP__nLINkxiWlGzQiFv_GgGGqShWhBS_lEqCidMabWaYwIx_fVTluiPJuBryPtBkkCGxb)lOj_iJXBGOqj_aerFn_cKkEWbAK_YrgX__mcroeiRmuaMqYh",
"output": "32 7"
},
{
"input": "255\n___t_Cjo_____J___c__F_(_c______JY__Ub__x___________K_zf___T_U___Kc_______P_____W__S__o____Yx__ge___v____S___N_p_v____n_b___E__e_V___a___S____yvZk_Lr___U_e__x____i_____m___Z______E__A_________k____T__)l_B_________________q(__O___oi___B_b______Gf____jz____)",
"output": "3 45"
},
{
"input": "255\nT___J(M_XZJlr_lH___mqJA_p__kW)ko__F_M_Aro__ZA_G_M_P_____j_V(J_Jk_dkR_ta_lbIUhKFfo_y_DluW)IVFj_gouRfMhabn()_e___q_vo__QPEGBI_TpVVI_clPwwb_m_yL_cMVKgi___RJb_J_f____tPCyntLOr_s_x_N_SyqQw_zP_mycsW_o_c_o_Yzb_UVa_ATd(BYH_gl___Y__Uzok_Y_IA_XL_D__bkJ____e__K_quk)",
"output": "10 25"
},
{
"input": "255\ngB(ZKoVzD_WVZaYCzXGJYiTHB_XpOcKuLmclmw)UmpgxadtSQ(jGo)KQfXT(Yr_fP_CPbdIv)(AAmaGwrvN)(_Zg)dw(q_O_yLXQzdf)cVN_hd__EaTKwvYNte(_NmFs_)d_KOCp(UWUuGkuMJ)IXwulpMrJwBqdprtLcOE_JSnifGNBBQnuB_(_rhlesFvqglyJ_OYr_WpRM)_fjIfYdXpEbSOZCvk()x_YLygRDpOOZrjycBG_NEa_KjII_Db",
"output": "20 17"
},
{
"input": "255\n__X__()__x___X_(_)(_Ax)__H()_(_)_(_________)___(Y_p__t)_(_F)_(bY__S__)_____v_()__()J____q_(__)_c___G_SI__(__ynv)_M_______(_x_____V___ib__i)(__r_)__A(_)d(H)____H_K_Q_(___KW)(p_n)__(______g)____L(_)_T_hL___(__)___(_)(_)_h()(f_____)_l_____(_)(l)____(_)_h(_)F",
"output": "2 20"
},
{
"input": "255\njNufi_Tql(Q)()_Rm(_RS)w()(Q)_(_)(c)Eme()()()J(vKJ_)(X_si)()g(u)(_)n()F()a()(_)(U)fx(c__qivDE)J(__pS_k)r()(N_Z_cW__)__z_LgHJE_()s_()BCKMgJ(eW)_t(oGp)()kl()(_)_(__tn_W_Y)dD()(_)_()()x_(u)(W)(T)E(_LF_DkdIx)sx__(Q_)(bL)V(_)(oKrE)__(_)(fW_)_z_()()O(O)_()cacQg_",
"output": "6 31"
},
{
"input": "255\na()J()f()vAL()(pV)(Ve)()()c()()(Wtg)(_)DW(D)()()sEXF()(_B)V(_W)Z_a_(_)U(tb)(u)I()Z()_()()()cw()ZW()Z()V()A(T)_a()()_jL(V)()(z)()Tn()y()(B)uEf()(B)()()p()()(B_)nz(Xs)(o)T()()IkH()()(pJ)()()()()()E()z()Ja_()Z()(Q)(_)(N)()c()p()g(_)l()()Q()()U()()()()(aZ)m()",
"output": "4 20"
},
{
"input": "255\nAf________T_C____t_p(_Ug___Fr_Wg_)j_____x__j_a___Q_____(__p_____M)__J__jj____E__J(_W____eT)__wtm____T____Z_c_____C____P_____k___(___ql_X_B_________l____L_______F___m___p_S__DI______w)_f__r_lGG_m__SJ(__q__G_____s___s___o_______bg____f____vZ___rg_k___C____)",
"output": "3 29"
},
{
"input": "255\n(s)()(y)()()l()()()()()()()()_c()()()()X()()()()(l)()()()()()ND()(F)()()_()()()()a()()F(O)(e)()(_)(t)(_)()_()()_()()()()()(So)()()(Lm)(e)()()(F)()Yt(_)()()__()()()(w)T()(s)()_()()()()O(j)()U()()()()()_(_H)()()_()()()c()(_)()()y(j)()C_()()HRx()()(EE)()p()W",
"output": "3 17"
},
{
"input": "255\n()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()_()()()()()()()()K()()()()()()()()()()()()(_)()()_()()()z()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()",
"output": "1 0"
},
{
"input": "255\n(I_____)_________Q__W(P_V___G__m_U_)___________a_X__X_n__Br______N___(__)(_q)(___G____x_)__r_ru__D_(____E_u)_cV_joiL_(______)C__W(___BtgJ__ga_FFwpcu_K)_Tm(____h__)_(____v_)_(_F___E_n_lm_kctg_____u__)Q___vh(u_)__(____CAM__F_Y___O__G_P___)_P_ZLo__K__nGAgq_S",
"output": "5 30"
},
{
"input": "255\nacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJasdza",
"output": "255 0"
},
{
"input": "255\n(cvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJasdz)",
"output": "0 1"
},
{
"input": "255\n(a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a)",
"output": "0 127"
},
{
"input": "1\n_",
"output": "0 0"
},
{
"input": "1\na",
"output": "1 0"
},
{
"input": "2\n()",
"output": "0 0"
},
{
"input": "2\nad",
"output": "2 0"
},
{
"input": "2\n_a",
"output": "1 0"
},
{
"input": "2\nq_",
"output": "1 0"
},
{
"input": "3\n(_)",
"output": "0 0"
},
{
"input": "3\n(a)",
"output": "0 1"
},
{
"input": "3\nq_z",
"output": "1 0"
},
{
"input": "6\na(al)a",
"output": "1 1"
},
{
"input": "10\na(a)aa(a)a",
"output": "2 2"
},
{
"input": "5\n()abc",
"output": "3 0"
}
] | 46 | 0 | 3 | 60,163 |
|
567 | President and Roads | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=β <=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town *t*, for which his motorcade passes along some path from *s* to *t* (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from *s* to *t*, along which he will travel the fastest.
The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer. | The first lines contain four integers *n*, *m*, *s* and *t* (2<=β€<=*n*<=β€<=105;Β 1<=β€<=*m*<=β€<=105;Β 1<=β€<=*s*,<=*t*<=β€<=*n*) β the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=β <=*t*).
Next *m* lines contain the roads. Each road is given as a group of three integers *a**i*,<=*b**i*,<=*l**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*;Β *a**i*<=β <=*b**i*;Β 1<=β€<=*l**i*<=β€<=106) β the cities that are connected by the *i*-th road and the time needed to ride along it. The road is directed from city *a**i* to city *b**i*.
The cities are numbered from 1 to *n*. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from *s* to *t* along the roads. | Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the *i*-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.
If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes). | [
"6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1\n",
"3 3 1 3\n1 2 10\n2 3 10\n1 3 100\n",
"2 2 1 2\n1 2 1\n1 2 2\n"
] | [
"YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES\n",
"YES\nYES\nCAN 81\n",
"YES\nNO\n"
] | The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1βββ2βββ4βββ5βββ6 or 1βββ2βββ3βββ5βββ6. | [
{
"input": "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1",
"output": "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"
},
{
"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 100",
"output": "YES\nYES\nCAN 81"
},
{
"input": "2 2 1 2\n1 2 1\n1 2 2",
"output": "YES\nNO"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 19",
"output": "CAN 2\nCAN 2\nYES"
},
{
"input": "4 3 1 4\n1 2 1\n2 3 1\n3 4 1",
"output": "YES\nYES\nYES"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 2",
"output": "NO\nNO\nYES\nCAN 1"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "NO\nNO\nYES\nYES"
},
{
"input": "6 6 1 6\n1 2 2\n2 3 4\n2 4 3\n3 5 2\n4 5 3\n5 6 10",
"output": "YES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"
},
{
"input": "6 6 1 6\n1 2 2\n2 3 3\n2 4 3\n3 5 2\n4 5 3\n5 6 10",
"output": "YES\nYES\nCAN 2\nYES\nCAN 2\nYES"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "2 2 1 2\n1 2 6\n1 2 6",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 3 1 2\n1 2 7\n1 2 7\n1 2 7",
"output": "CAN 1\nCAN 1\nCAN 1"
},
{
"input": "2 10 1 2\n1 2 5\n1 2 5\n1 2 7\n1 2 5\n1 2 6\n1 2 5\n1 2 5\n1 2 6\n1 2 5\n1 2 6",
"output": "CAN 1\nCAN 1\nCAN 3\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 2"
},
{
"input": "3 2 1 2\n3 2 3\n1 3 6",
"output": "YES\nYES"
},
{
"input": "3 3 1 3\n2 3 7\n2 3 7\n1 2 6",
"output": "CAN 1\nCAN 1\nYES"
},
{
"input": "3 4 3 1\n2 1 4\n2 1 2\n3 2 1\n2 1 2",
"output": "CAN 3\nCAN 1\nYES\nCAN 1"
},
{
"input": "3 5 1 2\n1 3 3\n1 2 9\n3 2 6\n1 2 10\n1 3 3",
"output": "CAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1"
},
{
"input": "3 7 1 3\n1 3 11\n1 3 12\n1 2 2\n1 3 11\n1 2 2\n2 3 9\n2 3 9",
"output": "CAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 1"
},
{
"input": "5 7 3 2\n5 4 8\n3 1 2\n1 2 20\n1 5 8\n4 2 4\n1 5 8\n5 4 9",
"output": "CAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 2"
},
{
"input": "7 8 5 3\n4 3 5\n7 1 8\n2 1 16\n2 7 7\n2 6 21\n5 2 10\n6 4 4\n1 6 5",
"output": "YES\nYES\nCAN 2\nYES\nCAN 2\nYES\nYES\nYES"
},
{
"input": "6 8 1 6\n1 2 13\n3 2 3\n4 5 6\n1 6 28\n1 3 10\n1 4 18\n2 4 4\n5 6 4",
"output": "CAN 1\nCAN 1\nYES\nCAN 2\nCAN 1\nCAN 2\nYES\nYES"
},
{
"input": "7 10 4 7\n6 3 9\n2 1 4\n3 7 3\n5 2 6\n1 3 12\n5 2 6\n4 5 4\n4 5 3\n1 6 3\n4 6 16",
"output": "CAN 1\nCAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1"
},
{
"input": "10 13 2 10\n7 3 5\n6 1 10\n9 6 4\n4 10 48\n9 5 2\n1 10 3\n5 6 2\n7 6 19\n4 8 8\n2 4 8\n8 7 7\n7 6 20\n3 9 10",
"output": "CAN 1\nYES\nCAN 1\nCAN 2\nCAN 1\nYES\nCAN 1\nCAN 1\nYES\nYES\nYES\nCAN 2\nCAN 1"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 4 3",
"output": "NO\nNO\nNO\nCAN 1"
},
{
"input": "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "NO\nCAN 3\nCAN 3\nYES\nYES\nYES"
},
{
"input": "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "NO\nCAN 3\nCAN 3\nYES\nYES\nYES"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "3 3 1 3\n1 2 1\n1 3 2\n2 3 1",
"output": "NO\nCAN 1\nNO"
},
{
"input": "10 10 1 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "10 10 1 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "3 3 1 3\n1 2 1\n2 3 1\n1 3 2",
"output": "NO\nNO\nCAN 1"
},
{
"input": "6 7 1 6\n1 2 1000000\n2 3 1000000\n2 5 1000000\n1 3 1000000\n3 5 1000000\n2 4 1000000\n5 6 1000000",
"output": "CAN 1\nNO\nCAN 1\nCAN 1\nCAN 1\nNO\nYES"
},
{
"input": "2 1 1 2\n1 2 1000000",
"output": "YES"
},
{
"input": "2 2 1 2\n1 2 1000000\n1 2 1000000",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 2 1 2\n1 2 1000000\n1 2 1000000",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000",
"output": "NO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO"
},
{
"input": "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000",
"output": "CAN 999999\nCAN 999999\nCAN 999999\nCAN 999999\nYES\nCAN 999999\nCAN 999999\nCAN 999999\nCAN 999999"
},
{
"input": "3 2 1 3\n1 3 1\n1 2 1",
"output": "YES\nNO"
},
{
"input": "4 5 1 4\n1 2 1\n1 2 1\n2 3 1\n3 4 1\n3 4 1",
"output": "NO\nNO\nYES\nNO\nNO"
},
{
"input": "3 3 1 3\n1 2 666\n2 3 555\n3 1 1",
"output": "YES\nYES\nNO"
}
] | 46 | 0 | 0 | 60,189 |
|
959 | Mahmoud and Ehab and the wrong algorithm | [
"constructive algorithms",
"trees"
] | null | null | Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:
Given an undirected tree consisting of *n* nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (*u*,<=*v*) that belongs to the tree, either *u* is in the set, or *v* is in the set, or both are in the set. Mahmoud has found the following algorithm:
- Root the tree at node 1. - Count the number of nodes at an even depth. Let it be *evenCnt*. - Count the number of nodes at an odd depth. Let it be *oddCnt*. - The answer is the minimum between *evenCnt* and *oddCnt*.
The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.
Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of *n* nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one. | The only line contains an integer *n* (2<=β€<=*n*<=β€<=105), the number of nodes in the desired trees. | The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only.
If the answer for a section exists, it should contain *n*<=-<=1 lines, each containing 2 space-separated integers *u* and *v* (1<=β€<=*u*,<=*v*<=β€<=*n*), which means that there's an undirected edge between node *u* and node *v*. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict.
If there are multiple answers, you can print any of them. | [
"2\n",
"8\n"
] | [
"-1\n1 2\n",
"1 2\n1 3\n2 4\n2 5\n3 6\n4 7\n4 8\n1 2\n1 3\n2 4\n2 5\n2 6\n3 7\n6 8"
] | In the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed β-β1 in the first section, but notice that we printed this tree in the second section.
In the second sample:
In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this: <img class="tex-graphics" src="https://espresso.codeforces.com/fb4efe76f0a74395fe77f22da2dbd2a3340f8b2a.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second tree, the algorithm will find an answer with 3 nodes which is correct: <img class="tex-graphics" src="https://espresso.codeforces.com/700db299c05ae94849f44b93e8240d375a0fe05f.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "2",
"output": "-1\n1 2"
},
{
"input": "8",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8"
},
{
"input": "99",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "100",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "100000",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "3212",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "54321",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "54320",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "3",
"output": "-1\n1 2\n1 3"
},
{
"input": "4",
"output": "-1\n1 2\n1 3\n1 4"
},
{
"input": "5",
"output": "-1\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "6",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 2\n1 3\n1 4\n1 5\n1 6"
},
{
"input": "7",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7"
},
{
"input": "67575",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "99999",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "2048",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "2047",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "2049",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "10101",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "11",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11"
},
{
"input": "13",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13"
},
{
"input": "21",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21"
},
{
"input": "31",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31"
},
{
"input": "43",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43"
},
{
"input": "57",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n..."
},
{
"input": "73",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n..."
},
{
"input": "91",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "111",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "133",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "157",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "183",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "211",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "241",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "273",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "307",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "343",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "381",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
},
{
"input": "421",
"output": "1 2\n1 3\n1 4\n2 5\n2 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n1 8..."
}
] | 46 | 0 | 0 | 60,216 |
|
97 | Winning Strategy | [
"binary search",
"graphs",
"math",
"shortest paths"
] | C. Winning Strategy | 2 | 256 | One university has just found out about a sport programming contest called ACM ICPC v2.0. This contest doesn't differ much from the well-known ACM ICPC, for example, the participants are not allowed to take part in the finals more than two times. However, there is one notable difference: the teams in the contest should consist of exactly *n* participants.
Having taken part in several ACM ICPC v2.0 finals and having not won any medals, the students and the university governors realized that it's high time they changed something about the preparation process. Specifically, as the first innovation it was decided to change the teams' formation process. Having spent considerable amount of time on studying the statistics of other universities' performance, they managed to receive some interesting information: the dependence between the probability of winning a medal and the number of team members that participated in the finals in the past. More formally, we know *n*<=+<=1 real numbers *p*0<=β€<=*p*1<=β€<=...<=β€<=*p**n*, where *p**i* is the probability of getting a medal on the finals if the team has *i* participants of previous finals, and other *n*<=-<=*i* participants arrived to the finals for the first time.
Despite such useful data, the university governors are unable to determine such team forming tactics that would provide the maximum probability of winning a medal at ACM ICPC v2.0 finals on average (we are supposed to want to provide such result to the far future and we are also supposed to have an endless supply of students). And how about you, can you offer such optimal tactic? At the first stage the university governors want to know the value of maximum average probability.
More formally, suppose that the university sends a team to the *k*-th world finals. The team has *a**k* participants of previous finals (0<=β€<=*a**k*<=β€<=*n*). Since each person can participate in the finals no more than twice, the following condition must be true: . Your task is to choose sequence so that the limit Ξ¨ exists and it's value is maximal:
As is an infinite sequence, you should only print the maximum value of the Ξ¨ limit. | The first line contains an integer *n* (3<=β€<=*n*<=β€<=100), *n* is the number of team participants. The second line contains *n*<=+<=1 real numbers with no more than 6 digits after decimal point *p**i* (0<=β€<=*i*<=β€<=*n*,<=0<=β€<=*p**i*<=β€<=1) β the probability of that the team will win a medal if it contains *i* participants who has already been on the finals. Also the condition *p**i*<=β€<=*p**i*<=+<=1 should be fulfilled for all 0<=β€<=*i*<=β€<=*n*<=-<=1. | Print the only real number β the expected average number of medals won per year if the optimal strategy is used. The result may have absolute or relative error 10<=-<=6. | [
"3\n0.115590 0.384031 0.443128 0.562356\n",
"3\n1 1 1 1\n"
] | [
"0.4286122500\n",
"0.9999999999\n"
] | In the second test, no matter what participants the team contains, it is doomed to be successful. | [
{
"input": "3\n0.115590 0.384031 0.443128 0.562356",
"output": "0.4286122500"
},
{
"input": "3\n1 1 1 1",
"output": "0.9999999999"
},
{
"input": "10\n0.054228 0.284367 0.307914 0.319911 0.325274 0.336089 0.549308 0.554288 0.814348 0.817238 0.861607",
"output": "0.5872132857"
},
{
"input": "20\n0.081966 0.097675 0.319863 0.340093 0.351920 0.506820 0.525053 0.536592 0.556337 0.574506 0.602601 0.620568 0.678526 0.739903 0.761558 0.775742 0.785815 0.812902 0.891963 0.913274 0.916400",
"output": "0.6549519231"
},
{
"input": "50\n0.002733 0.006971 0.008918 0.011383 0.035551 0.042300 0.066802 0.067755 0.096749 0.098875 0.150015 0.154402 0.191630 0.192494 0.198452 0.217941 0.249867 0.298732 0.379811 0.382433 0.393376 0.398309 0.400639 0.404437 0.410679 0.454481 0.474332 0.511653 0.542087 0.559806 0.581381 0.640528 0.644679 0.658710 0.683507 0.684247 0.691545 0.729354 0.741940 0.742649 0.747197 0.771071 0.792992 0.794223 0.839466 0.853904 0.854982 0.870647 0.918208 0.983684 0.983791",
"output": "0.5201970769"
},
{
"input": "10\n0.108229 0.144929 0.147907 0.150700 0.164624 0.847466 0.879012 0.929890 0.943290 0.950473 0.988280",
"output": "0.8474659999"
},
{
"input": "20\n0.013418 0.031047 0.058761 0.824441 0.832842 0.866752 0.867978 0.873314 0.881171 0.893784 0.914427 0.925851 0.935678 0.944517 0.951318 0.951857 0.969854 0.980218 0.980836 0.986990 0.989683",
"output": "0.9160011666"
},
{
"input": "15\n0.000943 0.009789 0.024618 0.033935 0.065238 0.110501 0.120076 0.122726 0.127778 0.165465 0.176855 0.183939 0.847525 0.889085 0.986752 0.989054",
"output": "0.5300567499"
},
{
"input": "20\n0.081966 0.097675 0.319863 0.340093 0.351920 0.506820 0.525053 0.536592 0.556337 0.574506 0.602601 0.620568 0.678526 0.739903 0.761558 0.775742 0.785815 0.812902 0.891963 0.913274 0.916400",
"output": "0.6549519231"
},
{
"input": "30\n0.005375 0.018956 0.069062 0.132277 0.146311 0.154532 0.219440 0.220080 0.251067 0.267117 0.278511 0.279826 0.286081 0.334665 0.360275 0.420889 0.455323 0.515078 0.518634 0.553399 0.656105 0.667799 0.740058 0.754391 0.769630 0.793889 0.795800 0.859261 0.859383 0.883934 0.973808",
"output": "0.5161386842"
},
{
"input": "10\n0.054228 0.284367 0.307914 0.319911 0.325274 0.336089 0.549308 0.554288 0.814348 0.817238 0.861607",
"output": "0.5872132857"
},
{
"input": "3\n0.115590 0.384031 0.443128 0.562356",
"output": "0.4286122500"
},
{
"input": "17\n0.069518 0.126595 0.146372 0.196193 0.240407 0.249531 0.250888 0.465053 0.620359 0.654906 0.713490 0.807333 0.828853 0.878560 0.906115 0.939098 0.939560 0.958607",
"output": "0.6515213333"
},
{
"input": "13\n0.051089 0.132781 0.143712 0.245537 0.253307 0.323688 0.435564 0.484608 0.584762 0.602883 0.702225 0.775067 0.847569 0.869662",
"output": "0.4901749999"
},
{
"input": "14\n0.091978 0.173558 0.216689 0.220746 0.348680 0.656493 0.691814 0.753198 0.804835 0.811447 0.842890 0.887136 0.909620 0.912307 0.920167",
"output": "0.7553876666"
},
{
"input": "15\n0.024907 0.187331 0.195955 0.382289 0.565933 0.684781 0.691834 0.696622 0.780745 0.804170 0.838211 0.862508 0.904611 0.922293 0.989297 0.997097",
"output": "0.7693687778"
},
{
"input": "10\n0.017688 0.159187 0.199438 0.857000 0.860224 0.911542 0.914250 0.916729 0.938956 0.948009 0.977353",
"output": "0.9115419999"
},
{
"input": "5\n0.039691 0.155676 0.180769 0.833999 0.835840 0.843271",
"output": "0.7016143333"
},
{
"input": "17\n0.001636 0.020765 0.026201 0.027823 0.065095 0.087107 0.096402 0.115641 0.149148 0.155487 0.163106 0.167860 0.173202 0.188831 0.199240 0.804180 0.957782 0.961249",
"output": "0.5095885625"
},
{
"input": "30\n0.020168 0.023946 0.025927 0.029094 0.032753 0.048447 0.051263 0.060004 0.063043 0.068712 0.079572 0.099400 0.132314 0.135194 0.141749 0.152333 0.172049 0.180249 0.187812 0.192549 0.827582 0.834497 0.858507 0.876441 0.900926 0.914567 0.932619 0.969198 0.985454 0.989613 0.998691",
"output": "0.6257285000"
},
{
"input": "10\n0.000000 0.100000 0.200000 0.300000 0.400000 0.500000 0.600000 0.700000 0.800000 0.900000 1.000000",
"output": "0.4999999999"
},
{
"input": "20\n0.000000 0.050000 0.100000 0.150000 0.200000 0.250000 0.300000 0.350000 0.400000 0.450000 0.500000 0.550000 0.600000 0.650000 0.700000 0.750000 0.800000 0.850000 0.900000 0.950000 1.000000",
"output": "0.4999999999"
},
{
"input": "3\n0.000000 0.333333 0.666667 1.000000",
"output": "0.5000002499"
},
{
"input": "50\n0.000000 0.020000 0.040000 0.060000 0.080000 0.100000 0.120000 0.140000 0.160000 0.180000 0.200000 0.220000 0.240000 0.260000 0.280000 0.300000 0.320000 0.340000 0.360000 0.380000 0.400000 0.420000 0.440000 0.460000 0.480000 0.500000 0.520000 0.540000 0.560000 0.580000 0.600000 0.620000 0.640000 0.660000 0.680000 0.700000 0.720000 0.740000 0.760000 0.780000 0.800000 0.820000 0.840000 0.860000 0.880000 0.900000 0.920000 0.940000 0.960000 0.980000 1.000000",
"output": "0.4999999999"
},
{
"input": "30\n0.000000 0.033333 0.066667 0.100000 0.133333 0.166667 0.200000 0.233333 0.266667 0.300000 0.333333 0.366667 0.400000 0.433333 0.466667 0.500000 0.533333 0.566667 0.600000 0.633333 0.666667 0.700000 0.733333 0.766667 0.800000 0.833333 0.866667 0.900000 0.933333 0.966667 1.000000",
"output": "0.5000003333"
},
{
"input": "34\n0.000000 0.029412 0.058824 0.088235 0.117647 0.147059 0.176471 0.205882 0.235294 0.264706 0.294118 0.323529 0.352941 0.382353 0.411765 0.441176 0.470588 0.500000 0.529412 0.558824 0.588235 0.617647 0.647059 0.676471 0.705882 0.735294 0.764706 0.794118 0.823529 0.852941 0.882353 0.911765 0.941176 0.970588 1.000000",
"output": "0.5000004706"
},
{
"input": "10\n0.010846 0.056873 0.061583 0.063982 0.067218 0.109862 0.110858 0.162870 0.163448 0.172321 1.000000",
"output": "0.5054229999"
},
{
"input": "20\n0.016393 0.019535 0.063973 0.068019 0.070384 0.101364 0.105011 0.107318 0.111267 0.114901 0.120520 0.124114 0.147981 0.152312 0.155148 0.157163 0.162580 0.178393 0.182655 0.183280 1.000000",
"output": "0.5081964999"
},
{
"input": "3\n0.023118 0.076806 0.112471 1.000000",
"output": "0.5115589999"
},
{
"input": "5\n0.104312 0.152908 0.157900 0.160739 0.186055 1.000000",
"output": "0.5521559999"
},
{
"input": "50\n0.000547 0.001394 0.001784 0.002277 0.007110 0.008460 0.013360 0.013551 0.019775 0.030003 0.030880 0.038326 0.038499 0.039690 0.043588 0.049973 0.059746 0.075962 0.076487 0.078675 0.079662 0.080128 0.080887 0.082136 0.090896 0.094866 0.102331 0.108417 0.111961 0.116276 0.128106 0.128936 0.131742 0.136701 0.136849 0.138309 0.145871 0.148388 0.148530 0.149439 0.154214 0.158598 0.158845 0.167893 0.170781 0.170996 0.174129 0.183642 0.196737 0.196758 1.000000",
"output": "0.5002734999"
},
{
"input": "17\n0.013904 0.025319 0.029274 0.048081 0.049906 0.050178 0.093011 0.124072 0.130981 0.142698 0.161467 0.165771 0.175712 0.181223 0.187820 0.187912 0.191721 1.000000",
"output": "0.5069519999"
},
{
"input": "3\n0.115590 0.115590 0.115590 0.115590",
"output": "0.1155899999"
},
{
"input": "5\n0.764539 0.764539 0.764539 0.764539 0.764539 0.764539",
"output": "0.7645389999"
},
{
"input": "10\n0.336089 0.336089 0.336089 0.336089 0.336089 0.336089 0.336089 0.336089 0.336089 0.336089 0.336089",
"output": "0.3360889999"
},
{
"input": "20\n0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675 0.097675",
"output": "0.0976749999"
},
{
"input": "50\n0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433 0.382433",
"output": "0.3824329999"
},
{
"input": "99\n0 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.9 0.9 0.9",
"output": "0.5041666667"
}
] | 92 | 0 | 0 | 60,802 |
Subsets and Splits