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
441
Valera and Swaps
[ "constructive algorithms", "dsu", "graphs", "implementation", "math", "string suffix structures" ]
null
null
A permutation *p* of length *n* is a sequence of distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=*n*). A permutation is an identity permutation, if for any *i* the following equation holds *p**i*<==<=*i*. A swap (*i*,<=*j*) is the operation that swaps elements *p**i* and *p**j* in the permutation. Let's assume that *f*(*p*) is the minimum number of swaps that you need to make the permutation *p* an identity permutation. Valera wonders, how he can transform permutation *p* into any permutation *q*, such that *f*(*q*)<==<=*m*, using the minimum number of swaps. Help him do that.
The first line contains integer *n* (1<=≀<=*n*<=≀<=3000) β€” the length of permutation *p*. The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≀<=*p**i*<=≀<=*n*) β€” Valera's initial permutation. The last line contains integer *m* (0<=≀<=*m*<=&lt;<=*n*).
In the first line, print integer *k* β€” the minimum number of swaps. In the second line, print 2*k* integers *x*1,<=*x*2,<=...,<=*x*2*k* β€” the description of the swap sequence. The printed numbers show that you need to consecutively make swaps (*x*1,<=*x*2), (*x*3,<=*x*4), ..., (*x*2*k*<=-<=1,<=*x*2*k*). If there are multiple sequence swaps of the minimum length, print the lexicographically minimum one.
[ "5\n1 2 3 4 5\n2\n", "5\n2 1 4 5 3\n2\n" ]
[ "2\n1 2 1 3 ", "1\n1 2 " ]
Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*s*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ..., *y*<sub class="lower-index">*s*</sub>, if there is such integer *r* (1 ≀ *r* ≀ *s*), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*r* - 1</sub> = *y*<sub class="lower-index">*r* - 1</sub> and *x*<sub class="lower-index">*r*</sub> &lt; *y*<sub class="lower-index">*r*</sub>.
[]
46
0
0
6,800
786
Legacy
[ "data structures", "graphs", "shortest paths" ]
null
null
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are *n* planets in their universe numbered from 1 to *n*. Rick is in planet number *s* (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial. By default he can not open any portal by this gun. There are *q* plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more. Plans on the website have three types: 1. With a plan of this type you can open a portal from planet *v* to planet *u*. 1. With a plan of this type you can open a portal from planet *v* to any planet with index in range [*l*,<=*r*]. 1. With a plan of this type you can open a portal from any planet with index in range [*l*,<=*r*] to planet *v*. Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.
The first line of input contains three integers *n*, *q* and *s* (1<=≀<=*n*,<=*q*<=≀<=105, 1<=≀<=*s*<=≀<=*n*) β€” number of planets, number of plans and index of earth respectively. The next *q* lines contain the plans. Each line starts with a number *t*, type of that plan (1<=≀<=*t*<=≀<=3). If *t*<==<=1 then it is followed by three integers *v*, *u* and *w* where *w* is the cost of that plan (1<=≀<=*v*,<=*u*<=≀<=*n*, 1<=≀<=*w*<=≀<=109). Otherwise it is followed by four integers *v*, *l*, *r* and *w* where *w* is the cost of that plan (1<=≀<=*v*<=≀<=*n*, 1<=≀<=*l*<=≀<=*r*<=≀<=*n*, 1<=≀<=*w*<=≀<=109).
In the first and only line of output print *n* integers separated by spaces. *i*-th of them should be minimum money to get from earth to *i*-th planet, or <=-<=1 if it's impossible to get to that planet.
[ "3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17\n", "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16\n" ]
[ "0 28 12 \n", "0 -1 -1 12 \n" ]
In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2.
[ { "input": "3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17", "output": "0 28 12 " }, { "input": "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16", "output": "0 -1 -1 12 " }, { "input": "6 1 5\n1 3 6 80612370", "output": "-1 -1 -1 -1 0 -1 " }, { "input": "10 8 7\n1 10 7 366692903\n1 4 8 920363557\n2 7 5 10 423509459\n2 2 5 7 431247033\n2 7 3 5 288617239\n2 7 3 3 175870925\n3 9 3 8 651538651\n3 4 2 5 826387883", "output": "-1 -1 175870925 288617239 288617239 423509459 0 423509459 423509459 423509459 " }, { "input": "1 1 1\n1 1 1 692142678", "output": "0 " }, { "input": "2 4 2\n3 2 1 2 227350719\n2 2 1 1 111798664\n1 2 2 972457508\n2 2 2 2 973058334", "output": "111798664 0 " }, { "input": "8 8 1\n3 7 2 5 267967223\n1 6 7 611402069\n3 7 2 8 567233748\n2 2 1 8 28643141\n3 3 3 8 79260103\n1 6 8 252844388\n2 1 4 4 827261673\n3 4 4 5 54569367", "output": "0 -1 906521776 827261673 -1 -1 1095228896 -1 " }, { "input": "100000 1 63256\n3 15441 33869 86113 433920134", "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 -..." }, { "input": "100000 3 62808\n1 24005 82398 56477958\n3 24602 1247 28132 162610429\n2 49286 32968 50427 574452545", "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 -..." } ]
46
4,608,000
-1
6,804
774
Maximum Number
[ "*special", "constructive algorithms", "greedy", "implementation" ]
null
null
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most *n* sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.
The first line contains the integer *n* (2<=≀<=*n*<=≀<=100<=000) β€” the maximum number of sections which can be highlighted on the display.
Print the maximum integer which can be shown on the display of Stepan's newest device.
[ "2\n", "3\n" ]
[ "1\n", "7\n" ]
none
[ { "input": "2", "output": "1" }, { "input": "3", "output": "7" }, { "input": "4", "output": "11" }, { "input": "5", "output": "71" }, { "input": "6", "output": "111" }, { "input": "85651", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "85666", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99999", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "100000", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99998", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "9", "output": "7111" }, { "input": "99997", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99996", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99995", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "156", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "255", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "4568", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "5431", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "6782", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "8343", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "9514", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." } ]
202
6,451,200
3
6,819
557
Ilya and Diplomas
[ "greedy", "implementation", "math" ]
null
null
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma. They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree. After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree. Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations. It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree.
The first line of the input contains a single integer *n* (3<=≀<=*n*<=≀<=3Β·106)Β β€”Β the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers *min*1 and *max*1 (1<=≀<=*min*1<=≀<=*max*1<=≀<=106)Β β€”Β the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers *min*2 and *max*2 (1<=≀<=*min*2<=≀<=*max*2<=≀<=106)Β β€”Β the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers *min*3 and *max*3 (1<=≀<=*min*3<=≀<=*max*3<=≀<=106)Β β€”Β the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≀<=*n*<=≀<=*max*1<=+<=*max*2<=+<=*max*3.
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
[ "6\n1 5\n2 6\n3 7\n", "10\n1 2\n1 3\n1 5\n", "6\n1 3\n2 2\n2 2\n" ]
[ "1 2 3 \n", "2 3 5 \n", "2 2 2 \n" ]
none
[ { "input": "6\n1 5\n2 6\n3 7", "output": "1 2 3 " }, { "input": "10\n1 2\n1 3\n1 5", "output": "2 3 5 " }, { "input": "6\n1 3\n2 2\n2 2", "output": "2 2 2 " }, { "input": "55\n1 1000000\n40 50\n10 200", "output": "5 40 10 " }, { "input": "3\n1 1\n1 1\n1 1", "output": "1 1 1 " }, { "input": "3\n1 1000000\n1 1000000\n1 1000000", "output": "1 1 1 " }, { "input": "1000\n100 400\n300 500\n400 1200", "output": "300 300 400 " }, { "input": "3000000\n1 1000000\n1 1000000\n1 1000000", "output": "1000000 1000000 1000000 " }, { "input": "11\n3 5\n3 5\n3 5", "output": "5 3 3 " }, { "input": "12\n3 5\n3 5\n3 5", "output": "5 4 3 " }, { "input": "13\n3 5\n3 5\n3 5", "output": "5 5 3 " }, { "input": "3000000\n1000000 1000000\n1000000 1000000\n1000000 1000000", "output": "1000000 1000000 1000000 " }, { "input": "50\n1 100\n1 100\n1 100", "output": "48 1 1 " }, { "input": "1279\n123 670\n237 614\n846 923", "output": "196 237 846 " }, { "input": "1589\n213 861\n5 96\n506 634", "output": "861 96 632 " }, { "input": "2115\n987 987\n112 483\n437 959", "output": "987 483 645 " }, { "input": "641\n251 960\n34 370\n149 149", "output": "458 34 149 " }, { "input": "1655\n539 539\n10 425\n605 895", "output": "539 425 691 " }, { "input": "1477\n210 336\n410 837\n448 878", "output": "336 693 448 " }, { "input": "1707\n149 914\n190 422\n898 899", "output": "619 190 898 " }, { "input": "1529\n515 515\n563 869\n169 451", "output": "515 845 169 " }, { "input": "1543\n361 994\n305 407\n102 197", "output": "994 407 142 " }, { "input": "1107\n471 849\n360 741\n71 473", "output": "676 360 71 " }, { "input": "1629279\n267360 999930\n183077 674527\n202618 786988", "output": "999930 426731 202618 " }, { "input": "1233589\n2850 555444\n500608 921442\n208610 607343", "output": "524371 500608 208610 " }, { "input": "679115\n112687 183628\n101770 982823\n81226 781340", "output": "183628 414261 81226 " }, { "input": "1124641\n117999 854291\n770798 868290\n76651 831405", "output": "277192 770798 76651 " }, { "input": "761655\n88152 620061\n60403 688549\n79370 125321", "output": "620061 62224 79370 " }, { "input": "2174477\n276494 476134\n555283 954809\n319941 935631", "output": "476134 954809 743534 " }, { "input": "1652707\n201202 990776\n34796 883866\n162979 983308", "output": "990776 498952 162979 " }, { "input": "2065529\n43217 891429\n434379 952871\n650231 855105", "output": "891429 523869 650231 " }, { "input": "1702543\n405042 832833\n50931 747750\n381818 796831", "output": "832833 487892 381818 " }, { "input": "501107\n19061 859924\n126478 724552\n224611 489718", "output": "150018 126478 224611 " }, { "input": "1629279\n850831 967352\n78593 463906\n452094 885430", "output": "967352 209833 452094 " }, { "input": "1233589\n2850 157021\n535109 748096\n392212 475634", "output": "157021 684356 392212 " }, { "input": "679115\n125987 786267\n70261 688983\n178133 976789", "output": "430721 70261 178133 " }, { "input": "1124641\n119407 734250\n213706 860770\n102149 102149", "output": "734250 288242 102149 " }, { "input": "761655\n325539 325539\n280794 792505\n18540 106895", "output": "325539 417576 18540 " }, { "input": "2174477\n352351 791072\n365110 969163\n887448 955610", "output": "791072 495957 887448 " }, { "input": "1652707\n266774 638522\n65688 235422\n924898 992826", "output": "638522 89287 924898 " }, { "input": "2065529\n608515 608515\n751563 864337\n614898 705451", "output": "608515 842116 614898 " }, { "input": "1702543\n5784 996578\n47395 300407\n151614 710197", "output": "996578 300407 405558 " }, { "input": "501107\n8073 390048\n190494 647328\n274071 376923", "output": "36542 190494 274071 " }, { "input": "200\n50 50\n100 100\n50 50", "output": "50 100 50 " }, { "input": "14\n1 100\n1 100\n8 9", "output": "5 1 8 " }, { "input": "300\n200 400\n50 100\n40 80", "output": "210 50 40 " }, { "input": "10\n3 6\n3 6\n3 6", "output": "4 3 3 " }, { "input": "14\n3 6\n3 6\n3 6", "output": "6 5 3 " }, { "input": "17\n3 6\n3 6\n3 6", "output": "6 6 5 " }, { "input": "1000000\n300000 600000\n300000 600000\n300000 600000", "output": "400000 300000 300000 " }, { "input": "1400000\n300000 600000\n300000 600000\n300000 600000", "output": "600000 500000 300000 " }, { "input": "1700000\n300000 600000\n300000 600000\n300000 600000", "output": "600000 600000 500000 " }, { "input": "561\n400 400\n80 80\n81 81", "output": "400 80 81 " }, { "input": "2000\n100 1000\n1 1\n1 2000", "output": "1000 1 999 " }, { "input": "1000002\n1 1000000\n1 1000000\n999999 1000000", "output": "2 1 999999 " }, { "input": "1000002\n1 1000000\n1 1000000\n1000000 1000000", "output": "1 1 1000000 " } ]
31
0
0
6,823
53
Autocomplete
[ "implementation" ]
A. Autocomplete
2
256
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*.
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≀<=*n*<=≀<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' operator in the modern programming languages.
[ "next\n2\nnextpermutation\nnextelement\n", "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n" ]
[ "nextelement\n", "find\n", "find\n" ]
none
[ { "input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find" }, { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find" }, { "input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "output": "kudljmxcse" }, { "input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "output": "ntqwpadm" }, { "input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "output": "aflb" }, { "input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb", "output": "dzwzyji" }, { "input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg" }, { "input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb" }, { "input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld" } ]
62
0
0
6,824
911
Inversion Counting
[ "brute force", "math" ]
null
null
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=1), (4,<=1), (4,<=3). You are given a permutation *a* of size *n* and *m* queries to it. Each query is represented by two indices *l* and *r* denoting that you have to reverse the segment [*l*,<=*r*] of the permutation. For example, if *a*<==<=[1,<=2,<=3,<=4] and a query *l*<==<=2, *r*<==<=4 is applied, then the resulting permutation is [1,<=4,<=3,<=2]. After each query you have to determine whether the number of inversions is odd or even.
The first line contains one integer *n* (1<=≀<=*n*<=≀<=1500) β€” the size of the permutation. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer *m* (1<=≀<=*m*<=≀<=2Β·105) β€” the number of queries to process. Then *m* lines follow, *i*-th line containing two integers *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=*n*) denoting that *i*-th query is to reverse a segment [*l**i*,<=*r**i*] of the permutation. All queries are performed one after another.
Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise.
[ "3\n1 2 3\n2\n1 2\n2 3\n", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n" ]
[ "odd\neven\n", "odd\nodd\nodd\neven\n" ]
The first example: 1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
[ { "input": "3\n1 2 3\n2\n1 2\n2 3", "output": "odd\neven" }, { "input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3", "output": "odd\nodd\nodd\neven" }, { "input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5", "output": "odd\nodd\neven\nodd\neven" }, { "input": "3\n2 1 3\n3\n2 3\n1 1\n1 3", "output": "even\neven\nodd" }, { "input": "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "even\neven\neven\neven\neven\neven\neven\neven\neven\neven" } ]
1,700
21,504,000
3
6,825
24
Ring road
[ "graphs" ]
A. Ring road
2
256
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all *n* roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other?
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*,<=*a**i*<=β‰ <=*b**i*,<=1<=≀<=*c**i*<=≀<=100) β€” road is directed from city *a**i* to city *b**i*, redirecting the traffic costs *c**i*.
Output single integer β€” the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.
[ "3\n1 3 1\n1 2 1\n3 2 1\n", "3\n1 3 1\n1 2 5\n3 2 1\n", "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n", "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n" ]
[ "1\n", "2\n", "39\n", "0\n" ]
none
[ { "input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1" }, { "input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0" }, { "input": "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54", "output": "143" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90", "output": "267" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40", "output": "435" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2", "output": "413" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45", "output": "950" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99", "output": "1117" }, { "input": "3\n3 1 1\n2 1 1\n2 3 1", "output": "1" } ]
248
0
3.938
6,829
328
IQ Test
[ "implementation" ]
null
null
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 and *d* are any numbers. Geometric progression is a sequence *b*1, *b*2<==<=*b*1*q*, ..., *b**n*<==<=*b**n*<=-<=1*q*, where *b*1<=β‰ <=0, *q*<=β‰ <=0, *q*<=β‰ <=1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.
The first line contains exactly four integer numbers between 1 and 1000, inclusively.
Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.
[ "836 624 412 200\n", "1 334 667 1000\n" ]
[ "-12\n", "1333\n" ]
This problem contains very weak pretests!
[ { "input": "836 624 412 200", "output": "-12" }, { "input": "1 334 667 1000", "output": "1333" }, { "input": "501 451 400 350", "output": "42" }, { "input": "836 624 412 200", "output": "-12" }, { "input": "1 334 667 1000", "output": "1333" }, { "input": "11 234 457 680", "output": "903" }, { "input": "640 431 222 13", "output": "-196" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 10 100 1000", "output": "10000" }, { "input": "3 18 108 648", "output": "3888" }, { "input": "512 384 288 216", "output": "162" }, { "input": "891 297 99 33", "output": "11" }, { "input": "64 160 400 1000", "output": "2500" }, { "input": "501 451 400 350", "output": "42" }, { "input": "501 450 400 350", "output": "42" }, { "input": "4 32 48 64", "output": "42" }, { "input": "9 8 7 5", "output": "42" }, { "input": "992 994 998 1000", "output": "42" }, { "input": "2 6 6 8", "output": "42" }, { "input": "2 4 8 8", "output": "42" }, { "input": "2 4 6 14", "output": "42" }, { "input": "2 12 4 14", "output": "42" }, { "input": "2 4 4 2", "output": "42" }, { "input": "1000 100 10 1", "output": "42" }, { "input": "2 9 27 81", "output": "42" }, { "input": "2 4 9 16", "output": "42" }, { "input": "2 4 9 18", "output": "42" }, { "input": "256 64 16 8", "output": "42" }, { "input": "256 385 576 864", "output": "42" }, { "input": "343 147 63 27", "output": "42" }, { "input": "729 648 576 512", "output": "42" }, { "input": "1000 980 960 941", "output": "42" }, { "input": "2 5 10 16", "output": "42" }, { "input": "1 2 3 10", "output": "42" }, { "input": "24 36 54 81", "output": "42" }, { "input": "1 2 4 8", "output": "16" }, { "input": "16 24 36 54", "output": "81" }, { "input": "8 4 2 1", "output": "42" }, { "input": "16 8 4 2", "output": "1" }, { "input": "32 16 8 4", "output": "2" }, { "input": "10 11 12 12", "output": "42" }, { "input": "1 2 10 20", "output": "42" }, { "input": "27 9 3 1", "output": "42" }, { "input": "81 108 144 192", "output": "256" }, { "input": "2 3 4 6", "output": "42" }, { "input": "1000 500 170 40", "output": "42" } ]
0
0
-1
6,834
978
Letters
[ "binary search", "implementation", "two pointers" ]
null
null
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$. A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $n$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $1$ to $a_1 + a_2 + \dots + a_n$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on. For example, in case $n=2$, $a_1=3$ and $a_2=5$ an envelope can have any integer from $1$ to $8$ written on it. If the number $7$ is written on an envelope, it means that the letter should be delivered to the room number $4$ of the second dormitory. For each of $m$ letters by the room number among all $n$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
The first line contains two integers $n$ and $m$ $(1 \le n, m \le 2 \cdot 10^{5})$ β€” the number of dormitories and the number of letters. The second line contains a sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^{10})$, where $a_i$ equals to the number of rooms in the $i$-th dormitory. The third line contains a sequence $b_1, b_2, \dots, b_m$ $(1 \le b_j \le a_1 + a_2 + \dots + a_n)$, where $b_j$ equals to the room number (among all rooms of all dormitories) for the $j$-th letter. All $b_j$ are given in increasing order.
Print $m$ lines. For each letter print two integers $f$ and $k$ β€” the dormitory number $f$ $(1 \le f \le n)$ and the room number $k$ in this dormitory $(1 \le k \le a_f)$ to deliver the letter.
[ "3 6\n10 15 12\n1 9 12 23 26 37\n", "2 3\n5 10000000000\n5 6 9999999999\n" ]
[ "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n", "1 5\n2 1\n2 9999999994\n" ]
In the first example letters should be delivered in the following order: - the first letter in room $1$ of the first dormitory - the second letter in room $9$ of the first dormitory - the third letter in room $2$ of the second dormitory - the fourth letter in room $13$ of the second dormitory - the fifth letter in room $1$ of the third dormitory - the sixth letter in room $12$ of the third dormitory
[ { "input": "3 6\n10 15 12\n1 9 12 23 26 37", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12" }, { "input": "2 3\n5 10000000000\n5 6 9999999999", "output": "1 5\n2 1\n2 9999999994" }, { "input": "1 1\n1\n1", "output": "1 1" }, { "input": "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54 60 61 76 80 81 84 90", "output": "1 1\n1 6\n1 10\n2 1\n2 5\n2 20\n3 1\n3 24\n3 30\n4 1\n4 16\n4 20\n5 1\n5 4\n5 10" }, { "input": "1 10\n10\n1 2 3 4 5 6 7 8 9 10", "output": "1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10" }, { "input": "5 8\n10 1 1 1 10\n9 10 11 12 13 14 15 23", "output": "1 9\n1 10\n2 1\n3 1\n4 1\n5 1\n5 2\n5 10" }, { "input": "1 3\n10000\n1 4325 10000", "output": "1 1\n1 4325\n1 10000" }, { "input": "4 18\n5 6 3 4\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18", "output": "1 1\n1 2\n1 3\n1 4\n1 5\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4" }, { "input": "3 10\n1000000000 1000000000 1000000000\n543678543 567869543 1000000000 1000000001 1500000000 1999999999 2000000000 2000000001 2754432345 3000000000", "output": "1 543678543\n1 567869543\n1 1000000000\n2 1\n2 500000000\n2 999999999\n2 1000000000\n3 1\n3 754432345\n3 1000000000" } ]
1,840
23,756,800
3
6,836
318
Strings of Power
[ "implementation", "strings", "two pointers" ]
null
null
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consecutive characters in a string) in a given text makes our hero especially joyful. Recently he felt an enormous fit of energy while reading a certain text. So Volodya decided to count all powerful substrings in this text and brag about it all day long. Help him in this difficult task. Two substrings are considered different if they appear at the different positions in the text. For simplicity, let us assume that Volodya's text can be represented as a single string.
Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.
Print exactly one number β€” the number of powerful substrings of the given string. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "heavymetalisheavymetal\n", "heavymetalismetal\n", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n" ]
[ "3", "2", "3" ]
In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful. In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".
[ { "input": "heavymetalisheavymetal", "output": "3" }, { "input": "heavymetalismetal", "output": "2" }, { "input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "output": "3" }, { "input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua", "output": "5" }, { "input": "metametaheavyetalalmetalavylkeoheavyhemetaleavycdk", "output": "3" }, { "input": "hg", "output": "0" } ]
966
3,072,000
3
6,839
0
none
[ "none" ]
null
null
This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*. More formally, there is a singly liked list built on an array of *n* elements. Element with index *i* contains two integers: *value**i* is the integer value in this element, and *next**i* that is the index of the next element of the singly linked list (or -1, if the current element is the last). The list is sorted, i.e. if *next**i*<=β‰ <=<=-<=1, then *value**next**i*<=&gt;<=*value**i*. You are given the number of elements in the list *n*, the index of the first element *start*, and the integer *x*. You can make up to 2000 queries of the following two types: - ? i (1<=≀<=*i*<=≀<=*n*)Β β€” ask the values *value**i* and *next**i*, - ! ansΒ β€” give the answer for the problem: the minimum integer, greater than or equal to *x*, or ! -1, if there are no such integers. Your program should terminate after this query. Write a program that solves this problem.
The first line contains three integers *n*, *start*, *x* (1<=≀<=*n*<=≀<=50000, 1<=≀<=*start*<=≀<=*n*, 0<=≀<=*x*<=≀<=109)Β β€” the number of elements in the list, the index of the first element and the integer *x*.
To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to *x*, or -1, if there is no such integer.
[ "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n" ]
[ "? 1\n? 2\n? 3\n? 4\n? 5\n! 81" ]
You can read more about singly linked list by the following link: [https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list](https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list) The illustration for the first sample case. Start and finish elements are marked dark. <img class="tex-graphics" src="https://espresso.codeforces.com/5202ec3b5e896b7db692ff7b80457c26cf6adb32.png" style="max-width: 100.0%;max-height: 100.0%;"/>
[ { "input": "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4", "output": "81\n1003" }, { "input": "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1", "output": "-1\n1002" }, { "input": "1 1 0\n0 -1", "output": "0\n2" }, { "input": "1 1 2\n0 -1", "output": "-1\n1002" }, { "input": "1 1 1000000000\n0 -1", "output": "-1\n1002" }, { "input": "5 3 3\n3 5\n2 1\n0 4\n1 2\n4 -1", "output": "3\n1003" }, { "input": "5 3 145337745\n619347297 5\n344132479 1\n122841322 4\n169280018 2\n740666615 -1", "output": "169280018\n1003" }, { "input": "5 3 315433300\n411188472 5\n316581280 1\n200698791 4\n314885421 2\n759386148 -1", "output": "316581280\n1003" }, { "input": "5 3 381735506\n469559901 5\n359493082 1\n137017061 4\n202768106 2\n955698260 -1", "output": "469559901\n1003" }, { "input": "5 3 587634055\n563214082 5\n404100743 1\n179733654 4\n236438578 2\n673892808 -1", "output": "673892808\n1003" }, { "input": "5 3 974128233\n547205043 5\n318213550 1\n122625404 4\n184874700 2\n669820978 -1", "output": "-1\n1002" }, { "input": "10 3 2\n3 9\n9 -1\n0 7\n6 8\n5 4\n8 2\n1 10\n7 6\n4 5\n2 1", "output": "2\n1003" }, { "input": "10 3 632584719\n378382911 9\n978367651 -1\n176599346 7\n557138623 8\n441019502 4\n823417558 2\n244832688 10\n702148024 6\n385598339 5\n357778234 1", "output": "702148024\n1003" }, { "input": "1 1 50\n60 -1", "output": "60\n2" }, { "input": "5 1 100\n200 2\n300 3\n400 4\n500 5\n600 -1", "output": "200\n2" } ]
78
921,600
0
6,871
887
Ratings and Reality Shows
[ "data structures", "two pointers" ]
null
null
There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by *a* and after each fashion show decreases by *b* (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become *c* and decreasing of her rating after fashion show becomes *d*. Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show. Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to *start*. If talk show happens in moment *t* if will affect all events in model's life in interval of time [*t*..*t*<=+<=*len*) (including *t* and not including *t*<=+<=*len*), where *len* is duration of influence. Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.
In first line there are 7 positive integers *n*, *a*, *b*, *c*, *d*, *start*, *len* (1<=≀<=*n*<=≀<=3Β·105, 0<=≀<=*start*<=≀<=109, 1<=≀<=*a*,<=*b*,<=*c*,<=*d*,<=*len*<=≀<=109), where *n* is a number of fashion shows and photo shoots, *a*, *b*, *c* and *d* are rating changes described above, *start* is an initial rating of model and *len* is a duration of influence of talk show. In next *n* lines descriptions of events are given. Each of those lines contains two integers *t**i* and *q**i* (1<=≀<=*t**i*<=≀<=109, 0<=≀<=*q*<=≀<=1)Β β€” moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1Β β€” to photo shoot. Events are given in order of increasing *t**i*, all *t**i* are different.
Print one non-negative integer *t*Β β€” the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print <=-<=1.
[ "5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0\n", "1 1 2 1 2 1 2\n1 0\n" ]
[ "6", "-1" ]
none
[ { "input": "5 1 1 1 4 0 5\n1 1\n2 1\n3 1\n4 0\n5 0", "output": "6" }, { "input": "1 1 2 1 2 1 2\n1 0", "output": "-1" }, { "input": "10 1 1 1 2 0 10\n1 1\n2 1\n3 0\n4 0\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1", "output": "5" } ]
61
0
0
6,877
687
The Values You Can Make
[ "dp" ]
null
null
Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and give it to Arya. Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the values *x*, such that Arya will be able to make *x* using some subset of coins with the sum *k*. Formally, Pari wants to know the values *x* such that there exists a subset of coins with the sum *k* such that some subset of this subset has the sum *x*, i.e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sum *x* using these coins.
The first line contains two integers *n* and *k* (1<=<=≀<=<=*n*,<=*k*<=<=≀<=<=500)Β β€” the number of coins and the price of the chocolate, respectively. Next line will contain *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=500)Β β€” the values of Pari's coins. It's guaranteed that one can make value *k* using these coins.
First line of the output must contain a single integer *q*β€” the number of suitable values *x*. Then print *q* integers in ascending orderΒ β€” the values that Arya can make for some subset of coins of Pari that pays for the chocolate.
[ "6 18\n5 6 1 10 12 2\n", "3 50\n25 25 50\n" ]
[ "16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 \n", "3\n0 25 50 \n" ]
none
[ { "input": "6 18\n5 6 1 10 12 2", "output": "16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 " }, { "input": "3 50\n25 25 50", "output": "3\n0 25 50 " }, { "input": "1 79\n79", "output": "2\n0 79 " }, { "input": "1 114\n114", "output": "2\n0 114 " }, { "input": "5 1\n1 500 205 6 355", "output": "2\n0 1 " }, { "input": "8 42\n7 24 22 25 31 12 17 26", "output": "4\n0 17 25 42 " }, { "input": "8 91\n74 25 66 50 62 30 50 50", "output": "4\n0 25 66 91 " }, { "input": "8 15\n13 3 5 5 6 14 5 5", "output": "4\n0 5 10 15 " }, { "input": "8 39\n38 17 25 33 7 29 15 22", "output": "8\n0 7 15 17 22 24 32 39 " }, { "input": "15 185\n69 61 185 127 169 42 140 93 12 115 36 46 19 80 123", "output": "34\n0 12 19 31 36 42 46 55 58 61 69 73 78 80 82 88 92 93 97 103 105 107 112 116 124 127 130 139 143 149 154 166 173 185 " }, { "input": "15 109\n92 60 14 9 22 99 17 22 82 28 105 98 109 20 32", "output": "28\n0 17 20 22 28 32 37 39 42 44 45 48 49 50 59 60 61 64 65 67 70 72 77 81 87 89 92 109 " }, { "input": "10 147\n15 76 48 111 39 111 145 16 34 68", "output": "16\n0 15 16 31 48 63 64 68 79 83 84 99 116 131 132 147 " }, { "input": "10 67\n58 39 56 7 51 47 20 26 24 54", "output": "4\n0 20 47 67 " }, { "input": "10 195\n157 4 183 125 63 121 113 3 145 103", "output": "16\n0 3 4 7 63 66 67 70 125 128 129 132 188 191 192 195 " }, { "input": "14 176\n66 109 148 141 65 52 147 65 171 11 157 60 151 19", "output": "4\n0 19 157 176 " }, { "input": "14 54\n54 39 2 16 17 18 41 22 25 30 54 4 27 2", "output": "23\n0 2 4 6 8 16 18 20 22 24 25 27 29 30 32 34 36 38 46 48 50 52 54 " }, { "input": "14 24\n18 16 15 24 18 19 19 8 8 2 4 9 18 9", "output": "14\n0 2 4 6 8 9 11 13 15 16 18 20 22 24 " }, { "input": "5 182\n134 18 48 91 25", "output": "15\n0 18 25 43 48 66 73 91 109 116 134 139 157 164 182 " }, { "input": "15 182\n63 17 134 113 18 48 112 175 91 25 176 55 78 177 175", "output": "15\n0 18 25 43 48 66 73 91 109 116 134 139 157 164 182 " }, { "input": "5 6\n2 71 7 27 6", "output": "2\n0 6 " }, { "input": "5 34\n28 32 91 6 70", "output": "4\n0 6 28 34 " }, { "input": "10 58\n57 2 18 35 3 35 38 7 38 3", "output": "16\n0 2 3 5 18 20 21 23 35 37 38 40 53 55 56 58 " }, { "input": "10 10\n7 4 6 2 9 6 8 8 10 10", "output": "6\n0 2 4 6 8 10 " }, { "input": "10 38\n16 21 7 12 20 37 34 7 6 20", "output": "8\n0 6 12 18 20 26 32 38 " }, { "input": "10 58\n30 51 7 29 25 2 44 28 49 45", "output": "10\n0 2 7 9 28 30 49 51 56 58 " }, { "input": "10 86\n64 5 30 53 65 24 32 36 23 23", "output": "8\n0 24 30 32 54 56 62 86 " }, { "input": "10 10\n5 10 10 10 2 3 4 7 3 5", "output": "9\n0 2 3 4 5 6 7 8 10 " }, { "input": "10 34\n1 28 14 4 11 24 4 11 7 28", "output": "24\n0 1 4 5 7 8 9 11 12 14 15 16 18 19 20 22 23 25 26 27 29 30 33 34 " }, { "input": "10 58\n20 25 11 37 4 48 20 54 2 26", "output": "18\n0 2 4 11 13 20 22 25 27 31 33 36 38 45 47 54 56 58 " }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "2\n0 1 " }, { "input": "9 457\n1 2 4 8 16 32 64 128 256", "output": "32\n0 1 8 9 64 65 72 73 128 129 136 137 192 193 200 201 256 257 264 265 320 321 328 329 384 385 392 393 448 449 456 457 " }, { "input": "9 436\n1 2 4 8 16 32 64 128 256", "output": "32\n0 4 16 20 32 36 48 52 128 132 144 148 160 164 176 180 256 260 272 276 288 292 304 308 384 388 400 404 416 420 432 436 " }, { "input": "9 474\n1 2 4 8 16 32 64 128 256", "output": "64\n0 2 8 10 16 18 24 26 64 66 72 74 80 82 88 90 128 130 136 138 144 146 152 154 192 194 200 202 208 210 216 218 256 258 264 266 272 274 280 282 320 322 328 330 336 338 344 346 384 386 392 394 400 402 408 410 448 450 456 458 464 466 472 474 " }, { "input": "9 442\n1 2 4 8 16 32 64 128 256", "output": "64\n0 2 8 10 16 18 24 26 32 34 40 42 48 50 56 58 128 130 136 138 144 146 152 154 160 162 168 170 176 178 184 186 256 258 264 266 272 274 280 282 288 290 296 298 304 306 312 314 384 386 392 394 400 402 408 410 416 418 424 426 432 434 440 442 " }, { "input": "15 388\n33 232 106 369 266 135 22 169 367 37 14 181 232 25 154", "output": "59\n0 14 22 25 33 37 39 47 51 58 59 62 70 72 84 135 149 157 160 168 169 172 174 181 182 183 186 191 193 194 195 197 202 205 206 207 214 216 219 220 228 231 239 253 304 316 318 326 329 330 337 341 349 351 355 363 366 374 388 " }, { "input": "10 9\n5 2 5 2 5 1 4 1 3 1", "output": "10\n0 1 2 3 4 5 6 7 8 9 " } ]
2,000
182,681,600
0
6,892
911
Three Garlands
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state β€” sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one β€” during *x*2-th second, and the third one β€” during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this!
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≀<=*k**i*<=≀<=1500) β€” time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second β€” 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" }, { "input": "3 3 3", "output": "YES" }, { "input": "2 3 6", "output": "NO" }, { "input": "2 3 3", "output": "NO" }, { "input": "4 4 2", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "2 11 2", "output": "YES" }, { "input": "4 4 4", "output": "NO" }, { "input": "4 4 5", "output": "NO" }, { "input": "3 3 2", "output": "NO" }, { "input": "3 6 6", "output": "NO" }, { "input": "2 3 2", "output": "YES" }, { "input": "1 1 3", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "2 4 4", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "2 10 10", "output": "NO" }, { "input": "3 4 4", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "2 4 5", "output": "NO" }, { "input": "228 2 2", "output": "YES" }, { "input": "2 998 1000", "output": "NO" }, { "input": "2 6 6", "output": "NO" }, { "input": "6 4 7", "output": "NO" }, { "input": "2 5 2", "output": "YES" }, { "input": "2 100 100", "output": "NO" }, { "input": "7 7 2", "output": "NO" }, { "input": "3 3 6", "output": "NO" }, { "input": "82 3 82", "output": "NO" }, { "input": "2 3 5", "output": "NO" }, { "input": "1 218 924", "output": "YES" }, { "input": "4 4 123", "output": "NO" }, { "input": "4 4 3", "output": "NO" }, { "input": "3 4 2", "output": "NO" }, { "input": "2 2 5", "output": "YES" }, { "input": "2 10 2", "output": "YES" }, { "input": "5 2 2", "output": "YES" }, { "input": "3 3 9", "output": "NO" }, { "input": "1 5 5", "output": "YES" }, { "input": "2 4 6", "output": "NO" }, { "input": "15 3 3", "output": "NO" }, { "input": "1 5 10", "output": "YES" }, { "input": "2 3 14", "output": "NO" }, { "input": "1265 2 593", "output": "NO" }, { "input": "2 2 567", "output": "YES" }, { "input": "1 6 5", "output": "YES" }, { "input": "2 2 7", "output": "YES" }, { "input": "2 2 1500", "output": "YES" }, { "input": "3 6 9", "output": "NO" }, { "input": "1 46 79", "output": "YES" }, { "input": "4 3 3", "output": "NO" }, { "input": "2 4 8", "output": "NO" }, { "input": "1493 1489 1487", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "1 2 5", "output": "YES" }, { "input": "1 2 8", "output": "YES" }, { "input": "3 4 5", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "3 2 3", "output": "NO" }, { "input": "7 2 2", "output": "YES" }, { "input": "3 2 2", "output": "YES" }, { "input": "6 7 4", "output": "NO" } ]
109
20,377,600
0
6,894
38
Chess
[ "brute force", "implementation", "math" ]
B. Chess
2
256
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=Γ—<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.
The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.
Print a single number which is the required number of ways.
[ "a1\nb2\n", "a8\nd4\n" ]
[ "44\n", "38\n" ]
none
[ { "input": "a1\nb2", "output": "44" }, { "input": "a8\nd4", "output": "38" }, { "input": "a8\nf1", "output": "42" }, { "input": "f8\nh3", "output": "42" }, { "input": "g8\nb7", "output": "42" }, { "input": "h1\ng5", "output": "42" }, { "input": "c6\nb5", "output": "39" }, { "input": "c1\nd2", "output": "42" }, { "input": "g3\nh4", "output": "42" }, { "input": "e3\ng5", "output": "38" }, { "input": "f8\na3", "output": "40" }, { "input": "a2\nh8", "output": "43" }, { "input": "a3\nc5", "output": "40" }, { "input": "g1\ne6", "output": "39" }, { "input": "e1\na7", "output": "41" }, { "input": "b5\nc1", "output": "39" }, { "input": "b2\ne1", "output": "43" }, { "input": "h8\ng2", "output": "43" }, { "input": "a3\nd6", "output": "38" }, { "input": "g6\nb7", "output": "39" }, { "input": "c8\ne6", "output": "40" }, { "input": "e6\nf2", "output": "35" }, { "input": "b6\nd8", "output": "41" }, { "input": "a4\nd1", "output": "42" }, { "input": "b5\nh8", "output": "40" }, { "input": "h6\na1", "output": "42" }, { "input": "c3\na8", "output": "39" }, { "input": "g5\nd2", "output": "38" }, { "input": "b6\ng7", "output": "39" }, { "input": "h6\na8", "output": "43" }, { "input": "a8\nb7", "output": "44" }, { "input": "c8\nb2", "output": "41" }, { "input": "e4\nc1", "output": "37" }, { "input": "f1\nc3", "output": "38" }, { "input": "a3\nc8", "output": "41" }, { "input": "e8\nb6", "output": "40" }, { "input": "a1\nb7", "output": "43" }, { "input": "g2\nb7", "output": "40" }, { "input": "e1\nd6", "output": "38" }, { "input": "e5\nh6", "output": "39" } ]
342
20,684,800
3.875972
6,896
424
Biathlon Track
[ "binary search", "brute force", "constructive algorithms", "data structures", "dp" ]
null
null
Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessary Olympic facilities as early as possible. First, a biathlon track will be built. To construct a biathlon track a plot of land was allocated, which is a rectangle divided into *n*<=Γ—<=*m* identical squares. Each of the squares has two coordinates: the number of the row (from 1 to *n*), where it is located, the number of the column (from 1 to *m*), where it is located. Also each of the squares is characterized by its height. During the sports the biathletes will have to move from one square to another. If a biathlete moves from a higher square to a lower one, he makes a descent. If a biathlete moves from a lower square to a higher one, he makes an ascent. If a biathlete moves between two squares with the same height, then he moves on flat ground. The biathlon track should be a border of some rectangular area of the allocated land on which biathletes will move in the clockwise direction. It is known that on one move on flat ground an average biathlete spends *t**p* seconds, an ascent takes *t**u* seconds, a descent takes *t**d* seconds. The Tomsk Administration wants to choose the route so that the average biathlete passes it in as close to *t* seconds as possible. In other words, the difference between time *t**s* of passing the selected track and *t* should be minimum. For a better understanding you can look at the first sample of the input data. In this sample *n*<==<=6,<=*m*<==<=7, and the administration wants the track covering time to be as close to *t*<==<=48 seconds as possible, also, *t**p*<==<=3, *t**u*<==<=6 and *t**d*<==<=2. If we consider the rectangle shown on the image by arrows, the average biathlete can move along the boundary in a clockwise direction in exactly 48 seconds. The upper left corner of this track is located in the square with the row number 4, column number 3 and the lower right corner is at square with row number 6, column number 7. Among other things the administration wants all sides of the rectangle which boundaries will be the biathlon track to consist of no less than three squares and to be completely contained within the selected land. You are given the description of the given plot of land and all necessary time values. You are to write the program to find the most suitable rectangle for a biathlon track. If there are several such rectangles, you are allowed to print any of them.
The first line of the input contains three integers *n*, *m* and *t* (3<=≀<=*n*,<=*m*<=≀<=300, 1<=≀<=*t*<=≀<=109) β€” the sizes of the land plot and the desired distance covering time. The second line also contains three integers *t**p*, *t**u* and *t**d* (1<=≀<=*t**p*,<=*t**u*,<=*t**d*<=≀<=100) β€” the time the average biathlete needs to cover a flat piece of the track, an ascent and a descent respectively. Then *n* lines follow, each line contains *m* integers that set the heights of each square of the given plot of land. Each of the height values is a positive integer, not exceeding 106.
In a single line of the output print four positive integers β€” the number of the row and the number of the column of the upper left corner and the number of the row and the number of the column of the lower right corner of the rectangle that is chosen for the track.
[ "6 7 48\n3 6 2\n5 4 8 3 3 7 9\n4 1 6 8 7 1 1\n1 6 4 6 4 8 6\n7 2 6 1 6 9 4\n1 9 8 6 3 9 2\n4 5 6 8 4 3 7" ]
[ "4 3 6 7\n" ]
none
[]
62
0
0
6,899
0
none
[ "none" ]
null
null
The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and *n* columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field. All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel. Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.
Each test contains from one to ten sets of the input data. The first line of the test contains a single integer *t* (1<=≀<=*t*<=≀<=10 for pretests and tests or *t*<==<=1 for hacks; see the Notes section for details) β€” the number of sets. Then follows the description of *t* sets of the input data. The first line of the description of each set contains two integers *n*,<=*k* (2<=≀<=*n*<=≀<=100,<=1<=≀<=*k*<=≀<=26) β€” the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of *n* character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the *k* trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.
For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.
[ "2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n", "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n" ]
[ "YES\nNO\n", "YES\nNO\n" ]
In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel. Note that in this problem the challenges are restricted to tests that contain only one testset.
[]
46
0
0
6,901
0
none
[ "none" ]
null
null
Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis. Petya decided to compress tables. He is given a table *a* consisting of *n* rows and *m* columns that is filled with positive integers. He wants to build the table *a*' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row *i* of the initial table *a**i*,<=*j*<=&lt;<=*a**i*,<=*k*, then in the resulting table *a*'*i*,<=*j*<=&lt;<=*a*'*i*,<=*k*, and if *a**i*,<=*j*<==<=*a**i*,<=*k* then *a*'*i*,<=*j*<==<=*a*'*i*,<=*k*. Similarly, if in some column *j* of the initial table *a**i*,<=*j*<=&lt;<=*a**p*,<=*j* then in compressed table *a*'*i*,<=*j*<=&lt;<=*a*'*p*,<=*j* and if *a**i*,<=*j*<==<=*a**p*,<=*j* then *a*'*i*,<=*j*<==<=*a*'*p*,<=*j*. Because large values require more space to store them, the maximum value in *a*' should be as small as possible. Petya is good in theory, however, he needs your help to implement the algorithm.
The first line of the input contains two integers *n* and *m* (, the number of rows and the number of columns of the table respectively. Each of the following *n* rows contain *m* integers *a**i*,<=*j* (1<=≀<=*a**i*,<=*j*<=≀<=109) that are the values in the table.
Output the compressed table in form of *n* lines each containing *m* integers. If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.
[ "2 2\n1 2\n3 4\n", "4 3\n20 10 30\n50 40 30\n50 60 70\n90 80 70\n" ]
[ "1 2\n2 3\n", "2 1 3\n5 4 3\n5 6 7\n9 8 7\n" ]
In the first sample test, despite the fact *a*<sub class="lower-index">1, 2</sub> ≠ *a*<sub class="lower-index">21</sub>, they are not located in the same row or column so they may become equal after the compression.
[]
46
0
0
6,903
893
Credit Card
[ "data structures", "dp", "greedy", "implementation" ]
null
null
Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of *i*-th day a transaction *a**i* occurs. If *a**i*<=&gt;<=0, then *a**i* bourles are deposited to Luba's account. If *a**i*<=&lt;<=0, then *a**i* bourles are withdrawn. And if *a**i*<==<=0, then the amount of money on Luba's account is checked. In the morning of any of *n* days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed *d*. It can happen that the amount of money goes greater than *d* by some transaction in the evening. In this case answer will be Β«-1Β». Luba must not exceed this limit, and also she wants that every day her account is checked (the days when *a**i*<==<=0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
The first line contains two integers *n*, *d* (1<=≀<=*n*<=≀<=105, 1<=≀<=*d*<=≀<=109) β€”the number of days and the money limitation. The second line contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (<=-<=104<=≀<=*a**i*<=≀<=104), where *a**i* represents the transaction in *i*-th day.
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
[ "5 10\n-1 5 0 -5 3\n", "3 4\n-10 0 20\n", "5 10\n-5 0 10 -11 0\n" ]
[ "0\n", "-1\n", "2\n" ]
none
[ { "input": "5 10\n-1 5 0 -5 3", "output": "0" }, { "input": "3 4\n-10 0 20", "output": "-1" }, { "input": "5 10\n-5 0 10 -11 0", "output": "2" }, { "input": "5 13756\n-2 -9 -10 0 10", "output": "1" }, { "input": "20 23036\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1", "output": "1" }, { "input": "12 82016\n1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2", "output": "1" }, { "input": "7 8555\n-2 -3 -2 3 0 -2 0", "output": "1" }, { "input": "16 76798\n-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10", "output": "1" }, { "input": "20 23079\n0 1 1 -1 1 0 -1 -1 0 0 1 -1 1 1 1 0 0 1 0 1", "output": "0" }, { "input": "19 49926\n-2 0 2 0 0 -2 2 -1 -1 0 0 0 1 0 1 1 -2 2 2", "output": "1" }, { "input": "19 78701\n1 0 -1 0 -1 -1 0 1 0 -1 1 1 -1 1 0 0 -1 0 0", "output": "1" }, { "input": "10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2", "output": "1" }, { "input": "9 13\n6 14 19 5 -5 6 -10 20 8", "output": "-1" }, { "input": "8 11\n12 -12 -9 3 -22 -21 1 3", "output": "-1" }, { "input": "8 26\n-4 9 -14 -11 0 7 23 -15", "output": "-1" }, { "input": "5 10\n-8 -24 0 -22 12", "output": "1" }, { "input": "10 23\n9 7 14 16 -13 -22 24 -3 -12 14", "output": "-1" }, { "input": "8 9\n6 -1 5 -5 -8 -7 -8 -7", "output": "-1" }, { "input": "3 14\n12 12 -8", "output": "-1" }, { "input": "9 9\n-3 2 0 -2 -7 -1 0 5 3", "output": "2" }, { "input": "4 100\n-100 0 -50 100", "output": "1" }, { "input": "9 5\n-2 0 3 -4 0 4 -3 -2 0", "output": "1" }, { "input": "7 4\n-6 0 2 -3 0 4 0", "output": "1" }, { "input": "6 2\n-2 3 0 -2 0 0", "output": "1" }, { "input": "1 1\n2", "output": "-1" }, { "input": "5 4\n-1 0 -3 0 3", "output": "1" }, { "input": "7 3\n1 -3 0 3 -1 0 2", "output": "-1" }, { "input": "4 4\n2 2 0 1", "output": "-1" }, { "input": "6 1\n-3 0 0 0 -2 3", "output": "1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 3\n2 0", "output": "0" }, { "input": "5 4\n-1 0 0 1 -1", "output": "1" }, { "input": "6 4\n-1 0 2 -4 0 5", "output": "-1" } ]
77
0
0
6,908
142
Help General
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot had a major argument with the Fairy Godmother (there were rumors that the argument occurred after the general spoke badly of the Godmother's flying techniques. That seemed to hurt the Fairy Godmother very deeply). As the result of the argument, the Godmother put a rather strange curse upon the general. It sounded all complicated and quite harmless: "If the squared distance between some two soldiers equals to 5, then those soldiers will conflict with each other!" The drill exercises are held on a rectangular *n*<=Γ—<=*m* field, split into *nm* square 1<=Γ—<=1 segments for each soldier. Thus, the square of the distance between the soldiers that stand on squares (*x*1,<=*y*1) and (*x*2,<=*y*2) equals exactly (*x*1<=-<=*x*2)2<=+<=(*y*1<=-<=*y*2)2. Now not all *nm* squad soldiers can participate in the drill exercises as it was before the Fairy Godmother's curse. Unless, of course, the general wants the soldiers to fight with each other or even worse... For example, if he puts a soldier in the square (2,<=2), then he cannot put soldiers in the squares (1,<=4), (3,<=4), (4,<=1) and (4,<=3) β€” each of them will conflict with the soldier in the square (2,<=2). Your task is to help the general. You are given the size of the drill exercise field. You are asked to calculate the maximum number of soldiers that can be simultaneously positioned on this field, so that no two soldiers fall under the Fairy Godmother's curse.
The single line contains space-separated integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000) that represent the size of the drill exercise field.
Print the desired maximum number of warriors.
[ "2 4\n", "3 4\n" ]
[ "4", "6" ]
In the first sample test Sir Lancelot can place his 4 soldiers on the 2 × 4 court as follows (the soldiers' locations are marked with gray circles on the scheme): In the second sample test he can place 6 soldiers on the 3 × 4 site in the following manner:
[ { "input": "2 4", "output": "4" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "4 3", "output": "6" }, { "input": "4 2", "output": "4" }, { "input": "1 1", "output": "1" }, { "input": "3 5", "output": "8" }, { "input": "5 3", "output": "8" }, { "input": "506 44", "output": "11132" }, { "input": "555 349", "output": "96848" }, { "input": "757 210", "output": "79485" }, { "input": "419 503", "output": "105379" }, { "input": "515 19", "output": "4893" }, { "input": "204 718", "output": "73236" }, { "input": "862 330", "output": "142230" }, { "input": "494 982", "output": "242554" }, { "input": "967 4", "output": "1934" }, { "input": "449 838", "output": "188131" }, { "input": "635 458", "output": "145415" }, { "input": "156 911", "output": "71058" }, { "input": "409 295", "output": "60328" }, { "input": "755 458", "output": "172895" }, { "input": "936 759", "output": "355212" }, { "input": "771 460", "output": "177330" }, { "input": "563 802", "output": "225763" }, { "input": "953 874", "output": "416461" }, { "input": "354 720", "output": "127440" }, { "input": "915 72", "output": "32940" }, { "input": "860 762", "output": "327660" }, { "input": "396 387", "output": "76626" }, { "input": "675 710", "output": "239625" }, { "input": "728 174", "output": "63336" }, { "input": "883 312", "output": "137748" }, { "input": "701 600", "output": "210300" }, { "input": "824 729", "output": "300348" }, { "input": "886 80", "output": "35440" }, { "input": "762 742", "output": "282702" }, { "input": "781 586", "output": "228833" }, { "input": "44 343", "output": "7546" }, { "input": "847 237", "output": "100370" }, { "input": "169 291", "output": "24590" }, { "input": "961 61", "output": "29311" }, { "input": "695 305", "output": "105988" }, { "input": "854 503", "output": "214781" }, { "input": "1 744", "output": "744" }, { "input": "1 383", "output": "383" }, { "input": "1 166", "output": "166" }, { "input": "557 1", "output": "557" }, { "input": "650 1", "output": "650" }, { "input": "1 995", "output": "995" }, { "input": "1 865", "output": "865" }, { "input": "1 393", "output": "393" }, { "input": "363 1", "output": "363" }, { "input": "1 506", "output": "506" }, { "input": "2 348", "output": "348" }, { "input": "583 2", "output": "584" }, { "input": "2 89", "output": "90" }, { "input": "576 2", "output": "576" }, { "input": "180 2", "output": "180" }, { "input": "719 2", "output": "720" }, { "input": "2 951", "output": "952" }, { "input": "313 2", "output": "314" }, { "input": "433 2", "output": "434" }, { "input": "804 2", "output": "804" }, { "input": "1 991", "output": "991" }, { "input": "1 992", "output": "992" }, { "input": "1 993", "output": "993" }, { "input": "994 1", "output": "994" }, { "input": "995 1", "output": "995" }, { "input": "996 1", "output": "996" }, { "input": "997 1", "output": "997" }, { "input": "1 998", "output": "998" }, { "input": "1 999", "output": "999" }, { "input": "1 1000", "output": "1000" }, { "input": "991 2", "output": "992" }, { "input": "2 992", "output": "992" }, { "input": "993 2", "output": "994" }, { "input": "994 2", "output": "996" }, { "input": "995 2", "output": "996" }, { "input": "2 996", "output": "996" }, { "input": "997 2", "output": "998" }, { "input": "2 998", "output": "1000" }, { "input": "2 999", "output": "1000" }, { "input": "2 1000", "output": "1000" }, { "input": "997 997", "output": "497005" }, { "input": "997 998", "output": "497503" }, { "input": "997 999", "output": "498002" }, { "input": "997 1000", "output": "498500" }, { "input": "998 997", "output": "497503" }, { "input": "998 998", "output": "498002" }, { "input": "998 999", "output": "498501" }, { "input": "998 1000", "output": "499000" }, { "input": "999 997", "output": "498002" }, { "input": "999 998", "output": "498501" }, { "input": "999 999", "output": "499001" }, { "input": "999 1000", "output": "499500" }, { "input": "1000 997", "output": "498500" }, { "input": "1000 998", "output": "499000" }, { "input": "1000 999", "output": "499500" }, { "input": "1000 1000", "output": "500000" }, { "input": "3 3", "output": "5" }, { "input": "1 2", "output": "2" }, { "input": "2 2", "output": "4" } ]
248
2,252,800
-1
6,920
592
Super M
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are *m* cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces. However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once. You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces.
The first line of the input contains two integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow *n*<=-<=1 lines, describing the road system. Each line contains two city numbers *u**i* and *v**i* (1<=≀<=*u**i*,<=*v**i*<=≀<=*n*) - the ends of the road *i*. The last line contains *m* distinct integers - numbers of cities being attacked. These numbers are given in no particular order.
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique.
[ "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n" ]
[ "2\n3\n", "2\n4\n" ]
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/93d3c0306b529e9c2324f68158ca2156587473a2.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df80aa84591eaa7b9f52c88cc43b5f7da5bfead3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. However, you should choose the first one as it starts in the city with the lower number.
[ { "input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3" }, { "input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4" }, { "input": "2 1\n2 1\n1", "output": "1\n0" }, { "input": "1 1\n1", "output": "1\n0" }, { "input": "10 2\n6 9\n6 2\n1 6\n4 10\n3 7\n9 4\n9 5\n6 7\n2 8\n7 6", "output": "6\n1" }, { "input": "15 2\n7 12\n13 11\n6 8\n2 15\n10 9\n5 1\n13 5\n5 4\n14 3\n8 9\n8 4\n4 7\n12 14\n5 2\n7 4", "output": "4\n1" }, { "input": "20 2\n1 16\n12 5\n15 19\n18 9\n8 4\n10 16\n9 16\n20 15\n14 19\n7 4\n18 12\n17 12\n2 20\n6 14\n3 19\n7 19\n18 15\n19 13\n9 11\n12 18", "output": "12\n1" }, { "input": "4 2\n4 3\n3 1\n1 2\n3 4", "output": "3\n1" }, { "input": "8 5\n2 5\n1 8\n6 7\n3 4\n6 8\n8 5\n5 3\n1 6 7 3 8", "output": "3\n6" }, { "input": "16 8\n16 12\n16 15\n15 9\n15 13\n16 3\n15 2\n15 10\n1 2\n6 16\n5 15\n2 7\n15 4\n14 15\n11 16\n8 5\n5 10 14 6 8 3 1 9", "output": "1\n16" }, { "input": "32 28\n30 12\n30 27\n24 32\n6 13\n11 5\n4 30\n8 28\n9 20\n8 20\n7 20\n5 30\n18 5\n20 14\n23 20\n17 20\n8 26\n20 1\n15 2\n20 13\n24 20\n22 24\n25 16\n2 3\n19 5\n16 10\n31 2\n29 5\n20 16\n2 20\n5 21\n5 20\n32 11 6 12 22 30 23 21 14 13 1 20 7 25 9 29 10 27 5 19 24 31 15 26 8 3 28 17", "output": "3\n53" }, { "input": "10 3\n10 5\n3 2\n6 8\n1 5\n10 4\n6 1\n9 8\n2 9\n7 3\n3 9 1", "output": "1\n5" }, { "input": "7 5\n6 4\n5 6\n6 7\n2 3\n5 2\n2 1\n4 6 1 7 3", "output": "1\n8" }, { "input": "15 7\n5 4\n12 5\n7 13\n10 11\n3 8\n6 12\n3 15\n1 3\n5 14\n7 9\n1 10\n6 1\n12 7\n10 2\n4 10 8 13 1 7 9", "output": "4\n14" }, { "input": "31 16\n3 25\n8 1\n1 9\n1 23\n16 15\n10 6\n25 30\n20 29\n2 24\n3 7\n19 22\n2 12\n16 4\n7 26\n31 10\n17 13\n25 21\n7 18\n28 2\n6 27\n19 5\n13 3\n17 31\n10 16\n20 14\n8 19\n6 11\n28 20\n13 28\n31 8\n31 27 25 20 26 8 28 15 18 17 10 23 4 16 30 22", "output": "4\n34" }, { "input": "63 20\n35 26\n54 5\n32 56\n56 53\n59 46\n37 31\n46 8\n4 1\n2 47\n59 42\n55 11\n62 6\n30 7\n60 24\n41 36\n34 22\n24 34\n21 2\n12 52\n8 44\n60 21\n24 30\n48 35\n48 25\n32 57\n20 37\n11 54\n11 62\n42 58\n31 43\n12 23\n55 48\n51 55\n41 27\n25 33\n21 18\n42 12\n4 15\n51 60\n62 39\n46 41\n57 9\n30 61\n31 4\n58 13\n34 29\n37 32\n18 16\n57 45\n2 49\n40 51\n43 17\n40 20\n20 59\n8 19\n58 10\n43 63\n54 50\n18 14\n25 38\n56 28\n35 3\n41 36 18 28 54 22 20 6 23 38 33 52 48 44 29 56 63 4 27 50", "output": "6\n66" }, { "input": "4 2\n2 3\n2 1\n2 4\n3 4", "output": "3\n2" }, { "input": "13 11\n4 11\n2 7\n4 13\n8 12\n8 9\n8 6\n3 8\n4 1\n2 10\n2 5\n3 4\n3 2\n10 4 5 6 1 2 3 9 13 7 12", "output": "1\n18" }, { "input": "7 5\n1 5\n4 1\n1 3\n7 1\n1 6\n1 2\n2 4 1 3 7", "output": "2\n6" }, { "input": "12 9\n11 12\n1 10\n1 7\n5 6\n8 7\n9 8\n4 5\n1 4\n2 3\n1 2\n10 11\n4 9 11 3 5 12 8 6 7", "output": "6\n16" }, { "input": "56 34\n7 31\n47 6\n13 4\n51 29\n13 12\n10 52\n10 41\n1 47\n47 54\n9 1\n4 27\n4 40\n49 19\n21 26\n24 33\n56 49\n41 56\n7 23\n41 48\n16 34\n35 9\n56 51\n5 43\n44 46\n10 25\n49 2\n1 21\n9 32\n33 20\n16 5\n5 35\n55 50\n55 53\n37 44\n43 15\n4 55\n8 10\n8 24\n21 42\n37 8\n39 13\n49 38\n39 16\n50 3\n55 7\n51 45\n21 11\n51 28\n50 18\n50 30\n5 37\n7 17\n35 22\n47 36\n35 14\n3 38 47 22 34 10 54 50 9 52 36 1 21 29 28 6 13 39 4 40 53 51 35 55 45 18 44 20 42 31 11 46 41 12", "output": "3\n70" }, { "input": "26 22\n20 16\n2 7\n7 19\n5 9\n20 23\n22 18\n24 3\n8 22\n16 10\n5 2\n7 15\n22 14\n25 4\n25 11\n24 13\n8 24\n13 1\n20 8\n22 6\n7 26\n16 12\n16 5\n13 21\n25 17\n2 25\n16 4 7 24 10 12 2 23 20 1 26 14 8 9 3 6 21 13 11 18 22 17", "output": "1\n37" }, { "input": "43 13\n7 28\n17 27\n39 8\n21 3\n17 20\n17 2\n9 6\n35 23\n43 22\n7 41\n5 24\n26 11\n21 43\n41 17\n16 5\n25 15\n39 10\n18 7\n37 33\n39 13\n39 16\n10 12\n1 21\n2 25\n14 36\n12 7\n16 34\n24 4\n25 40\n5 29\n37 31\n3 32\n22 14\n16 35\n5 37\n10 38\n25 19\n9 1\n26 42\n43 26\n10 30\n33 9\n28 6 42 38 27 32 8 11 36 7 41 29 19", "output": "19\n41" }, { "input": "21 20\n16 9\n7 11\n4 12\n2 17\n17 7\n5 2\n2 8\n4 10\n8 19\n6 15\n2 6\n12 18\n16 5\n20 16\n6 14\n5 3\n5 21\n20 1\n17 13\n6 4\n6 4 18 11 14 1 19 15 10 8 9 17 16 3 20 13 2 5 12 21", "output": "1\n32" }, { "input": "29 6\n16 9\n20 13\n24 3\n24 28\n22 12\n10 11\n10 26\n22 4\n10 27\n5 1\n2 23\n23 5\n16 7\n8 24\n7 19\n19 17\n8 10\n20 16\n20 25\n24 20\n23 15\n22 29\n2 8\n7 22\n2 21\n23 14\n19 18\n19 6\n19 17 18 27 29 4", "output": "4\n16" }, { "input": "31 29\n10 14\n16 6\n23 22\n25 23\n2 27\n24 17\n20 8\n5 2\n8 24\n16 5\n10 26\n8 7\n5 29\n20 16\n13 9\n13 21\n24 30\n13 1\n10 15\n23 3\n25 10\n2 25\n20 13\n25 11\n8 12\n30 28\n20 18\n5 4\n23 19\n16 31\n13 14 3 30 5 6 26 22 25 1 23 7 31 12 16 28 17 2 8 18 24 4 20 21 15 11 9 29 10", "output": "3\n46" }, { "input": "54 8\n33 9\n39 36\n22 14\n24 13\n8 50\n34 52\n47 2\n35 44\n16 54\n34 25\n1 3\n39 11\n9 17\n43 19\n10 40\n47 38\n5 37\n21 47\n37 12\n16 6\n37 7\n32 26\n39 42\n44 10\n1 18\n37 8\n9 1\n8 24\n10 33\n33 53\n5 4\n21 30\n9 31\n24 28\n24 49\n16 5\n34 35\n21 48\n47 43\n13 34\n39 16\n10 27\n22 32\n43 22\n13 46\n33 23\n44 15\n1 21\n8 41\n43 45\n5 29\n35 20\n13 51\n40 50 33 14 48 25 44 9", "output": "14\n21" }, { "input": "17 12\n5 2\n4 3\n8 17\n2 4\n2 8\n17 12\n8 10\n6 11\n16 7\n4 14\n15 13\n6 9\n4 6\n15 16\n16 5\n9 1\n4 8 1 9 3 12 15 10 13 6 14 16", "output": "1\n20" }, { "input": "28 6\n25 21\n9 18\n25 1\n16 5\n9 11\n28 19\n5 2\n20 16\n20 13\n2 23\n5 25\n8 24\n14 27\n3 15\n24 28\n8 10\n22 14\n14 17\n13 9\n3 22\n22 26\n16 7\n2 8\n25 3\n3 12\n14 4\n9 6\n28 27 22 24 20 16", "output": "27\n13" }, { "input": "10 9\n3 9\n4 8\n10 1\n2 3\n5 6\n4 3\n1 2\n5 4\n6 7\n9 1 5 8 7 3 4 6 10", "output": "7\n11" }, { "input": "9 6\n1 6\n3 4\n9 7\n3 2\n8 7\n2 1\n6 7\n3 5\n2 5 1 6 3 9", "output": "5\n6" }, { "input": "19 11\n8 9\n10 13\n16 15\n6 4\n3 2\n17 16\n4 7\n1 14\n10 11\n15 14\n4 3\n10 12\n4 5\n2 1\n16 19\n8 1\n10 9\n18 16\n10 14 18 12 17 11 19 8 1 3 9", "output": "11\n18" }, { "input": "36 5\n36 33\n11 12\n14 12\n25 24\n27 26\n23 24\n20 19\n1 2\n3 2\n17 18\n33 34\n23 1\n32 31\n12 15\n25 26\n4 5\n5 8\n5 6\n26 29\n1 9\n35 33\n33 32\n16 1\n3 4\n31 30\n16 17\n19 21\n1 30\n7 5\n9 10\n13 12\n19 18\n10 11\n22 19\n28 26\n29 12 11 17 33", "output": "12\n21" }, { "input": "10 2\n5 1\n1 3\n3 4\n4 2\n5 10\n1 9\n3 8\n4 7\n2 6\n3 4", "output": "3\n1" }, { "input": "53 30\n41 42\n27 24\n13 11\n10 11\n32 33\n34 33\n37 40\n21 22\n21 20\n46 47\n2 1\n31 30\n29 30\n11 14\n42 43\n50 51\n34 35\n36 35\n24 23\n48 47\n41 1\n28 29\n45 44\n16 15\n5 4\n6 5\n18 19\n9 8\n37 38\n11 12\n39 37\n49 48\n50 49\n43 44\n50 53\n3 4\n50 52\n24 25\n7 6\n46 45\n2 3\n17 18\n31 32\n19 20\n7 8\n15 1\n36 37\n23 22\n9 10\n17 16\n24 26\n28 1\n38 52 41 35 53 43 3 29 36 4 23 20 46 5 40 30 49 25 16 48 17 27 21 9 45 44 15 13 14 2", "output": "13\n74" }, { "input": "10 4\n2 3\n4 2\n8 9\n6 5\n8 1\n5 1\n8 10\n7 5\n1 2\n4 10 2 5", "output": "4\n6" }, { "input": "10 5\n4 5\n9 1\n1 2\n7 1\n5 1\n10 1\n7 3\n6 3\n5 8\n5 2 7 10 1", "output": "2\n6" }, { "input": "10 4\n8 7\n7 6\n1 2\n3 2\n3 4\n6 5\n10 7\n7 9\n5 4\n9 5 10 4", "output": "4\n6" }, { "input": "5 4\n2 3\n2 1\n3 5\n4 3\n4 2 5 1", "output": "1\n5" }, { "input": "5 1\n1 2\n2 3\n3 4\n4 5\n4", "output": "4\n0" } ]
794
21,606,400
0
6,927
854
Maxim Buys an Apartment
[ "constructive algorithms", "math" ]
null
null
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale. Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly *k* already inhabited apartments, but he doesn't know their indices yet. Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
The only line of the input contains two integers: *n* and *k* (1<=≀<=*n*<=≀<=109, 0<=≀<=*k*<=≀<=*n*).
Print the minimum possible and the maximum possible number of apartments good for Maxim.
[ "6 3\n" ]
[ "1 3\n" ]
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
[ { "input": "6 3", "output": "1 3" }, { "input": "10 1", "output": "1 2" }, { "input": "10 9", "output": "1 1" }, { "input": "8 0", "output": "0 0" }, { "input": "8 8", "output": "0 0" }, { "input": "966871928 890926970", "output": "1 75944958" }, { "input": "20 2", "output": "1 4" }, { "input": "1 0", "output": "0 0" }, { "input": "1 1", "output": "0 0" }, { "input": "2 0", "output": "0 0" }, { "input": "2 1", "output": "1 1" }, { "input": "2 2", "output": "0 0" }, { "input": "7 2", "output": "1 4" }, { "input": "8 3", "output": "1 5" }, { "input": "9 4", "output": "1 5" }, { "input": "10 3", "output": "1 6" }, { "input": "10 4", "output": "1 6" }, { "input": "10 5", "output": "1 5" }, { "input": "1000 1000", "output": "0 0" }, { "input": "1000 333", "output": "1 666" }, { "input": "1000 334", "output": "1 666" }, { "input": "999 333", "output": "1 666" }, { "input": "999 334", "output": "1 665" }, { "input": "998 332", "output": "1 664" }, { "input": "998 333", "output": "1 665" }, { "input": "89 4", "output": "1 8" }, { "input": "66 50", "output": "1 16" }, { "input": "88 15", "output": "1 30" }, { "input": "95 43", "output": "1 52" }, { "input": "900 344", "output": "1 556" }, { "input": "777 113", "output": "1 226" }, { "input": "964 42", "output": "1 84" }, { "input": "982 867", "output": "1 115" }, { "input": "1000000000 0", "output": "0 0" }, { "input": "1000000000 1000000000", "output": "0 0" }, { "input": "1000000000 333333333", "output": "1 666666666" }, { "input": "1000000000 333333334", "output": "1 666666666" }, { "input": "999999999 333333333", "output": "1 666666666" }, { "input": "999999999 333333334", "output": "1 666666665" }, { "input": "999999998 333333332", "output": "1 666666664" }, { "input": "999999998 333333333", "output": "1 666666665" }, { "input": "78602604 42160832", "output": "1 36441772" }, { "input": "35679021 9137902", "output": "1 18275804" }, { "input": "41949373 13173511", "output": "1 26347022" }, { "input": "77855558 49163875", "output": "1 28691683" }, { "input": "87187123 2851901", "output": "1 5703802" }, { "input": "66849627 25004217", "output": "1 41845410" }, { "input": "873046672 517064947", "output": "1 355981725" }, { "input": "639857373 1393427", "output": "1 2786854" }, { "input": "637563683 69636269", "output": "1 139272538" }, { "input": "911669737 141068293", "output": "1 282136586" }, { "input": "547575919 313272818", "output": "1 234303101" }, { "input": "955020006 297895809", "output": "1 595791618" }, { "input": "10 4", "output": "1 6" }, { "input": "11 3", "output": "1 6" }, { "input": "10 3", "output": "1 6" }, { "input": "4 1", "output": "1 2" }, { "input": "9 3", "output": "1 6" }, { "input": "7 2", "output": "1 4" }, { "input": "7 3", "output": "1 4" }, { "input": "12 5", "output": "1 7" }, { "input": "8 3", "output": "1 5" }, { "input": "1000 8", "output": "1 16" } ]
77
2,048,000
-1
6,930
0
none
[ "none" ]
null
null
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=Γ—<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of giant chess against his friend Pollard. Gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. Gerald is so confident of victory that he became interested, in how many ways can he win? The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. In addition, it can not go to the black cells, otherwise the Gerald still loses. There are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process.
The first line of the input contains three integers: *h*,<=*w*,<=*n* β€” the sides of the board and the number of black cells (1<=≀<=*h*,<=*w*<=≀<=105,<=1<=≀<=*n*<=≀<=2000). Next *n* lines contain the description of black cells. The *i*-th of these lines contains numbers *r**i*,<=*c**i* (1<=≀<=*r**i*<=≀<=*h*,<=1<=≀<=*c**i*<=≀<=*w*) β€” the number of the row and column of the *i*-th cell. It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.
Print a single line β€” the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109<=+<=7.
[ "3 4 2\n2 2\n2 3\n", "100 100 3\n15 16\n16 15\n99 88\n" ]
[ "2\n", "545732279\n" ]
none
[ { "input": "3 4 2\n2 2\n2 3", "output": "2" }, { "input": "100 100 3\n15 16\n16 15\n99 88", "output": "545732279" }, { "input": "1000 1000 4\n50 50\n51 50\n50 51\n51 51", "output": "899660737" }, { "input": "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000", "output": "999612315" }, { "input": "2 2 2\n2 1\n1 2", "output": "0" }, { "input": "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 5\n85 2\n88 1\n88 5\n86 3\n70 9\n49 3\n34 4\n5 7\n77 5\n50 1\n87 5", "output": "402737011" }, { "input": "100000 100000 2\n1 2\n2 1", "output": "0" }, { "input": "100000 100000 2\n99999 100000\n100000 99999", "output": "0" }, { "input": "100000 100000 3\n99998 100000\n99999 99999\n100000 99998", "output": "0" } ]
61
409,600
0
6,937
405
Domino Effect
[]
null
null
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges *n* dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=3000), the number of the dominoes in the line. The next line contains a character string *s* of length *n*. The *i*-th character of the string *s**i* is equal to - "L", if the *i*-th domino has been pushed to the left; - "R", if the *i*-th domino has been pushed to the right; - ".", if the *i*-th domino has not been pushed. It is guaranteed that if *s**i*<==<=*s**j*<==<="L" and *i*<=&lt;<=*j*, then there exists such *k* that *i*<=&lt;<=*k*<=&lt;<=*j* and *s**k*<==<="R"; if *s**i*<==<=*s**j*<==<="R" and *i*<=&lt;<=*j*, then there exists such *k* that *i*<=&lt;<=*k*<=&lt;<=*j* and *s**k*<==<="L".
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
[ "14\n.L.R...LR..L..\n", "5\nR....\n", "1\n.\n" ]
[ "4\n", "0\n", "1\n" ]
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
[ { "input": "14\n.L.R...LR..L..", "output": "4" }, { "input": "1\n.", "output": "1" }, { "input": "1\nL", "output": "0" }, { "input": "1\nR", "output": "0" }, { "input": "2\nL.", "output": "1" }, { "input": "2\nRL", "output": "0" }, { "input": "2\n..", "output": "2" }, { "input": "10\nR........L", "output": "0" }, { "input": "9\nR.......L", "output": "1" }, { "input": "6\n..L.RL", "output": "1" }, { "input": "34\n..R...L..RL..RLRLR...L....R....L..", "output": "14" }, { "input": "2\nLR", "output": "0" }, { "input": "2\n.R", "output": "1" }, { "input": "2\nR.", "output": "0" }, { "input": "2\n.L", "output": "0" }, { "input": "3\nRLR", "output": "0" }, { "input": "3\nLRL", "output": "0" }, { "input": "5\n.L.R.", "output": "1" }, { "input": "5\n.R.L.", "output": "3" }, { "input": "5\nRL.RL", "output": "1" }, { "input": "14\nLR..LR....LRLR", "output": "0" }, { "input": "34\n.RL.R.L.R..L.R...L.R....L.R.....L.", "output": "10" }, { "input": "3\nL.R", "output": "1" }, { "input": "11\nLR.......LR", "output": "1" }, { "input": "7\n......R", "output": "6" }, { "input": "9\n........L", "output": "0" }, { "input": "200\n....R..LRLR......LR..L....R..LR.L....R.LR.LR..LR.L...R..L.R.......LR..LRL.R..LR.LRLR..LRLRL....R..LR...LR.L..RL....R.LR..LR..L.R.L...R.LR.....L.R....LR..L.R...L..RLRL...RL..R..L.RLR......L..RL....R.L.", "output": "62" }, { "input": "300\nR.L..R.L.RL....R....L.RLR.L.R......LR....LRL.RL..RLRL..R.LRLRL.R.L.RLRLR.LRL..RL.RL.RLRLRL.R.L.RLR.L.R..LRLRL...RLRL.R.LRL..R..LR.LR.L.R...LR..L..R.L.RL.....R.....LR.....LR..LRL..RLRLRL.RLR....L..RL..RL..RLRLR.LRLR......LR......L..R....L.R.L....RL.R.LRL..RLRL..R..LRL.RLRL...RL..R.LRL.R.LRL.R....L.RL", "output": "88" }, { "input": "400\n.L.R.LR.LRL.R.LR.LR..L....RLR.L..R..LRLRLR.LRL..RLR.LRLRLRLR.LR..LRL.RLR...LRLR.LRL.R.LR..LR.LRLR...LRLRL.R.L.....RL..RL.RLRL.RL.RL...RL..R.LRLRL..R.LRL...R..LRL.RLRL...RL..RLRLRLRL.R..LRL.R..LRLRL.R.L.R.L.RL.RLRLRL....R.LR..L..RL.RL.RLRLR.L..RLRL.RLR..LRLR.L.R..L.R.LR.LRL.....RLRL..RL..RLR.......LRLRLRL..RLRL.RLRLRL.R...L.R.L..RL..R.L.RLRLR.LR..L..RLRLR.L...RLR...L.RL...R...L..R.LRLRLRLR..LRL.RLR", "output": "121" }, { "input": "3\nR..", "output": "0" }, { "input": "5\n...R.", "output": "3" }, { "input": "5\n..RL.", "output": "3" }, { "input": "4\n.LR.", "output": "0" }, { "input": "3\nL..", "output": "2" } ]
62
1,638,400
3
6,948
925
Resource Distribution
[ "binary search", "implementation", "sortings" ]
null
null
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units. In order for production to work, it is needed to deploy two services $S_1$ and $S_2$ to process incoming requests using the servers of the department. Processing of incoming requests of service $S_i$ takes $x_i$ resource units. The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service $S_i$ is deployed using $k_i$ servers, then the load is divided equally between these servers and each server requires only $x_i / k_i$ (that may be a fractional number) resource units. Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides. Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
The first line contains three integers $n$, $x_1$, $x_2$ ($2 \leq n \leq 300\,000$, $1 \leq x_1, x_2 \leq 10^9$)Β β€” the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $n$ space-separated integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq 10^9$)Β β€” the number of resource units provided by each of the servers.
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $k_1$ and $k_2$ ($1 \leq k_1, k_2 \leq n$)Β β€” the number of servers used for each of the services. In the third line print $k_1$ integers, the indices of the servers that will be used for the first service. In the fourth line print $k_2$ integers, the indices of the servers that will be used for the second service. No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
[ "6 8 16\n3 5 2 9 8 7\n", "4 20 32\n21 11 11 12\n", "4 11 32\n5 5 16 16\n", "5 12 20\n7 8 4 11 9\n" ]
[ "Yes\n3 2\n1 2 6\n5 4", "Yes\n1 3\n1\n2 3 4\n", "No\n", "No\n" ]
In the first sample test each of the servers 1, 2 and 6 will will provide $8 / 3 = 2.(6)$ resource units and each of the servers 5, 4 will provide $16 / 2 = 8$ resource units. In the second sample test the first server will provide $20$ resource units and each of the remaining servers will provide $32 / 3 = 10.(6)$ resource units.
[ { "input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n4 2\n3 1 2 6\n5 4" }, { "input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4" }, { "input": "4 11 32\n5 5 16 16", "output": "No" }, { "input": "5 12 20\n7 8 4 11 9", "output": "No" }, { "input": "2 1 1\n1 1", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 1\n1 1000000", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 1\n1000000000 1000000000", "output": "Yes\n1 1\n1\n2" }, { "input": "2 1 2\n1 1", "output": "No" }, { "input": "15 250 200\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41", "output": "Yes\n11 3\n13 10 8 15 6 7 12 4 1 9 3\n11 14 5" }, { "input": "4 12 11\n4 4 6 11", "output": "Yes\n3 1\n1 2 3\n4" } ]
61
7,065,600
0
6,955
858
Which floor?
[ "brute force", "implementation" ]
null
null
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*?
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=100, 0<=≀<=*m*<=≀<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≀<=*k**i*<=≀<=100, 1<=≀<=*f**i*<=≀<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory.
Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
[ "10 3\n6 2\n2 1\n7 3\n", "8 4\n3 1\n6 2\n5 2\n2 1\n" ]
[ "4\n", "-1\n" ]
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
[ { "input": "10 3\n6 2\n2 1\n7 3", "output": "4" }, { "input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1" }, { "input": "8 3\n7 2\n6 2\n1 1", "output": "2" }, { "input": "4 2\n8 3\n3 1", "output": "2" }, { "input": "11 4\n16 4\n11 3\n10 3\n15 4", "output": "3" }, { "input": "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "output": "4" }, { "input": "1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 2\n1 1\n2 2", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 0", "output": "-1" }, { "input": "2 1\n3 3", "output": "2" }, { "input": "3 2\n1 1\n3 3", "output": "3" }, { "input": "3 3\n1 1\n3 3\n2 2", "output": "3" }, { "input": "3 0", "output": "-1" }, { "input": "1 1\n2 1", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 3\n3 2\n1 1\n2 1", "output": "1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 1", "output": "-1" }, { "input": "2 2\n1 1\n3 1", "output": "1" }, { "input": "1 3\n1 1\n2 1\n3 1", "output": "1" }, { "input": "81 0", "output": "-1" }, { "input": "22 1\n73 73", "output": "22" }, { "input": "63 2\n10 10\n64 64", "output": "63" }, { "input": "88 3\n37 37\n15 15\n12 12", "output": "88" }, { "input": "29 4\n66 66\n47 47\n62 62\n2 2", "output": "29" }, { "input": "9 40\n72 72\n47 47\n63 63\n66 66\n21 21\n94 94\n28 28\n45 45\n93 93\n25 25\n100 100\n43 43\n49 49\n9 9\n74 74\n26 26\n42 42\n50 50\n2 2\n92 92\n76 76\n3 3\n78 78\n44 44\n69 69\n36 36\n65 65\n81 81\n13 13\n46 46\n24 24\n96 96\n73 73\n82 82\n68 68\n64 64\n41 41\n31 31\n29 29\n10 10", "output": "9" }, { "input": "50 70\n3 3\n80 80\n23 23\n11 11\n87 87\n7 7\n63 63\n61 61\n67 67\n53 53\n9 9\n43 43\n55 55\n27 27\n5 5\n1 1\n99 99\n65 65\n37 37\n60 60\n32 32\n38 38\n81 81\n2 2\n34 34\n17 17\n82 82\n26 26\n71 71\n4 4\n16 16\n19 19\n39 39\n51 51\n6 6\n49 49\n64 64\n83 83\n10 10\n56 56\n30 30\n76 76\n90 90\n42 42\n47 47\n91 91\n21 21\n52 52\n40 40\n77 77\n35 35\n88 88\n75 75\n95 95\n28 28\n15 15\n69 69\n22 22\n48 48\n66 66\n31 31\n98 98\n73 73\n25 25\n97 97\n18 18\n13 13\n54 54\n72 72\n29 29", "output": "50" }, { "input": "6 0", "output": "-1" }, { "input": "32 1\n9 5", "output": "16" }, { "input": "73 2\n17 9\n21 11", "output": "37" }, { "input": "6 3\n48 24\n51 26\n62 31", "output": "3" }, { "input": "43 4\n82 41\n52 26\n88 44\n41 21", "output": "22" }, { "input": "28 40\n85 43\n19 10\n71 36\n39 20\n57 29\n6 3\n15 8\n11 6\n99 50\n77 39\n79 40\n31 16\n35 18\n24 12\n54 27\n93 47\n90 45\n72 36\n63 32\n22 11\n83 42\n5 3\n12 6\n56 28\n94 47\n25 13\n41 21\n29 15\n36 18\n23 12\n1 1\n84 42\n55 28\n58 29\n9 5\n68 34\n86 43\n3 2\n48 24\n98 49", "output": "14" }, { "input": "81 70\n55 28\n85 43\n58 29\n20 10\n4 2\n47 24\n42 21\n28 14\n26 13\n38 19\n9 5\n83 42\n7 4\n72 36\n18 9\n61 31\n41 21\n64 32\n90 45\n46 23\n67 34\n2 1\n6 3\n27 14\n87 44\n39 20\n11 6\n21 11\n35 18\n48 24\n44 22\n3 2\n71 36\n62 31\n34 17\n16 8\n99 50\n57 29\n13 7\n79 40\n100 50\n53 27\n89 45\n36 18\n43 22\n92 46\n98 49\n75 38\n40 20\n97 49\n37 19\n68 34\n30 15\n96 48\n17 9\n12 6\n45 23\n65 33\n76 38\n84 42\n23 12\n91 46\n52 26\n8 4\n32 16\n77 39\n88 44\n86 43\n70 35\n51 26", "output": "41" }, { "input": "34 0", "output": "-1" }, { "input": "63 1\n94 24", "output": "16" }, { "input": "4 2\n38 10\n48 12", "output": "1" }, { "input": "37 3\n66 17\n89 23\n60 15", "output": "10" }, { "input": "71 4\n15 4\n13 4\n4 1\n70 18", "output": "18" }, { "input": "77 40\n49 13\n66 17\n73 19\n15 4\n36 9\n1 1\n41 11\n91 23\n51 13\n46 12\n39 10\n42 11\n56 14\n61 16\n70 18\n92 23\n65 17\n54 14\n97 25\n8 2\n87 22\n33 9\n28 7\n38 10\n50 13\n26 7\n7 2\n31 8\n84 21\n47 12\n27 7\n53 14\n19 5\n93 24\n29 8\n3 1\n77 20\n62 16\n9 3\n44 11", "output": "20" }, { "input": "18 70\n51 13\n55 14\n12 3\n43 11\n42 11\n95 24\n96 24\n29 8\n65 17\n71 18\n18 5\n62 16\n31 8\n100 25\n4 1\n77 20\n56 14\n24 6\n93 24\n97 25\n79 20\n40 10\n49 13\n86 22\n21 6\n46 12\n6 2\n14 4\n23 6\n20 5\n52 13\n88 22\n39 10\n70 18\n94 24\n13 4\n37 10\n41 11\n91 23\n85 22\n83 21\n89 23\n33 9\n64 16\n67 17\n57 15\n47 12\n36 9\n72 18\n81 21\n76 19\n35 9\n80 20\n34 9\n5 2\n22 6\n84 21\n63 16\n74 19\n90 23\n68 17\n98 25\n87 22\n2 1\n92 23\n50 13\n38 10\n28 7\n8 2\n60 15", "output": "5" }, { "input": "89 0", "output": "-1" }, { "input": "30 1\n3 1", "output": "-1" }, { "input": "63 2\n48 6\n17 3", "output": "8" }, { "input": "96 3\n45 6\n25 4\n35 5", "output": "12" }, { "input": "37 4\n2 1\n29 4\n27 4\n47 6", "output": "5" }, { "input": "64 40\n40 5\n92 12\n23 3\n75 10\n71 9\n2 1\n54 7\n18 3\n9 2\n74 10\n87 11\n11 2\n90 12\n30 4\n48 6\n12 2\n91 12\n60 8\n35 5\n13 2\n53 7\n46 6\n38 5\n59 8\n97 13\n32 4\n6 1\n36 5\n43 6\n83 11\n81 11\n99 13\n69 9\n10 2\n21 3\n78 10\n31 4\n27 4\n57 8\n1 1", "output": "8" }, { "input": "17 70\n63 8\n26 4\n68 9\n30 4\n61 8\n84 11\n39 5\n53 7\n4 1\n81 11\n50 7\n91 12\n59 8\n90 12\n20 3\n21 3\n83 11\n94 12\n37 5\n8 1\n49 7\n34 5\n19 3\n44 6\n74 10\n2 1\n73 10\n88 11\n43 6\n36 5\n57 8\n64 8\n76 10\n40 5\n71 9\n95 12\n15 2\n41 6\n89 12\n42 6\n96 12\n1 1\n52 7\n38 5\n45 6\n78 10\n82 11\n16 2\n48 6\n51 7\n56 7\n28 4\n87 11\n93 12\n46 6\n29 4\n97 13\n54 7\n35 5\n3 1\n79 10\n99 13\n13 2\n55 7\n100 13\n11 2\n75 10\n24 3\n33 5\n22 3", "output": "3" }, { "input": "9 0", "output": "-1" }, { "input": "50 1\n31 2", "output": "-1" }, { "input": "79 2\n11 1\n22 2", "output": "-1" }, { "input": "16 3\n100 7\n94 6\n3 1", "output": "1" }, { "input": "58 4\n73 5\n52 4\n69 5\n3 1", "output": "4" }, { "input": "25 40\n70 5\n28 2\n60 4\n54 4\n33 3\n21 2\n51 4\n20 2\n44 3\n79 5\n65 5\n1 1\n52 4\n23 2\n38 3\n92 6\n63 4\n3 1\n91 6\n5 1\n64 4\n34 3\n25 2\n97 7\n89 6\n61 4\n71 5\n88 6\n29 2\n56 4\n45 3\n6 1\n53 4\n57 4\n90 6\n76 5\n8 1\n46 3\n73 5\n87 6", "output": "2" }, { "input": "78 70\n89 6\n52 4\n87 6\n99 7\n3 1\n25 2\n46 3\n78 5\n35 3\n68 5\n85 6\n23 2\n60 4\n88 6\n17 2\n8 1\n15 1\n67 5\n95 6\n59 4\n94 6\n31 2\n4 1\n16 1\n10 1\n97 7\n42 3\n2 1\n24 2\n34 3\n37 3\n70 5\n18 2\n41 3\n48 3\n58 4\n20 2\n38 3\n72 5\n50 4\n49 4\n40 3\n61 4\n6 1\n45 3\n28 2\n13 1\n27 2\n96 6\n56 4\n91 6\n77 5\n12 1\n11 1\n53 4\n76 5\n74 5\n82 6\n55 4\n80 5\n14 1\n44 3\n7 1\n83 6\n79 5\n92 6\n66 5\n36 3\n73 5\n100 7", "output": "5" }, { "input": "95 0", "output": "-1" }, { "input": "33 1\n30 1", "output": "-1" }, { "input": "62 2\n14 1\n15 1", "output": "-1" }, { "input": "3 3\n6 1\n25 1\n38 2", "output": "1" }, { "input": "44 4\n72 3\n80 3\n15 1\n36 2", "output": "2" }, { "input": "34 40\n25 1\n28 1\n78 3\n5 1\n13 1\n75 3\n15 1\n67 3\n57 2\n23 1\n26 1\n61 2\n22 1\n48 2\n85 3\n24 1\n82 3\n83 3\n53 2\n38 2\n19 1\n33 2\n69 3\n17 1\n79 3\n54 2\n77 3\n97 4\n20 1\n35 2\n14 1\n18 1\n71 3\n21 1\n36 2\n56 2\n44 2\n63 2\n72 3\n32 1", "output": "2" }, { "input": "83 70\n79 3\n49 2\n2 1\n44 2\n38 2\n77 3\n86 3\n31 1\n83 3\n82 3\n35 2\n7 1\n78 3\n23 1\n39 2\n58 2\n1 1\n87 3\n72 3\n20 1\n48 2\n14 1\n13 1\n6 1\n70 3\n55 2\n52 2\n25 1\n11 1\n61 2\n76 3\n95 3\n32 1\n66 3\n29 1\n9 1\n5 1\n3 1\n88 3\n59 2\n96 3\n10 1\n63 2\n40 2\n42 2\n34 2\n43 2\n19 1\n89 3\n94 3\n24 1\n98 4\n12 1\n30 1\n69 3\n17 1\n50 2\n8 1\n93 3\n16 1\n97 4\n54 2\n71 3\n18 1\n33 2\n80 3\n15 1\n99 4\n75 3\n4 1", "output": "3" }, { "input": "2 0", "output": "-1" }, { "input": "36 1\n96 1", "output": "1" }, { "input": "73 2\n34 1\n4 1", "output": "-1" }, { "input": "6 3\n37 1\n22 1\n70 1", "output": "1" }, { "input": "47 4\n66 1\n57 1\n85 1\n47 1", "output": "1" }, { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n72 1\n76 1\n47 1\n17 1\n67 1\n95 1\n41 1\n54 1\n88 1\n42 1\n80 1\n98 1\n96 1\n10 1\n24 1\n78 1\n18 1\n3 1\n91 1\n2 1\n15 1\n5 1\n60 1\n36 1\n46 1", "output": "1" }, { "input": "63 70\n82 1\n53 1\n57 1\n46 1\n97 1\n19 1\n36 1\n90 1\n23 1\n88 1\n68 1\n45 1\n2 1\n70 1\n86 1\n8 1\n83 1\n40 1\n99 1\n42 1\n32 1\n52 1\n81 1\n50 1\n77 1\n37 1\n54 1\n75 1\n4 1\n49 1\n73 1\n22 1\n21 1\n98 1\n18 1\n51 1\n14 1\n76 1\n92 1\n80 1\n78 1\n33 1\n79 1\n89 1\n67 1\n9 1\n44 1\n60 1\n64 1\n55 1\n29 1\n100 1\n16 1\n87 1\n10 1\n12 1\n25 1\n85 1\n30 1\n63 1\n39 1\n38 1\n31 1\n5 1\n26 1\n91 1\n43 1\n72 1\n48 1\n94 1", "output": "1" }, { "input": "2 0", "output": "-1" } ]
46
0
0
6,959
0
none
[ "none" ]
null
null
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≀<=*k* for every *i*; - *a**n*<=β‰ <=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=β‰ <=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=200<=000,<=1<=≀<=*k*<=≀<=109)Β β€” the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≀<=*k*,<=*a**n*<=β‰ <=0)Β β€” describing a valid polynomial . It's guaranteed that *P*(2)<=β‰ <=0.
Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0.
[ "3 1000000000\n10 -9 -3 5\n", "3 12\n10 -9 -3 5\n", "2 20\n14 -7 19\n" ]
[ "3\n", "2\n", "0\n" ]
In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
[ { "input": "3 1000000000\n10 -9 -3 5", "output": "3" }, { "input": "3 12\n10 -9 -3 5", "output": "2" }, { "input": "2 20\n14 -7 19", "output": "0" }, { "input": "5 5\n0 -4 -2 -2 0 5", "output": "1" }, { "input": "6 10\n-2 -1 7 -3 2 7 -6", "output": "2" }, { "input": "7 100\n2 21 11 45 58 85 -59 38", "output": "1" }, { "input": "100 1000\n-62 57 -27 -67 49 -10 66 -64 -36 -78 62 -75 -39 75 -47 -36 41 -88 62 -43 22 29 -20 58 40 16 71 -2 -87 12 86 -90 -92 67 -12 -48 -10 -26 78 68 22 -3 66 -95 -81 34 14 -76 -27 76 -60 87 -84 3 35 -60 46 -65 29 -29 2 -44 -55 18 -75 91 36 34 -86 53 59 -54 -29 33 -95 66 9 72 67 -44 37 44 32 -52 -34 -4 -99 58 7 -22 -53 11 10 10 -25 -100 -95 -27 43 -46 25", "output": "10" }, { "input": "1 5\n5 -3", "output": "0" }, { "input": "1 10\n-6 2", "output": "2" }, { "input": "5 10000\n-160 3408 -4620 5869 7434 -6253", "output": "1" }, { "input": "10 1\n0 0 0 0 0 0 0 0 0 0 1", "output": "0" }, { "input": "10 1\n0 0 1 -1 1 0 0 1 1 -1 -1", "output": "0" }, { "input": "10 2\n-2 -2 1 2 -1 -2 1 -2 1 2 -1", "output": "2" }, { "input": "20 100\n52 -82 36 90 -62 -35 -93 -98 -80 -40 29 8 43 26 35 55 -56 -99 -17 13 11", "output": "1" }, { "input": "90 10\n-4 2 2 5 -1 3 4 1 -2 10 -9 -2 -4 3 8 0 -8 -3 9 1 2 4 8 2 0 2 -10 4 -4 -6 2 -9 3 -9 -3 8 8 9 -7 -10 3 9 -2 -7 5 -7 -5 6 1 5 1 -8 3 8 0 -6 2 2 3 -10 2 1 4 8 -3 1 5 7 -7 -3 2 -2 -9 7 7 -2 7 -6 7 -3 2 -5 10 0 0 9 -1 -4 1 -8 4", "output": "4" }, { "input": "101 20\n4 16 -5 8 -13 -6 -19 -4 18 9 -5 5 3 13 -12 -2 -1 -4 -13 14 2 15 -11 -17 -15 6 9 -15 -10 16 18 -7 8 -19 17 11 -6 -5 -16 -7 -14 5 -17 -6 18 19 -14 -5 1 11 -17 18 4 9 -1 19 1 8 9 -14 11 -8 -18 -12 15 14 -8 0 8 16 2 -20 -19 17 14 -2 3 -9 -13 4 6 -16 3 -12 19 -14 -8 -16 7 -4 5 9 17 7 -3 -15 6 18 -13 10 -8 2", "output": "1" }, { "input": "10 1000\n-538 -553 -281 -270 209 -989 -418 486 330 725 -430", "output": "1" }, { "input": "30 1000\n622 815 -733 -613 -741 571 -761 -432 -7 201 554 730 607 415 -453 820 161 147 406 875 -413 462 998 481 698 661 18 -331 752 -232 -72", "output": "2" }, { "input": "5 2000000\n1038520 -406162 -106421 106958 -807010 850753", "output": "2" }, { "input": "10 1000000000\n-857095622 -567296277 -923645190 -246044525 610990226 -617677619 -239569893 355377587 222686442 250110001 -200293692", "output": "2" }, { "input": "20 1000000000\n-924490890 231431639 -579465017 -690485236 173663728 144784457 364609617 444830562 48833250 1095623 333652904 -901650010 -850265945 844112020 -9178988 -527869441 93581840 607677914 -521131467 -628140952 329057708", "output": "3" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n-1 0 -2", "output": "0" }, { "input": "2 2\n-1 -1 1", "output": "1" }, { "input": "2 2\n1 1 -2", "output": "0" }, { "input": "3 2\n2 -1 -1 1", "output": "2" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "35 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "35 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "32 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "32 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "55 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "55 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "69 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "69 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "61 10\n0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1", "output": "0" }, { "input": "2 10\n1 -2 1", "output": "1" }, { "input": "65 1\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1", "output": "0" } ]
61
5,222,400
0
6,969
66
Petya and His Friends
[ "constructive algorithms", "math", "number theory" ]
D. Petya and His Friends
2
256
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*. Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *a**i* (1<=≀<=*i*<=≀<=*k*) is evenly divisible by *d*. At that, we assume that all *a**i*'s are greater than zero. Knowing that Petya is keen on programming, his friends has agreed beforehand that the 1-st friend gives *a*1 sweets, the 2-nd one gives *a*2 sweets, ..., the *n*-th one gives *a**n* sweets. At the same time, for any *i* and *j* (1<=≀<=*i*,<=*j*<=≀<=*n*) they want the *GCD*(*a**i*,<=*a**j*) not to be equal to 1. However, they also want the following condition to be satisfied: *GCD*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1. One more: all the *a**i* should be distinct. Help the friends to choose the suitable numbers *a*1,<=...,<=*a**n*.
The first line contains an integer *n* (2<=≀<=*n*<=≀<=50).
If there is no answer, print "-1" without quotes. Otherwise print a set of *n* distinct positive numbers *a*1,<=*a*2,<=...,<=*a**n*. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any of them. Do not forget, please, that all of the following conditions must be true: - For every *i* and *j* (1<=≀<=*i*,<=*j*<=≀<=*n*): *GCD*(*a**i*,<=*a**j*)<=β‰ <=1- *GCD*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1- For every *i* and *j* (1<=≀<=*i*,<=*j*<=≀<=*n*,<=*i*<=β‰ <=*j*): *a**i*<=β‰ <=*a**j* Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "3\n", "4\n" ]
[ "99\n55\n11115\n", "385\n360\n792\n8360\n" ]
none
[ { "input": "3", "output": "15\n10\n6" }, { "input": "4", "output": "105\n70\n42\n30" }, { "input": "5", "output": "1155\n770\n462\n330\n210" }, { "input": "6", "output": "15015\n10010\n6006\n4290\n2730\n2310" }, { "input": "7", "output": "255255\n170170\n102102\n72930\n46410\n39270\n30030" }, { "input": "8", "output": "4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510" }, { "input": "9", "output": "111546435\n74364290\n44618574\n31870410\n20281170\n17160990\n13123110\n11741730\n9699690" }, { "input": "10", "output": "3234846615\n2156564410\n1293938646\n924241890\n588153930\n497668710\n380570190\n340510170\n281291010\n223092870" }, { "input": "11", "output": "100280245065\n66853496710\n40112098026\n28651498590\n18232771830\n15427730010\n11797675890\n10555815270\n8720021310\n6915878970\n6469693230" }, { "input": "12", "output": "3710369067405\n2473579378270\n1484147626962\n1060105447830\n674612557710\n570826010370\n436514007930\n390565164990\n322640788470\n255887521890\n239378649510\n200560490130" }, { "input": "2", "output": "-1" }, { "input": "13", "output": "152125131763605\n101416754509070\n60850052705442\n43464323361030\n27659114866110\n23403866425170\n17897074325130\n16013171764590\n13228272327270\n10491388397490\n9814524629910\n8222980095330\n7420738134810" }, { "input": "14", "output": "6541380665835015\n4360920443890010\n2616552266334006\n1868965904524290\n1189341939242730\n1006366256282310\n769574195980590\n688566385877370\n568815710072610\n451129701092070\n422024559086130\n353588144099190\n319091739796830\n304250263527210" }, { "input": "15", "output": "307444891294245705\n204963260862830470\n122977956517698282\n87841397512641630\n55899071144408310\n47299214045268570\n36169987211087730\n32362620136236390\n26734338373412670\n21203095951327290\n19835154277048110\n16618642772661930\n14997311770451010\n14299762385778870\n13082761331670030" }, { "input": "16", "output": "16294579238595022365\n10863052825730014910\n6517831695438008946\n4655594068170006390\n2962650770653640430\n2506858344399234210\n1917009322187649690\n1715218867220528670\n1416919933790871510\n1123764085420346370\n1051263176683549830\n880788066951082290\n794857523833903530\n757887406446280110\n693386350578511590\n614889782588491410" }, { "input": "17", "output": "961380175077106319535\n640920116718070879690\n384552070030842527814\n274680050022030377010\n174796395468564785370\n147904642319554818390\n113103550009071331710\n101197913166011191530\n83598276093661419090\n66302081039800435830\n62024527424329439970\n51966495950113855110\n46896593906200308270\n44715356980330526490\n40909794684132183810\n36278497172720993190\n32589158477190044730" }, { "input": "18", "output": "58644190679703485491635\n39096127119802323661090\n23457676271881394196654\n16755483051343852997610\n10662580123582451907570\n9022183181492843921790\n6899316550553351234310\n6173072703126682683330\n5099494841713346564490\n4044426943427826585630\n3783496172884095838170\n3169956252956945161710\n2860692228278218804470\n2727636775800162115890\n2495497475732063212410\n2212988327535980584590\n1987938667108592728530\n1922760350154212639070" }, { "input": "19", "output": "3929160775540133527939545\n2619440517026755685293030\n1571664310216053411175818\n1122617364440038150839870\n714392868280024277807190\n604486273160020542759930\n462254208887074532698770\n413595871109487739783110\n341666154394794219820830\n270976605209664381237210\n253494243583234421157390\n212387068948115325834570\n191666379294640659899490\n182751663978610861764630\n167198330874048235231470\n148270217944910699167530\n133191890696275712811510\n128824943460332246817690\n117288381359406970983270" }, { "input": "20", "output": "278970415063349480483707695\n185980276708899653655805130\n111588166025339792193483078\n79705832875242708709630770\n50721893647881723724310490\n42918525394361458535955030\n32820048830982291821612670\n29365306848773629524600810\n24258296962030389607278930\n19239338969886171067841910\n17998091294409643902174690\n15079481895316188134254470\n13608312929919486852863790\n12975368142481371185288730\n11871081492057424701434370\n10527185474088659640894630\n9456624239435575609617210\n9146570985683589524055990\n832747..." }, { "input": "21", "output": "20364840299624512075310661735\n13576560199749674716873774490\n8145936119849804830124264694\n5818525799892717735803046210\n3702698236295365831874665770\n3133052353788386473124717190\n2395863564661707302977724910\n2143667399960474955295859130\n1770855678228218441331361890\n1404471744801690487952459430\n1313860664491904004858752370\n1100802178358081733800576310\n993406843884122540259056670\n947201874401140096526077290\n866588948920192003204709010\n768484539608472153785307990\n690333569478797019502056330\n6676..." }, { "input": "22", "output": "1608822383670336453949542277065\n1072548255780224302633028184710\n643528953468134581579816910826\n459663538191524701128440650590\n292513160667333900718098595830\n247511135949282531376852658010\n189273221608274876935240267890\n169349724596877521468372871270\n139897598580029256865177589310\n110953267839333548548244294970\n103794992494860416383841437230\n86963372090288456970245528490\n78479140666845680680465476930\n74828948077690067625560105910\n68460526964695168253172011790\n60710278629069300149039331210\n54..." }, { "input": "23", "output": "133532257844637925677812008996395\n89021505229758617118541339330930\n53412903137855170271124803598558\n38152073669896550193660573998970\n24278592335388713759602183453890\n20543424283790450104278770614830\n15709677393486814785624942234870\n14056027141540834281874948315410\n11611500682142428319809739912730\n9209121230664684529504276482510\n8614984377073414559858839290090\n7217959883493941928530378864670\n6513768675348191496478634585190\n6210802690448275612921488790530\n5682223738069698965013276978570\n503895..." }, { "input": "24", "output": "11884370948172775385325268800679155\n7922913965448516923550179200452770\n4753748379269110154130107520271662\n3395534556620792967235791085908330\n2160794717849595524604594327396210\n1828364761257350059280810584719870\n1398161288020326515920619858903430\n1250986415597134251086870400071490\n1033423560710676120463066852232970\n819611789529156923125880606943390\n766733609559533895827436696818010\n642398429630960831639203718955630\n579725412105989043186598478081910\n552761439449896529550012502357170\n50571791268..." }, { "input": "25", "output": "1152783981972759212376551073665878035\n768522654648506141584367382443918690\n461113592789103684950620429466351214\n329366851992216917821871735333108010\n209597087631410765886645649757432370\n177351381841962955750238626717827390\n135621644937971672044300126313632710\n121345682312922022355426428806934530\n100242085388935583684917484666598090\n79502343584328221543210418873508830\n74373160127274787895261359591346970\n62312647674203200669002760738696110\n56233364974280937189100052373945270\n53617859626639963366..." }, { "input": "26", "output": "116431182179248680450031658440253681535\n77620788119499120300021105626835787690\n46572472871699472180012663376101472614\n33266052051213908700009045268643909010\n21169305850772487354551210625500669370\n17912489566038258530774101298500566390\n13697786138735138876474312757676903710\n12255913913605124257898069309500387530\n10124450624282493952176665951326407090\n8029736702017150375864252306224391830\n7511689172854753577421397318726043970\n6293577415094523267569278834608307110\n567956986240237465609910528976847..." }, { "input": "27", "output": "11992411764462614086353260819346129198105\n7994941176308409390902173879564086132070\n4796964705785045634541304327738451679242\n3426403361275032596100931662670322628030\n2180438502629566197518774694426568945110\n1844986425301940628669732433745558338170\n1410871972289719304276854214040721082130\n1262359133101327798563501138878539915590\n1042818414301096877074196592986619930270\n827062880307766488714017987541112358490\n773703984804039618474403923828782528910\n648238473754735896559635719964655632330\n584995695..." }, { "input": "28", "output": "1283188058797499707239798907670035824197235\n855458705864999804826532605113357216131490\n513275223518999882895919563068014329678894\n366625159656428487782799687905724521199210\n233306919781363583134508892303642877126770\n197413547507307647267661370410774742184190\n150963301034999965557623400902357155787910\n135072427241842074446294621860003770968130\n111581570330217365846939035449568332538890\n88495728192931014292399924666899022358430\n82786326374032239176761219849679730593370\n6936151669175674093188102203..." }, { "input": "29", "output": "139867498408927468089138080936033904837498615\n93244998939284978726092053957355936558332410\n55946999363570987235655232374413561934999446\n39962142402550705168325165981723972810713890\n25430454256168630561661469261097073606817930\n21518076678296533552175089374774446898076710\n16454999812814996245780950698356929980882190\n14722894569360786114646113782740411035526170\n12162391165993692877316354864002948246739010\n9646034373029480557871591788691993437068870\n9023709574769514070266972963615090634677330\n756040..." }, { "input": "30", "output": "15805027320208803894072603145771831246637343495\n10536684880139202596048402097181220831091562330\n6322010928083521557629041258308732498654937398\n4515722091488229684020743755934808927610669570\n2873641330947055253467746026503969317570426090\n2431542664647508291395785099349512499482668230\n1859414978848094575773247428914333087839687470\n1663687086337768830955010857449666447014457210\n1374350201757287295136748099632333151881508130\n1090001884152331303039489872122195258388782310\n10196791819489550899401679448..." }, { "input": "31", "output": "2007238469666518094547220599513022568322942623865\n1338158979777678729698147066342015045548628415910\n802895387866607237818888239805209027329177049546\n573496705619005169870634457003720733806555035390\n364952449030276017190403745366004103331444113430\n308805918410233553007264707617388087434298865210\n236145702313708011123202423472120302155640308690\n211288259964896641531286378896107638770836065670\n174542475623175486482367008653306310288951532510\n138430239287346075486015213759518797815375353370\n129499256..." }, { "input": "32", "output": "262948239526313870385685898536205956450305483726315\n175298826350875913590457265690803970966870322484210\n105179295810525548154274359414482382580122193490526\n75128068436089677253053113867487416128658709636090\n47808770822966158251942890642946537536419178859330\n40453575311740595443951676697877839453893151342510\n30935087003095749457139517474847759582388880438390\n27678762055401460040598515635390100678979524602770\n22865064306635988729190078133583126647852650758810\n1813436134664233588866799300249696251381..." }, { "input": "33", "output": "36023908815105000242838968099460216033691851270505155\n24015939210070000161892645399640144022461234180336770\n14409563526042000097135587239784086413476740508202062\n10292545375744285783668276599845776009626243220144330\n6549801602746363680516176018083675642489427503728210\n5542139817708461575821379707609264005183361733923870\n4238106919424117675628113894054143062787276620059430\n3791990401590000025561996642048443793020194870579490\n3132513810009130455899040704300888350755813153956970\n248440750449000001674..." }, { "input": "34", "output": "5007323325299595033754616565824970028683167326600216545\n3338215550199730022503077710549980019122111551066811030\n2002929330119838013501846626329988011473266930640086618\n1430663807228455723929890447378562865338047807600061870\n910422422781744551591748466513630914306030423018221190\n770357434661476159039171779357687696720487281015417930\n589096861799952356912307831273525885727431450188260770\n527086665821010003553117533244733687229807087010549110\n435419419591269133369966657897823480755058028400018830\n345..." }, { "input": "35", "output": "746091175469639660029437868307920534273791931663432265205\n497394116979759773352958578871947022849194621108954843470\n298436470187855864011775147323168213709516772665372906082\n213168907277039902865553676659405866935369123332409218630\n135652940994479938187170521510531006231598533029714957310\n114783257764559947696836595124295466811352604871297271570\n87775432408192901179933866859755356973387286078050854730\n78535913207330490529414512453465319397241255964571817390\n64877493519099100872125032026775698632503..." }, { "input": "36", "output": "112659767495915588664445118114496000675342581681178272045955\n75106511663943725776296745409664000450228387787452181363970\n45063906998366235465778047245798400270137032672471308818382\n32188504998833025332698605175570285907240737623193792013130\n20483594090166470666262748748090181940971378487486958553810\n17332271922448552102222325863768615488514243335565888007070\n13254090293637128078170013895823058902981480197785679064230\n11858922894306904069941591380473263228983429650650344425890\n9796501521383964231690..." }, { "input": "37", "output": "17687583496858747420317883543975872106028785323944988711214935\n11791722331239164946878589029317248070685856882629992474143290\n7075033398743498968127153417590348842411514129577995484485974\n5053595284816784977233681012564534887436795806841425346061410\n3215924272156135894603251553450158564732506422535452492948170\n2721166691824422680048905160611672631696736203683844417109990\n2080892176101029108272692181644220247768092391052351613084110\n1861850894406183938980829846734302326950398455152104074864730\n15380..." }, { "input": "38", "output": "2883076109987975829511815017668067153282692007803033159928034405\n1922050739991983886341210011778711435521794671868688773285356270\n1153230443995190331804726007067226861313076803121213263971213762\n823736031425135951289090005048019186652197716515152331408009830\n524195656361450150820330003212375846051398546873278756350551710\n443550170767380896847971541179702638966568001200466639988928370\n339185424704467744648448825608007900386199059741533312932709930\n30348169578820798205387526501769127929291494818979296..." }, { "input": "39", "output": "481473710367991963528473107950567214598209565303106537707981745635\n320982473578661309018982071967044809732139710202071025138654497090\n192589484147196785411389243180226885839283826121242615083192698254\n137563917247997703865278030843019204170917018658030439345137641610\n87540674612362175186995110536466766290583557327837552310542135570\n74072878518152609773611247377010340707416856200477928878151037790\n56643965925646113356290953876537319364495242976836063259762558310\n50681443196630733002997169257954443641..." }, { "input": "40", "output": "83294951893662609690425847675448128125490254797437431023480841994855\n55529967929108406460283898450298752083660169864958287348987227996570\n33317980757465043876170339070179251250196101918974972409392336797942\n23798557683903602768693099335842322321568644227839266006708811998530\n15144536707938656307350154122808750568270955417715896549723789453610\n12814607983640401490834745796222788942383116122682681695920129537670\n9799406105136777610638335020640956250057677034992638943938922587630\n8767889673017116809518..." }, { "input": "41", "output": "14909796388965607134586226733905214934462755608741300153203070717079045\n9939864259310404756390817822603476622975170405827533435468713811386030\n5963918555586242853834490693562085973785102243496520061281228286831618\n4259941825418744895596064781115775695560787316783228615200877347736870\n2710872070721019479015677587982766351720501019771145482400558312196190\n2293814829071631866859419497523879220686577785960200023569703187242930\n1754093692819483192304261968694731168760324189263682370965067143185770\n156945..." }, { "input": "42", "output": "2698673146402774891360107038836843903137758765182175327729755799791307145\n1799115430935183260906738025891229268758505843454783551819837199860871430\n1079469258561109956544042815534737561255103506072870131091902319916522858\n771049470400792826102887725381955400896502504337764379351358799940373470\n490667844800504525701837643424880709661410684578577332314501054507510390\n415180484061965367901554929051822138944270579258796204266116276890970330\n3174909584003264578070714163337463415456186782567265091446771529..." }, { "input": "43", "output": "515446570962930004249780444417837185499311924149795487596383357760139664695\n343631047308620002833186962945224790332874616099863658397588905173426443130\n206178628385172001699912177767134874199724769659918195038553343104055865878\n147270448846551429785651555547953481571231978328512996456109530788611332770\n93717558356896364409050989894152215545329440754508270472069701410934484490\n79299472455835385269196991448898028538355680638430075014828208886175333030\n606407730544623534411506405197455512352131675470347..." }, { "input": "44", "output": "99481188195845490820207625772642576801367201360910529106101988047706955286135\n66320792130563660546805083848428384534244800907273686070734658698471303524090\n39792475278338196328083050309057030720546880544364211642440795219082782114454\n28423196627384425948630750220755021943247771817403008316029139442201987224610\n18087488762880998330946841049571377600248582065620096201109452372310355506570\n15304798183976229356955019349637319507902646363217004477861844315031839274790\n1170366919951123421414207362031089138..." }, { "input": "45", "output": "19597794074581561691580902277210587629869338668099374233902091645398270191368595\n13065196049721041127720601518140391753246225778732916155934727763598846794245730\n7839117629832624676632360910884235051947735467239749693560836658159308076547438\n5599369735594731911880257793488739322819811048028392638257740470113791483248170\n3563235286287556671196527686765561387248970666927158951618562117345140034794290\n3015045242243317183320138811878551943056821333553749882138783330061272337133630\n23056228323037131401859..." }, { "input": "46", "output": "3899961020841730776624599553164906938343998394951775472546516237434255768082350405\n2599974013894487184416399702109937958895998929967850315031010824956170512054900270\n1559984408336692310649839821265962775337599357980710189018606494973702307232940162\n1114274577383351650464171300904259125241142398557650135013290353552644505166385830\n709083821971223777568109009666346716062545162718504631372093861351682866924063710\n599994003206420119480707623563831836668307445377196226545617882682193195089592370\n458818943..." }, { "input": "47", "output": "822891775397605193867790505717795363990583661334824624707314926098627967065375935455\n548594516931736795911860337145196909327055774223216416471543284065751978043583956970\n329156710159042077547116202287118145596233464533929849882925970439451186826150374182\n235111935827887198247940144490798675425881046095664178487804264599607990590107410130\n149616686435928217066871001039599157089197029333604477219511804745205084920977442810\n126598734676554645210429308571968517537012870974588403801125373245942764163903990..." }, { "input": "48", "output": "183504865913665958232517282775068366169900156477665891309731228519994036655578833606465\n122336577275777305488344855183378910779933437651777260873154152346662691103719222404310\n73401946365466383293006913110027346467960062591066356523892491407997614662231533442586\n52429961689618845209290652221448104619971473279333111802780351005712581901593952458990\n33364521075211992405912233231830612030890937541393798419951132458180733937377969746630\n282315178328716858819257358115489794107538702273332140476509582338452..." }, { "input": "49", "output": "41655604562402172518781423189940519120567335520430157327308988874038646320816395228667555\n27770403041601448345854282126627012747044890346953438218205992582692430880544263485778370\n16662241824960869007512569275976207648226934208172062930923595549615458528326558091467022\n11901601303543477862508978054268719748733524434408616379231139678296756091661827208190730\n7573746284073122276142076943625548931012242821896392241328907068007026603784799132485010\n640855454806187269519714202922161832624112854160463958881..." }, { "input": "50", "output": "9539133444790097506800945910496378878609919834178506027953758452154850007466954507364870095\n6359422296526731671200630606997585919073279889452337351969172301436566671644636338243246730\n3815653377916039002720378364198551551443967933671402411181503380861940002986781802945948038\n2725466698511456430514555974427536822459977095479573150843930986329957144990558430675677170\n1734387899052745001236535620090250705201803606214273823264319718573609092266719001339067290\n1467558991506168847200145524691750596709218436..." } ]
154
2,355,200
3.957113
6,980
11
How Many Squares?
[ "implementation" ]
C. How Many Squares?
2
64
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2<=Γ—<=2. We are only interested in two types of squares: 1. squares with each side parallel to a side of the matrix; 1. squares with each side parallel to a diagonal of the matrix. Regardless of type, a square must contain at least one 1 and can't touch (by side or corner) any foreign 1. Of course, the lengths of the sides of each square should be equal. How many squares are in the given matrix?
The first line contains integer *t* (1<=≀<=*t*<=≀<=10000), where *t* is the number of test cases in the input. Then test cases follow. Each case starts with a line containing integers *n* and *m* (2<=≀<=*n*,<=*m*<=≀<=250), where *n* is the number of rows and *m* is the number of columns. The following *n* lines contain *m* characters each (0 or 1). The total number of characters in all test cases doesn't exceed 106 for any input file.
You should output exactly *t* lines, with the answer to the *i*-th test case on the *i*-th line.
[ "2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000\n", "1\n12 11\n11111111111\n10000000001\n10111111101\n10100000101\n10101100101\n10101100101\n10100000101\n10100000101\n10111111101\n10000000001\n11111111111\n00000000000\n" ]
[ "1\n2\n", "3\n" ]
none
[ { "input": "2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000", "output": "1\n2" }, { "input": "1\n12 11\n11111111111\n10000000001\n10111111101\n10100000101\n10101100101\n10101100101\n10100000101\n10100000101\n10111111101\n10000000001\n11111111111\n00000000000", "output": "3" } ]
2,000
6,963,200
0
6,982
493
Vasya and Basketball
[ "binary search", "brute force", "data structures", "implementation", "sortings", "two pointers" ]
null
null
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of *d* meters, and a throw is worth 3 points if the distance is larger than *d* meters, where *d* is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of *d*. Help him to do that.
The first line contains integer *n* (1<=≀<=*n*<=≀<=2Β·105) β€” the number of throws of the first team. Then follow *n* integer numbers β€” the distances of throws *a**i* (1<=≀<=*a**i*<=≀<=2Β·109). Then follows number *m* (1<=≀<=*m*<=≀<=2Β·105) β€” the number of the throws of the second team. Then follow *m* integer numbers β€” the distances of throws of *b**i* (1<=≀<=*b**i*<=≀<=2Β·109).
Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction *a*<=-<=*b* is maximum. If there are several such scores, find the one in which number *a* is maximum.
[ "3\n1 2 3\n2\n5 6\n", "5\n6 7 8 9 10\n5\n1 2 3 4 5\n" ]
[ "9:6\n", "15:10\n" ]
none
[ { "input": "3\n1 2 3\n2\n5 6", "output": "9:6" }, { "input": "5\n6 7 8 9 10\n5\n1 2 3 4 5", "output": "15:10" }, { "input": "5\n1 2 3 4 5\n5\n6 7 8 9 10", "output": "15:15" }, { "input": "3\n1 2 3\n3\n6 4 5", "output": "9:9" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n1\n11", "output": "30:3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 11\n1\n10", "output": "30:3" }, { "input": "3\n1 2 3\n3\n1 2 3", "output": "9:9" }, { "input": "3\n1 2 3\n3\n3 4 5", "output": "9:9" }, { "input": "4\n2 5 3 2\n4\n1 5 6 2", "output": "12:11" }, { "input": "2\n3 3\n3\n1 3 3", "output": "6:8" }, { "input": "3\n1 1 1\n4\n1 3 1 1", "output": "6:8" }, { "input": "4\n4 2 1 1\n4\n3 2 2 2", "output": "9:8" }, { "input": "3\n3 9 4\n2\n10 1", "output": "9:5" }, { "input": "14\n4336 24047 24846 25681 28597 30057 32421 34446 48670 67750 68185 69661 85721 89013\n30\n8751 10576 14401 22336 22689 35505 38649 43073 43176 44359 44777 50210 50408 51361 53181 60095 65554 68201 68285 68801 72501 75881 80251 80509 83306 93167 95365 95545 97201 97731", "output": "28:60" }, { "input": "1\n1\n2\n1 2", "output": "2:4" }, { "input": "18\n450 3726 12063 27630 29689 30626 33937 35015 45951 46217 53004 59541 75551 75836 78996 81297 93876 96211\n47\n3393 5779 6596 7935 9549 10330 11145 13121 14801 15578 24104 24125 25871 31280 35036 38969 40077 41342 42708 46033 47491 48451 49152 51905 55002 55689 56565 57901 59481 60017 66075 67081 68397 71122 74961 78501 84098 87083 87893 89281 89739 90321 92046 95821 96717 96921 96951", "output": "36:94" }, { "input": "3\n3 3 4\n6\n2 2 3 3 3 3", "output": "7:12" }, { "input": "3\n2 2 2\n3\n1 1 1", "output": "9:6" }, { "input": "2\n2 2\n2\n2 2", "output": "6:6" }, { "input": "1\n7\n6\n6 7 8 9 10 11", "output": "2:12" }, { "input": "1\n1\n2\n1 1", "output": "2:4" }, { "input": "3\n1 2 3\n1\n1", "output": "9:3" }, { "input": "3\n3 3 4\n6\n3 2 2 2 3 2", "output": "9:14" }, { "input": "1\n3\n1\n3", "output": "3:3" }, { "input": "1\n1\n5\n1 1 1 1 1", "output": "2:10" }, { "input": "2\n1 999999999\n2\n2 4", "output": "5:4" } ]
405
99,635,200
0
6,991
713
Sonya and Queries
[ "data structures", "implementation" ]
null
null
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i*Β β€” add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i*Β β€” delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s*Β β€” count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
The first line of the input contains an integer *t* (1<=≀<=*t*<=≀<=100<=000)Β β€” the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i*Β β€” the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≀<=*a**i*<=&lt;<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
[ "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n" ]
[ "2\n1\n2\n1\n1\n", "1\n" ]
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
[ { "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "output": "2\n1\n2\n1\n1" }, { "input": "4\n+ 200\n+ 200\n- 200\n? 0", "output": "1" }, { "input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "output": "3\n2\n3\n4\n4\n2\n2" }, { "input": "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11", "output": "0\n1\n0\n2\n1\n0\n1\n0\n1\n0" }, { "input": "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011", "output": "0\n0\n0\n0\n0" }, { "input": "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396", "output": "1\n1\n1\n1\n1" }, { "input": "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011", "output": "1\n1" }, { "input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29", "output": "1\n1\n1\n1\n1\n1\n1\n1" } ]
77
4,198,400
-1
6,995
630
Parking Lot
[ "combinatorics", "math" ]
null
null
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes. The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever. Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly *n* successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.
The only line of the input contains one integer *n* (3<=≀<=*n*<=≀<=30) β€” the amount of successive cars of the same make.
Output one integer β€” the number of ways to fill the parking lot by cars of four makes using the described way.
[ "3\n" ]
[ "24" ]
Let's denote car makes in the following way: A β€” Aston Martin, B β€” Bentley, M β€” Mercedes-Maybach, Z β€” Zaporozhets. For *n* = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM Originally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.
[ { "input": "3", "output": "24" }, { "input": "4", "output": "132" }, { "input": "5", "output": "672" }, { "input": "6", "output": "3264" }, { "input": "7", "output": "15360" }, { "input": "12", "output": "27525120" }, { "input": "15", "output": "2214592512" }, { "input": "28", "output": "280349076803813376" }, { "input": "29", "output": "1161928703861587968" }, { "input": "30", "output": "4809844402031689728" } ]
15
409,600
0
7,003
366
Dima and To-do List
[ "brute force", "implementation" ]
null
null
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks. Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one. Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
The first line of the input contains two integers *n*,<=*k*Β (1<=≀<=*k*<=≀<=*n*<=≀<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*Β (1<=≀<=*a**i*<=≀<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task. It is guaranteed that *n* is divisible by *k*.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
[ "6 2\n3 2 1 6 5 4\n", "10 5\n1 3 5 7 9 9 4 1 8 5\n" ]
[ "1\n", "3\n" ]
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12. Explanation of the second example. In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
[ { "input": "6 2\n3 2 1 6 5 4", "output": "1" }, { "input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3" }, { "input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 10\n8 4 5 7 6 9 2 2 3 5", "output": "7" }, { "input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "4 2\n2 1 1 3", "output": "1" }, { "input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5", "output": "1" }, { "input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4", "output": "1" } ]
171
29,388,800
3
7,018
280
k-Maximum Subsequence Sum
[ "data structures", "flows", "graphs", "implementation" ]
null
null
Consider integer sequence *a*1,<=*a*2,<=...,<=*a**n*. You should run queries of two types: - The query format is "0 *i* *val*". In reply to this query you should make the following assignment: *a**i*<==<=*val*. - The query format is "1 *l* *r* *k*". In reply to this query you should print the maximum sum of at most *k* non-intersecting subsegments of sequence *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*. Formally, you should choose at most *k* pairs of integers (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**t*,<=*y**t*) (*l*<=≀<=*x*1<=≀<=*y*1<=&lt;<=*x*2<=≀<=*y*2<=&lt;<=...<=&lt;<=*x**t*<=≀<=*y**t*<=≀<=*r*;Β *t*<=≀<=*k*) such that the sum *a**x*1<=+<=*a**x*1<=+<=1<=+<=...<=+<=*a**y*1<=+<=*a**x*2<=+<=*a**x*2<=+<=1<=+<=...<=+<=*a**y*2<=+<=...<=+<=*a**x**t*<=+<=*a**x**t*<=+<=1<=+<=...<=+<=*a**y**t* is as large as possible. Note that you should choose at most *k* subsegments. Particularly, you can choose 0 subsegments. In this case the described sum considered equal to zero.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105), showing how many numbers the sequence has. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≀<=500). The third line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. The next *m* lines contain the queries in the format, given in the statement. All changing queries fit into limits: 1<=≀<=*i*<=≀<=*n*, |*val*|<=≀<=500. All queries to count the maximum sum of at most *k* non-intersecting subsegments fit into limits: 1<=≀<=*l*<=≀<=*r*<=≀<=*n*, 1<=≀<=*k*<=≀<=20. It is guaranteed that the number of the queries to count the maximum sum of at most *k* non-intersecting subsegments doesn't exceed 10000.
For each query to count the maximum sum of at most *k* non-intersecting subsegments print the reply β€” the maximum sum. Print the answers to the queries in the order, in which the queries follow in the input.
[ "9\n9 -8 9 -1 -1 -1 9 -8 9\n3\n1 1 9 1\n1 1 9 2\n1 4 6 3\n", "15\n-4 8 -3 -10 10 4 -7 -7 0 -6 3 8 -10 7 2\n15\n1 3 9 2\n1 6 12 1\n0 6 5\n0 10 -7\n1 4 9 1\n1 7 9 1\n0 10 -3\n1 4 10 2\n1 3 13 2\n1 4 11 2\n0 15 -9\n0 13 -9\n0 11 -10\n1 5 14 2\n1 6 12 1\n" ]
[ "17\n25\n0\n", "14\n11\n15\n0\n15\n26\n18\n23\n8\n" ]
In the first query of the first example you can select a single pair (1, 9). So the described sum will be 17. Look at the second query of the first example. How to choose two subsegments? (1, 3) and (7, 9)? Definitely not, the sum we could get from (1, 3) and (7, 9) is 20, against the optimal configuration (1, 7) and (9, 9) with 25. The answer to the third query is 0, we prefer select nothing if all of the numbers in the given interval are negative.
[]
46
0
0
7,038
9
Running Student
[ "brute force", "geometry", "implementation" ]
B. Running Student
1
64
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes *n* stops, the *i*-th stop is in point (*x**i*,<=0) - coordinates of all the stops are different - the minibus drives at a constant speed, equal to *v**b* - it can be assumed the passengers get on and off the minibus at a bus stop momentarily - Student can get off the minibus only at a bus stop - Student will have to get off the minibus at a terminal stop, if he does not get off earlier - the University, where the exam will be held, is in point (*x**u*,<=*y**u*) - Student can run from a bus stop to the University at a constant speed *v**s* as long as needed - a distance between two points can be calculated according to the following formula: - Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
The first line contains three integer numbers: 2<=≀<=*n*<=≀<=100, 1<=≀<=*v**b*,<=*v**s*<=≀<=1000. The second line contains *n* non-negative integers in ascending order: coordinates *x**i* of the bus stop with index *i*. It is guaranteed that *x*1 equals to zero, and *x**n*<=≀<=105. The third line contains the coordinates of the University, integers *x**u* and *y**u*, not exceeding 105 in absolute value.
In the only line output the answer to the problem β€” index of the optimum bus stop.
[ "4 5 2\n0 2 4 6\n4 1\n", "2 1 1\n0 100000\n100000 100000\n" ]
[ "3", "2" ]
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
[ { "input": "4 5 2\n0 2 4 6\n4 1", "output": "3" }, { "input": "2 1 1\n0 100000\n100000 100000", "output": "2" }, { "input": "6 5 1\n0 1 2 3 4 5\n0 0", "output": "2" }, { "input": "4 100 10\n0 118 121 178\n220 220", "output": "4" }, { "input": "4 3 3\n0 6 8 10\n7 -4", "output": "2" }, { "input": "5 900 1\n0 37474 80030 85359 97616\n-1 -1", "output": "2" }, { "input": "5 200 400\n0 8068 28563 51720 66113\n5423 -34", "output": "2" }, { "input": "6 10 3\n0 12 14 16 19 20\n14 0", "output": "3" }, { "input": "6 13 11\n0 16 27 31 39 42\n54 3", "output": "6" }, { "input": "11 853 721\n0 134 1971 2369 3381 3997 4452 6875 8983 9360 9399\n7345 333", "output": "8" }, { "input": "35 35 12\n0 90486 90543 90763 91127 91310 92047 92405 93654 93814 94633 94752 94969 94994 95287 96349 96362 96723 96855 96883 97470 97482 97683 97844 97926 98437 98724 98899 98921 99230 99253 99328 99444 99691 99947\n96233 -7777", "output": "9" }, { "input": "55 11 44\n0 3343 3387 3470 3825 3832 3971 4026 4043 4389 4492 4886 5015 5084 5161 5436 5595 5616 5677 5987 6251 6312 6369 6469 6487 6493 6507 6641 6928 7067 7159 7280 7303 7385 7387 7465 7536 7572 7664 7895 7921 7955 8110 8191 8243 8280 8523 8525 8581 8877 9221 9462 9505 9594 9596\n8000 0", "output": "2" }, { "input": "72 1000 777\n0 215 2814 5104 5226 5925 6734 9213 11697 13739 14015 16101 17234 19013 19566 19683 20283 20837 21332 21432 25490 26284 27728 29911 30112 30133 31494 31595 32499 32932 33289 36611 37736 43548 44440 44537 47656 47699 48327 50942 52178 53759 56925 57671 62024 65441 67958 70346 71606 75235 75466 75553 75905 76173 76512 77784 78183 80425 81339 81543 84537 88384 89953 90214 92107 92274 93328 93550 93987 97546 99459 99532\n63421 35", "output": "45" }, { "input": "76 1 1\n0 1000 1754 2749 3687 4983 8121 10299 11043 12986 14125 15910 17070 17189 17551 17953 17973 20816 25436 26150 27446 27788 28466 28941 29537 33965 37566 40845 40930 41304 41614 41615 43042 45098 45844 49878 50453 50936 55480 58410 59258 59287 62789 64127 64333 64450 64862 65404 66451 67626 69294 69804 71988 72165 74196 74560 75407 76611 77055 77344 79470 83566 84550 87458 87627 88205 89880 90255 90586 91970 93795 95308 99032 99442 99547 99549\n0 0", "output": "2" }, { "input": "94 2 1\n0 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093\n5050 -100000", "output": "2" }, { "input": "100 1 2\n0 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n100 0", "output": "2" }, { "input": "100 1000 1\n0 505 506 514 515 520 523 527 529 530 538 547 550 554 559 562 566 568 569 580 582 584 588 597 609 621 624 629 630 631 634 641 646 653 657 666 673 678 680 683 685 690 695 698 699 700 705 709 716 731 734 735 736 738 756 761 762 765 769 772 776 779 784 790 794 812 814 816 833 837 842 845 850 854 855 863 868 872 882 892 893 898 899 900 901 902 915 916 917 932 936 954 962 968 975 978 983 992 996 998\n600 7778", "output": "23" }, { "input": "2 1 1\n0 100000\n-100000 -100000", "output": "2" }, { "input": "2 1000 1000\n0 1\n1 0", "output": "2" }, { "input": "3 1 1\n0 1 2\n2 0", "output": "3" } ]
124
0
0
7,061
155
Combination
[ "greedy", "sortings" ]
null
null
Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number *a**i*, and the bottom contains number *b**i*, then when the player is playing the card, he gets *a**i* points and also gets the opportunity to play additional *b**i* cards. After the playing the card is discarded. More formally: let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number *b**i*, which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards. Of course, Ilya wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards Ilya has. Each of the next *n* lines contains two non-negative space-separated integers β€” *a**i* and *b**i* (0<=≀<=*a**i*,<=*b**i*<=≀<=104) β€” the numbers, written at the top and the bottom of the *i*-th card correspondingly.
Print the single number β€” the maximum number of points you can score in one round by the described rules.
[ "2\n1 0\n2 0\n", "3\n1 0\n2 0\n0 2\n" ]
[ "2\n", "3\n" ]
In the first sample none of two cards brings extra moves, so you should play the one that will bring more points. In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.
[ { "input": "2\n1 0\n2 0", "output": "2" }, { "input": "3\n1 0\n2 0\n0 2", "output": "3" }, { "input": "5\n0 0\n2 0\n2 0\n3 0\n5 1", "output": "8" }, { "input": "7\n9 1\n8 1\n9 0\n9 1\n5 1\n1 1\n0 1", "output": "41" }, { "input": "7\n5 0\n4 0\n3 0\n5 2\n3 0\n4 2\n0 0", "output": "21" }, { "input": "1\n7 0", "output": "7" }, { "input": "1\n10 1", "output": "10" }, { "input": "10\n18 0\n4 0\n10 0\n5 0\n1 0\n18 0\n19 0\n11 1\n11 1\n0 1", "output": "41" }, { "input": "20\n33 0\n53 0\n91 0\n15 0\n35 0\n55 0\n23 0\n70 0\n98 0\n98 0\n56 0\n65 0\n20 0\n45 0\n71 0\n80 0\n39 0\n41 0\n47 0\n79 0", "output": "98" }, { "input": "20\n20 0\n36 0\n27 0\n25 0\n0 0\n24 0\n90 0\n94 0\n100 0\n72 0\n50 0\n6 0\n16 0\n85 0\n22 4\n60 0\n48 0\n13 0\n13 0\n7 0", "output": "391" }, { "input": "50\n35 0\n72 0\n28 0\n47 0\n20 0\n94 0\n82 0\n23 0\n71 0\n92 0\n79 0\n74 0\n19 4\n36 0\n59 0\n71 0\n53 0\n36 0\n11 4\n31 0\n77 0\n47 0\n71 0\n69 0\n53 0\n2 0\n56 0\n69 0\n13 0\n78 0\n84 0\n33 0\n77 0\n28 0\n14 2\n32 0\n86 0\n7 0\n6 0\n52 0\n89 0\n66 1\n0 0\n2 0\n41 0\n81 0\n5 0\n5 0\n58 4\n57 0", "output": "1087" }, { "input": "50\n137 0\n174 1\n10 0\n58 0\n85 3\n35 0\n125 0\n53 0\n185 0\n19 0\n192 0\n182 0\n70 0\n174 1\n86 0\n153 0\n9 0\n87 2\n158 0\n171 0\n45 0\n29 0\n27 0\n115 0\n106 1\n159 3\n13 0\n61 3\n106 0\n140 0\n18 0\n144 2\n176 0\n3 0\n112 0\n106 2\n6 0\n182 0\n128 0\n23 1\n127 0\n127 0\n50 0\n19 0\n119 0\n180 0\n29 0\n130 0\n127 0\n37 0", "output": "2838" }, { "input": "100\n0 0\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 0\n1 0\n0 0\n0 0\n1 0\n1 0\n1 0\n0 0\n0 0\n1 0\n0 0\n1 0\n1 0\n1 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 0\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n1 0\n0 0\n1 0\n1 0\n0 0\n0 0\n0 0\n1 0\n1 0\n1 0\n0 0\n0 0\n1 0\n1 0\n0 0\n1 0\n1 0\n1 0\n0 0\n0 0\n0 0\n1 0", "output": "1" }, { "input": "100\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1", "output": "0" }, { "input": "1\n0 0", "output": "0" }, { "input": "1\n0 10000", "output": "0" }, { "input": "1\n2 9999", "output": "2" }, { "input": "2\n0 10000\n1 0", "output": "1" }, { "input": "7\n1 1000\n100 1000\n3 1000\n4 1000\n5 1000\n6 1000\n7 1000", "output": "126" } ]
154
6,451,200
0
7,082
926
Choose Place
[]
null
null
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the places are shown on the picture: Here, the desks in the top row are the closest to the blackboard, while the desks in the bottom row are the furthest from the blackboard. You are given a plan of the class, where '*' denotes an occupied place, '.' denotes a vacant place, and the aisles are denoted by '-'. Find any of the most convenient vacant places for Petya.
The input consists of 6 lines. Each line describes one row of desks, starting from the closest to the blackboard. Each line is given in the following format: two characters, each is '*' or '.' β€” the description of the left desk in the current row; a character '-' β€” the aisle; two characters, each is '*' or '.' β€” the description of the center desk in the current row; a character '-' β€” the aisle; two characters, each is '*' or '.' β€” the description of the right desk in the current row. So, the length of each of the six lines is 8. It is guaranteed that there is at least one vacant place in the classroom.
Print the plan of the classroom after Petya takes one of the most convenient for him places. Mark this place with the letter 'P'. There should be exactly one letter 'P' in the plan. Petya can only take a vacant place. In all other places the output should coincide with the input. If there are multiple answers, print any.
[ "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..\n", "**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n" ]
[ "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-..\n", "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-..\n", "**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..\n" ]
In the first example the maximum convenience is 3. In the second example the maximum convenience is 2. In the third example the maximum convenience is 4.
[ { "input": "..-**-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-**-..\n..-**-..\n..-..-..\n..-P.-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-..-..\n..-**-..", "output": "**-**-**\n**-**-**\n..-**-.*\n**-**-**\n..-P.-..\n..-**-.." }, { "input": "**-**-*.\n*.-*.-**\n**-**-**\n**-**-**\n..-..-..\n..-**-..", "output": "**-**-*.\n*.-*P-**\n**-**-**\n**-**-**\n..-..-..\n..-**-.." }, { "input": "..-..-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-..-..\n..-P.-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n..-**-..\n..-**-..\n..-..-..\n..-..-..", "output": "**-**-**\n**-**-**\n..-**-..\n..-**-..\n..-..-..\n..-P.-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\nP.-**-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n*.-**-*.", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n..-**-..\n*P-**-*." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n*.-**-..\n.*-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n*.-**-..\nP*-**-**" }, { "input": "**-**-**\n**-**-**\n.*-**-..\n..-**-..\n**-**-..\n.*-..-*.", "output": "**-**-**\n**-**-**\n.*-**-..\n..-**-..\n**-**-..\n.*-P.-*." }, { "input": "**-**-**\n**-**-**\n..-**-**\n*.-**-*.\n*.-..-.*\n*.-*.-.*", "output": "**-**-**\n**-**-**\n..-**-**\n*.-**-*.\n*.-..-.*\n*.-*P-.*" }, { "input": "*.-**-*.\n.*-**-..\n**-*.-.*\n**-*.-..\n..-.*-*.\n*.-..-..", "output": "*.-**-*.\n.*-**-..\n**-*.-.*\n**-*P-..\n..-.*-*.\n*.-..-.." }, { "input": "*.-**-.*\n**-**-.*\n*.-..-..\n..-.*-**\n*.-**-.*\n.*-..-..", "output": "*.-**-.*\n**-**-.*\n*.-..-..\n..-P*-**\n*.-**-.*\n.*-..-.." }, { "input": "..-..-*.\n*.-.*-**\n.*-..-..\n..-..-*.\n..-..-.*\n.*-**-..", "output": "..-..-*.\n*.-P*-**\n.*-..-..\n..-..-*.\n..-..-.*\n.*-**-.." }, { "input": "..-**-.*\n..-*.-*.\n**-*.-**\n..-..-*.\n.*-.*-..\n**-..-..", "output": "..-**-.*\n..-*P-*.\n**-*.-**\n..-..-*.\n.*-.*-..\n**-..-.." }, { "input": "..-.*-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-P*-..\n..-**-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "..-**-..\n..-**-*.\n*.-..-..\n..-..-..\n..-**-..\n..-..-..", "output": "..-**-..\n..-**-*.\n*.-..-..\n..-P.-..\n..-**-..\n..-..-.." }, { "input": "**-.*-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**", "output": "**-P*-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**" }, { "input": "**-**-**\n**-**-**\n**-**-*.\n**-*.-**\n**-**-**\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-*.\n**-*P-**\n**-**-**\n**-*.-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-*P-**" }, { "input": "..-**-..\n..-.*-..\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "..-**-..\n..-P*-..\n..-..-..\n..-..-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-..\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-..\n..-**-.." }, { "input": "**-**-**\n*.-**-**\n..-..-..\n..-..-..\n..-..-..\n..-..-..", "output": "**-**-**\n*.-**-**\n..-..-..\n..-P.-..\n..-..-..\n..-..-.." }, { "input": "**-**-**\n*.-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**", "output": "**-**-**\n*P-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-.*", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-P*" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-.*-**\n**-**-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-P*-**\n**-**-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-.*\n**-**-**\n**-**-**\n..-**-..", "output": "**-**-**\n**-**-**\n**-**-P*\n**-**-**\n**-**-**\n..-**-.." }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*P\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*.-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-*P-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-.*-**\n**-**-**", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-P*-**\n**-**-**" }, { "input": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*.", "output": "**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-**\n**-**-*P" }, { "input": "**-**-**\n**-**-**\n**-*.-**\n**-**-**\n..-**-..\n..-..-..", "output": "**-**-**\n**-**-**\n**-*P-**\n**-**-**\n..-**-..\n..-..-.." } ]
46
0
0
7,086
342
Xenia and Tree
[ "data structures", "divide and conquer", "trees" ]
null
null
Xenia the programmer has a tree consisting of *n* nodes. We will consider the tree nodes indexed from 1 to *n*. We will also consider the first node to be initially painted red, and the other nodes β€” to be painted blue. The distance between two tree nodes *v* and *u* is the number of edges in the shortest path between *v* and *u*. Xenia needs to learn how to quickly execute queries of two types: 1. paint a specified blue node in red; 1. calculate which red node is the closest to the given one and print the shortest distance to the closest red node. Your task is to write a program which will execute the described queries.
The first line contains two integers *n* and *m* (2<=≀<=*n*<=≀<=105,<=1<=≀<=*m*<=≀<=105) β€” the number of nodes in the tree and the number of queries. Next *n*<=-<=1 lines contain the tree edges, the *i*-th line contains a pair of integers *a**i*,<=*b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*,<=*a**i*<=β‰ <=*b**i*) β€” an edge of the tree. Next *m* lines contain queries. Each query is specified as a pair of integers *t**i*,<=*v**i* (1<=≀<=*t**i*<=≀<=2,<=1<=≀<=*v**i*<=≀<=*n*). If *t**i*<==<=1, then as a reply to the query we need to paint a blue node *v**i* in red. If *t**i*<==<=2, then we should reply to the query by printing the shortest distance from some red node to node *v**i*. It is guaranteed that the given graph is a tree and that all queries are correct.
For each second type query print the reply in a single line.
[ "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5\n" ]
[ "0\n3\n2\n" ]
none
[ { "input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5", "output": "0\n3\n2" } ]
77
3,891,200
-1
7,094
988
Substrings Sort
[ "sortings", "strings" ]
null
null
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
The first line contains an integer $n$ ($1 \le n \le 100$) β€” the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order.
[ "5\na\naba\nabacaba\nba\naba\n", "5\na\nabacaba\nba\naba\nabab\n", "3\nqwerty\nqwerty\nqwerty\n" ]
[ "YES\na\nba\naba\naba\nabacaba\n", "NO\n", "YES\nqwerty\nqwerty\nqwerty\n" ]
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
[ { "input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba" }, { "input": "5\na\nabacaba\nba\naba\nabab", "output": "NO" }, { "input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty" }, { "input": "1\nwronganswer", "output": "YES\nwronganswer" }, { "input": "3\na\nb\nab", "output": "NO" }, { "input": "2\nababaab\nabaab", "output": "YES\nabaab\nababaab" }, { "input": "2\nq\nqq", "output": "YES\nq\nqq" }, { "input": "5\nabab\nbab\nba\nab\na", "output": "NO" }, { "input": "3\nb\nc\nd", "output": "NO" }, { "input": "3\naba\nbab\nababa", "output": "NO" }, { "input": "4\na\nba\nabacabac\nb", "output": "NO" }, { "input": "4\nab\nba\nabab\na", "output": "NO" }, { "input": "3\naaa\naab\naaab", "output": "NO" }, { "input": "2\nac\nabac", "output": "YES\nac\nabac" }, { "input": "2\na\nb", "output": "NO" }, { "input": "3\nbaa\nbaaaaaaaab\naaaaaa", "output": "NO" }, { "input": "3\naaab\naab\naaaab", "output": "YES\naab\naaab\naaaab" }, { "input": "2\naaba\naba", "output": "YES\naba\naaba" }, { "input": "10\na\nb\nc\nd\nab\nbc\ncd\nabc\nbcd\nabcd", "output": "NO" }, { "input": "5\na\nab\nae\nabcd\nabcde", "output": "NO" }, { "input": "3\nv\nab\nvab", "output": "NO" }, { "input": "4\na\nb\nc\nabc", "output": "NO" }, { "input": "2\nab\naab", "output": "YES\nab\naab" }, { "input": "3\nabc\na\nc", "output": "NO" }, { "input": "2\nabaab\nababaab", "output": "YES\nabaab\nababaab" }, { "input": "3\ny\nxx\nxxy", "output": "NO" }, { "input": "4\naaaa\naaaa\naaaa\nab", "output": "NO" }, { "input": "3\nbad\naba\nabad", "output": "NO" }, { "input": "3\nabcabc\nab\nbc", "output": "NO" }, { "input": "2\naaaab\naaaaab", "output": "YES\naaaab\naaaaab" }, { "input": "5\nab\naba\naba\naba\nabd", "output": "NO" }, { "input": "4\nded\nd\ne\nd", "output": "NO" }, { "input": "5\nekgetterherforme\ner\nter\nher\ntter", "output": "NO" }, { "input": "3\naa\nbba\ncbba", "output": "NO" }, { "input": "3\nab\naa\naab", "output": "NO" }, { "input": "6\naaaa\naaaa\naaaa\naaaaab\nab\nab", "output": "NO" }, { "input": "3\na\nbcd\nabcd", "output": "NO" }, { "input": "3\naa\nab\naab", "output": "NO" }, { "input": "3\nabcde\nab\ncde", "output": "NO" }, { "input": "4\nanoop\np\nan\noop", "output": "NO" }, { "input": "3\nab\ncd\nabcd", "output": "NO" }, { "input": "3\nafaba\nafab\nfaba", "output": "NO" }, { "input": "3\nababc\nabababc\nab", "output": "YES\nab\nababc\nabababc" }, { "input": "3\na\nba\nbbab", "output": "YES\na\nba\nbbab" }, { "input": "2\naabaa\naba", "output": "YES\naba\naabaa" }, { "input": "3\nbc\nbca\na", "output": "NO" }, { "input": "2\naba\nabba", "output": "NO" }, { "input": "7\na\nb\nc\nab\nac\nac\nac", "output": "NO" }, { "input": "2\naa\nmmmmmmmammmmmmmm", "output": "NO" } ]
46
0
3
7,097
474
Flowers
[ "dp" ]
null
null
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size *k*. Now Marmot wonders in how many ways he can eat between *a* and *b* flowers. As the number of ways could be very large, print it modulo 1000000007 (109<=+<=7).
Input contains several test cases. The first line contains two integers *t* and *k* (1<=≀<=*t*,<=*k*<=≀<=105), where *t* represents the number of test cases. The next *t* lines contain two integers *a**i* and *b**i* (1<=≀<=*a**i*<=≀<=*b**i*<=≀<=105), describing the *i*-th test.
Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7).
[ "3 2\n1 3\n2 3\n4 4\n" ]
[ "6\n5\n5\n" ]
- For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*).
[ { "input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5" }, { "input": "1 1\n1 3", "output": "14" }, { "input": "1 2\n64329 79425", "output": "0" } ]
1,076
9,420,800
3
7,099
992
Nastya and a Wardrobe
[ "math" ]
null
null
Nastya received a gift on New YearΒ β€” a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer.
The only line contains two integers *x* and *k* (0<=≀<=*x*,<=*k*<=≀<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland.
In the only line print a single integerΒ β€” the expected number of dresses Nastya will own one year later modulo 109<=+<=7.
[ "2 0\n", "2 1\n", "3 2\n" ]
[ "4\n", "7\n", "21\n" ]
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
[ { "input": "2 0", "output": "4" }, { "input": "2 1", "output": "7" }, { "input": "3 2", "output": "21" }, { "input": "1 411", "output": "485514976" }, { "input": "1 692", "output": "860080936" }, { "input": "16 8", "output": "7937" }, { "input": "18 12", "output": "143361" }, { "input": "1 1000000000000000000", "output": "719476261" }, { "input": "0 24", "output": "0" }, { "input": "24 0", "output": "48" }, { "input": "1000000000000000000 1", "output": "195" }, { "input": "348612312017571993 87570063840727716", "output": "551271547" }, { "input": "314647997243943415 107188213956410843", "output": "109575135" }, { "input": "375000003 2", "output": "0" }, { "input": "451 938", "output": "598946958" }, { "input": "4 1669", "output": "185365669" }, { "input": "24 347", "output": "860029201" }, { "input": "1619 1813", "output": "481568710" }, { "input": "280 472", "output": "632090765" }, { "input": "1271 237", "output": "27878991" }, { "input": "626 560", "output": "399405853" }, { "input": "167 887", "output": "983959273" }, { "input": "1769 422", "output": "698926874" }, { "input": "160 929", "output": "752935252" }, { "input": "1075 274", "output": "476211777" }, { "input": "1332 332", "output": "47520583" }, { "input": "103872254428948073 97291596742897547", "output": "283633261" }, { "input": "157600018563121064 54027847222622605", "output": "166795759" }, { "input": "514028642164226185 95344332761644668", "output": "718282571" }, { "input": "91859547444219924 75483775868568438", "output": "462306789" }, { "input": "295961633522750187 84483303945499729", "output": "11464805" }, { "input": "8814960236468055 86463151557693391", "output": "430718856" }, { "input": "672751296745170589 13026894786355983", "output": "260355651" }, { "input": "909771081413191574 18862935031728197", "output": "800873185" }, { "input": "883717267463724670 29585639347346605", "output": "188389362" }, { "input": "431620727626880523 47616788361847228", "output": "311078131" }, { "input": "816689044159694273 6475970360049048", "output": "211796030" }, { "input": "313779810374175108 13838123840048842", "output": "438854949" }, { "input": "860936792402722414 59551033597232946", "output": "359730003" }, { "input": "332382902893992163 15483141652464187", "output": "719128379" }, { "input": "225761360057436129 49203610094504526", "output": "54291755" }, { "input": "216006901533424028 8313457244750219", "output": "362896012" }, { "input": "568001660010321225 97167523790774710", "output": "907490480" }, { "input": "904089164817530426 53747406876903279", "output": "702270335" }, { "input": "647858974461637674 18385058205826214", "output": "375141527" }, { "input": "720433754707338458 94180351080265292", "output": "273505123" }, { "input": "268086842387268316 76502855388264782", "output": "288717798" }, { "input": "488603693655520686 79239542983498430", "output": "316399174" }, { "input": "152455635055802121 50394545488662355", "output": "697051907" }, { "input": "585664029992038779 34972826534657555", "output": "699566354" }, { "input": "349532090641396787 12248820623854158", "output": "233938854" }, { "input": "353579407209009179 74469254935824590", "output": "771349161" }, { "input": "491414900908765740 49509676303815755", "output": "237095803" }, { "input": "91142854626119420 900651524977956", "output": "211575546" }, { "input": "73543340229981083 66918326344192076", "output": "710215652" }, { "input": "463958371369193376 89203995753927042", "output": "41857490" }, { "input": "911873413622533246 54684577459651780", "output": "926432198" }, { "input": "316313018463929883 78259904441946885", "output": "36284201" }, { "input": "889560480100219043 54181377424922141", "output": "281123162" }, { "input": "0 3259862395629356", "output": "0" }, { "input": "1 3", "output": "9" }, { "input": "3 1", "output": "11" }, { "input": "1000000007 1", "output": "1000000006" }, { "input": "1000000007 2", "output": "1000000004" }, { "input": "1000000007 0", "output": "0" }, { "input": "1000000007 12", "output": "999995912" }, { "input": "1000000007 70", "output": "729983755" }, { "input": "250000002 1", "output": "0" }, { "input": "1000000007 3", "output": "1000000000" }, { "input": "999999999 0", "output": "999999991" }, { "input": "1000000007 5", "output": "999999976" }, { "input": "1000000007 1000000007", "output": "1000000006" }, { "input": "10000000000000000 0", "output": "860000007" }, { "input": "1000000000000 0", "output": "999986007" }, { "input": "99999999999999999 0", "output": "600000012" }, { "input": "1000000000000000 0", "output": "986000007" } ]
93
0
0
7,104
0
none
[ "none" ]
null
null
This is an interactive problem. Jury has hidden a permutation *p* of integers from 0 to *n*<=-<=1. You know only the length *n*. Remind that in permutation all integers are distinct. Let *b* be the inverse permutation for *p*, i.e. *p**b**i*<==<=*i* for all *i*. The only thing you can do is to ask xor of elements *p**i* and *b**j*, printing two indices *i* and *j* (not necessarily distinct). As a result of the query with indices *i* and *j* you'll get the value , where denotes the xor operation. You can find the description of xor operation in notes. Note that some permutations can remain indistinguishable from the hidden one, even if you make all possible *n*2 queries. You have to compute the number of permutations indistinguishable from the hidden one, and print one of such permutations, making no more than 2*n* queries. The hidden permutation does not depend on your queries.
The first line contains single integer *n* (1<=≀<=*n*<=≀<=5000) β€” the length of the hidden permutation. You should read this integer first.
When your program is ready to print the answer, print three lines. In the first line print "!". In the second line print single integer *answers*_*cnt*Β β€” the number of permutations indistinguishable from the hidden one, including the hidden one. In the third line print *n* integers *p*0,<=*p*1,<=...,<=*p**n*<=-<=1 (0<=≀<=*p**i*<=&lt;<=*n*, all *p**i* should be distinct)Β β€” one of the permutations indistinguishable from the hidden one. Your program should terminate after printing the answer.
[ "3\n0\n0\n3\n2\n3\n2", "4\n2\n3\n2\n0\n2\n3\n2\n0" ]
[ "? 0 0\n? 1 1\n? 1 2\n? 0 2\n? 2 1\n? 2 0\n!\n1\n0 1 2", "? 0 1\n? 1 2\n? 2 3\n? 3 3\n? 3 2\n? 2 1\n? 1 0\n? 0 0\n!\n2\n3 1 2 0" ]
xor operation, or bitwise exclusive OR, is an operation performed over two integers, in which the *i*-th digit in binary representation of the result is equal to 1 if and only if exactly one of the two integers has the *i*-th digit in binary representation equal to 1. For more information, see [here](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). In the first example *p* = [0, 1, 2], thus *b* = [0, 1, 2], the values <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png" style="max-width: 100.0%;max-height: 100.0%;"/> are correct for the given *i*, *j*. There are no other permutations that give the same answers for the given queries. The answers for the queries are: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b36cf4ccf629eaa3a225cda06a5697eb030eb4d7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/88e848d2e69ecfb3b8c8d63fdc8949c7cc1e9f28.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/233e40a031e99efe33bdf68f4a383163a23e1e7b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3ec81fca9911a6bde9c2c7cae6c189514105085f.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/be5d5595e56564765e3db6b865de2219cdadadeb.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3355af6093e240986c338bf13071b479e2604ca9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example *p* = [3, 1, 2, 0], and *b* = [3, 1, 2, 0], the values <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5dae53b8ed0e62c9af6c21130fc022b384e359ff.png" style="max-width: 100.0%;max-height: 100.0%;"/> match for all pairs *i*, *j*. But there is one more suitable permutation *p* = [0, 2, 1, 3], *b* = [0, 2, 1, 3] that matches all *n*<sup class="upper-index">2</sup> possible queries as well. All other permutations do not match even the shown queries.
[ { "input": "3\n0 1 2", "output": "1\n0 1 2 " }, { "input": "4\n3 1 2 0", "output": "2\n0 2 1 3 " }, { "input": "4\n3 2 1 0", "output": "4\n0 1 2 3 " }, { "input": "8\n2 3 0 1 4 5 6 7", "output": "4\n0 1 2 3 6 7 4 5 " }, { "input": "1\n0", "output": "1\n0 " }, { "input": "10\n0 1 2 3 4 5 6 7 8 9", "output": "2\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "6\n0 1 2 4 3 5", "output": "1\n0 1 2 4 3 5 " }, { "input": "2\n0 1", "output": "2\n0 1 " }, { "input": "10\n6 7 4 5 0 1 8 9 2 3", "output": "2\n6 7 4 5 0 1 8 9 2 3 " }, { "input": "10\n9 8 1 7 6 4 5 2 0 3", "output": "1\n9 8 1 7 6 4 5 2 0 3 " }, { "input": "64\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 62 63 60 61", "output": "4\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 62 63 60 61 " }, { "input": "128\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 126 123 124 125 122 127", "output": "2\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 126 123 124 125 122 127 " } ]
2,000
5,529,600
0
7,111
702
Powers of Two
[ "brute force", "data structures", "implementation", "math" ]
null
null
You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=&lt;<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*).
The first line contains the single positive integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109).
Print the number of pairs of indexes *i*,<=*j* (*i*<=&lt;<=*j*) that *a**i*<=+<=*a**j* is a power of 2.
[ "4\n7 3 2 1\n", "3\n1 1 1\n" ]
[ "2\n", "3\n" ]
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4). In the second example all pairs of indexes (*i*, *j*) (where *i* &lt; *j*) include in answer.
[ { "input": "4\n7 3 2 1", "output": "2" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "1\n1000000000", "output": "0" }, { "input": "10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607", "output": "2" }, { "input": "10\n6 6 7 3 9 14 15 7 2 2", "output": "9" }, { "input": "100\n3 6 12 1 16 4 9 5 4 4 5 8 12 4 6 14 5 1 2 2 2 1 7 1 9 10 6 13 7 8 3 11 8 11 7 5 15 6 14 10 4 2 10 9 1 8 14 9 5 11 3 4 1 12 6 8 13 4 8 5 4 13 13 1 3 9 14 7 14 10 7 3 12 8 9 8 6 15 9 10 12 14 15 4 16 8 8 4 8 7 5 10 16 4 10 13 6 16 16 5", "output": "532" }, { "input": "1\n2", "output": "0" }, { "input": "2\n1 1", "output": "1" } ]
3,000
6,246,400
0
7,124
523
Mean Requests
[ "*special", "implementation" ]
null
null
In this problem you will have to deal with a real algorithm that is used in the VK social network. As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a certain period of time of *T* seconds (for example, *T*<==<=60Β *seconds*<==<=1Β *min* and *T*<==<=86400Β *seconds*<==<=1Β *day*). For example, if this value drops dramatically, that shows that the site has access problem. If this value grows, that may be a reason to analyze the cause for the growth and add more servers to the website if it is really needed. However, even such a natural problem as counting the mean number of queries for some period of time can be a challenge when you process the amount of data of a huge social network. That's why the developers have to use original techniques to solve problems approximately, but more effectively at the same time. Let's consider the following formal model. We have a service that works for *n* seconds. We know the number of queries to this resource *a**t* at each moment of time *t* (1<=≀<=*t*<=≀<=*n*). Let's formulate the following algorithm of calculating the mean with exponential decay. Let *c* be some real number, strictly larger than one. Thus, the mean variable is recalculated each second using the number of queries that came at that second. We can make some mathematical calculations and prove that choosing the value of constant *c* correctly will make the value of mean not very different from the real mean value *a**x* at *t*<=-<=*T*<=+<=1<=≀<=*x*<=≀<=*t*. The advantage of such approach is that it only uses the number of requests at the current moment of time and doesn't require storing the history of requests for a large time range. Also, it considers the recent values with the weight larger than the weight of the old ones, which helps to react to dramatic change in values quicker. However before using the new theoretical approach in industrial programming, there is an obligatory step to make, that is, to test its credibility practically on given test data sets. Your task is to compare the data obtained as a result of the work of an approximate algorithm to the real data. You are given *n* values *a**t*, integer *T* and real number *c*. Also, you are given *m* moments *p**j* (1<=≀<=*j*<=≀<=*m*), where we are interested in the mean value of the number of queries for the last *T* seconds. Implement two algorithms. The first one should calculate the required value by definition, i.e. by the formula . The second algorithm should calculate the mean value as is described above. Print both values and calculate the relative error of the second algorithm by the formula , where *approx* is the approximate value, obtained by the second algorithm, and *real* is the exact value obtained by the first algorithm.
The first line contains integer *n* (1<=≀<=*n*<=≀<=2Β·105), integer *T* (1<=≀<=*T*<=≀<=*n*) and real number *c* (1<=&lt;<=*c*<=≀<=100) β€” the time range when the resource should work, the length of the time range during which we need the mean number of requests and the coefficient *c* of the work of approximate algorithm. Number *c* is given with exactly six digits after the decimal point. The next line contains *n* integers *a**t* (1<=≀<=*a**t*<=≀<=106) β€” the number of queries to the service at each moment of time. The next line contains integer *m* (1<=≀<=*m*<=≀<=*n*) β€” the number of moments of time when we are interested in the mean number of queries for the last *T* seconds. The next line contains *m* integers *p**j* (*T*<=≀<=*p**j*<=≀<=*n*), representing another moment of time for which we need statistics. Moments *p**j* are strictly increasing.
Print *m* lines. The *j*-th line must contain three numbers *real*, *approx* and *error*, where: - is the real mean number of queries for the last *T* seconds; - *approx* is calculated by the given algorithm and equals *mean* at the moment of time *t*<==<=*p**j* (that is, after implementing the *p**j*-th iteration of the cycle); - is the relative error of the approximate algorithm. The numbers you printed will be compared to the correct numbers with the relative or absolute error 10<=-<=4. It is recommended to print the numbers with at least five digits after the decimal point.
[ "1 1 2.000000\n1\n1\n1\n", "11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11\n", "13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13\n" ]
[ "1.000000 0.500000 0.500000\n", "8.000000 4.449600 0.443800\n9.500000 6.559680 0.309507\n8.250000 6.447744 0.218455\n8.000000 6.358195 0.205226\n8.250000 6.286556 0.237993\n6.000000 6.229245 0.038207\n6.000000 6.183396 0.030566\n6.000000 6.146717 0.024453\n", "3.000000 1.771200 0.409600\n3.000000 2.016960 0.327680\n7.250000 5.613568 0.225715\n7.250000 5.090854 0.297813\n7.250000 4.672684 0.355492\n7.250000 4.338147 0.401635\n3.000000 4.070517 0.356839\n3.000000 3.856414 0.285471\n3.000000 3.685131 0.228377\n3.000000 3.548105 0.182702\n" ]
none
[ { "input": "1 1 2.000000\n1\n1\n1", "output": "1.000000 0.500000 0.500000" }, { "input": "11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11", "output": "8.000000 4.449600 0.443800\n9.500000 6.559680 0.309507\n8.250000 6.447744 0.218455\n8.000000 6.358195 0.205226\n8.250000 6.286556 0.237993\n6.000000 6.229245 0.038207\n6.000000 6.183396 0.030566\n6.000000 6.146717 0.024453" }, { "input": "13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13", "output": "3.000000 1.771200 0.409600\n3.000000 2.016960 0.327680\n7.250000 5.613568 0.225715\n7.250000 5.090854 0.297813\n7.250000 4.672684 0.355492\n7.250000 4.338147 0.401635\n3.000000 4.070517 0.356839\n3.000000 3.856414 0.285471\n3.000000 3.685131 0.228377\n3.000000 3.548105 0.182702" }, { "input": "1 1 2.000000\n4\n1\n1", "output": "4.000000 2.000000 0.500000" }, { "input": "1 1 2.000000\n1121\n1\n1", "output": "1121.000000 560.500000 0.500000" }, { "input": "1 1 2.000000\n758432\n1\n1", "output": "758432.000000 379216.000000 0.500000" }, { "input": "3 1 2.000000\n8 25 21\n3\n1 2 3", "output": "8.000000 4.000000 0.500000\n25.000000 14.500000 0.420000\n21.000000 17.750000 0.154762" }, { "input": "19 3 1.333333\n12 15 11 10 16 4 9 2 24 3 6 3 21 21 2 16 13 12 2\n17\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19", "output": "12.666667 7.250003 0.427631\n12.000000 7.937505 0.338541\n12.333333 9.953131 0.192989\n10.000000 8.464850 0.153515\n9.666667 8.598640 0.110486\n5.000000 6.948982 0.389796\n11.666667 11.211739 0.038994\n9.666667 9.158807 0.052537\n11.000000 8.369107 0.239172\n4.000000 7.026832 0.756708\n10.000000 10.520127 0.052013\n15.000000 13.140098 0.123993\n14.666667 10.355076 0.293972\n13.000000 11.766310 0.094899\n10.333333 12.074736 0.168523\n13.666667 12.056055 0.117850\n9.000000 9.542043 0.060227" }, { "input": "64 3 1.333333\n1337 1913 135 885 1567 1049 1116 368 350 725 517 1874 588 918 1923 998 1237 1098 121 1304 1459 942 538 1480 293 178 958 728 1240 1721 1549 825 928 1189 194 626 1872 670 1145 200 333 1772 1136 614 174 1448 249 1783 798 1375 1574 870 360 398 1387 1092 314 294 1056 1890 1170 697 668 1570\n62\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64", "output": "1128.333333 580.453454 0.485566\n977.666667 656.590254 0.328411\n862.333333 884.192912 0.025349\n1167.000000 925.394915 0.207031\n1244.000000 973.046430 0.217808\n844.333333 821.785028 0.026705\n611.333333 703.838947 0.151318\n481.000000 709.129387 0.474281\n530.666667 661.097206 0.245786\n1038.666667 964.323145 0.071576\n993.000000 870.242577 0.123623\n1126.666667 882.182153 0.216998\n1143.000000 1142.386900 0.000536\n1279.666667 1106.290452 0.135485\n1386.000000 1138.968124 0.178234\n1111.000000 1128.726375 0.015955\n81..." } ]
4,000
17,817,600
0
7,134
442
Andrey and Problem
[ "greedy", "math", "probabilities" ]
null
null
Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends β€” the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of Andrey's friends. The second line contains *n* real numbers *p**i* (0.0<=≀<=*p**i*<=≀<=1.0) β€” the probability that the *i*-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
Print a single real number β€” the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10<=-<=9.
[ "4\n0.1 0.2 0.3 0.8\n", "2\n0.1 0.2\n" ]
[ "0.800000000000\n", "0.260000000000\n" ]
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one. In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1Β·0.8 + 0.9Β·0.2 = 0.26.
[ { "input": "4\n0.1 0.2 0.3 0.8", "output": "0.800000000000" }, { "input": "2\n0.1 0.2", "output": "0.260000000000" }, { "input": "1\n0.217266", "output": "0.217266000000" }, { "input": "2\n0.608183 0.375030", "output": "0.608183000000" }, { "input": "3\n0.388818 0.399762 0.393874", "output": "0.478724284024" }, { "input": "4\n0.801024 0.610878 0.808545 0.732504", "output": "0.808545000000" }, { "input": "5\n0.239482 0.686259 0.543226 0.764939 0.401318", "output": "0.764939000000" }, { "input": "6\n0.462434 0.775020 0.479749 0.373861 0.492031 0.746333", "output": "0.775020000000" }, { "input": "7\n0.745337 0.892271 0.792853 0.892917 0.768246 0.901623 0.815793", "output": "0.901623000000" }, { "input": "1\n0.057695", "output": "0.057695000000" }, { "input": "2\n0.057750 0.013591", "output": "0.069771239500" }, { "input": "3\n0.087234 0.075148 0.033833", "output": "0.172781711023" }, { "input": "4\n0.016717 0.061051 0.036222 0.096258", "output": "0.181832937456" }, { "input": "5\n0.057095 0.046954 0.054676 0.025927 0.080810", "output": "0.214634688963" }, { "input": "6\n0.010924 0.032857 0.021824 0.020356 0.007107 0.082489", "output": "0.154629381329" }, { "input": "7\n0.016061 0.043107 0.088973 0.014785 0.044298 0.028315 0.086014", "output": "0.246482855791" }, { "input": "100\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01", "output": "0.369729637650" }, { "input": "1\n1.0", "output": "1.000000000000" }, { "input": "3\n0.1 0.1 0.1", "output": "0.243000000000" }, { "input": "3\n0.2 0.2 0.2", "output": "0.384000000000" }, { "input": "5\n0.01 0.01 0.01 0.01 0.01", "output": "0.048029800500" }, { "input": "3\n1.0 1.0 0", "output": "1.000000000000" }, { "input": "3\n0.1 0.2 0.3", "output": "0.398000000000" }, { "input": "7\n0.1 0.1 0.1 0.1 0.1 0.1 0.1", "output": "0.372008700000" }, { "input": "5\n0.5 0.5 0.5 1 0.5", "output": "1.000000000000" }, { "input": "3\n0.4 0.2 0.4", "output": "0.480000000000" }, { "input": "10\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1", "output": "0.387420489000" }, { "input": "2\n1.0 1.0", "output": "1.000000000000" }, { "input": "10\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01", "output": "0.091351724748" }, { "input": "5\n1.0 1.0 1.0 0.1 0", "output": "1.000000000000" }, { "input": "5\n0.0001 0.0001 0.0001 0.0001 0.0001", "output": "0.000499800030" }, { "input": "20\n0.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", "output": "0.387420489000" }, { "input": "2\n0.0 1.0", "output": "1.000000000000" }, { "input": "5\n0.00001 0.00001 0.00001 0.00001 0.00001", "output": "0.000049998000" }, { "input": "3\n0.2 0.8 1", "output": "1.000000000000" }, { "input": "4\n0.1 0.1 0.1 0.1", "output": "0.291600000000" }, { "input": "5\n0.31 0.21 0.05 0.37 0.18", "output": "0.450600000000" }, { "input": "5\n1 1 1 1 1", "output": "1.000000000000" }, { "input": "4\n1 1 1 1", "output": "1.000000000000" }, { "input": "7\n0.14 0.28 0.13 0.31 0.15 0.17 0.27", "output": "0.438108000000" }, { "input": "20\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001", "output": "0.019623400697" }, { "input": "100\n0.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.1 0.1 0.1 0.1", "output": "0.387420489000" } ]
108
20,172,800
0
7,149
689
Mike and Shortcuts
[ "dfs and similar", "graphs", "greedy", "shortest paths" ]
null
null
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≀<=*a**i*<=≀<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≀<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=β‰ <=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≀<=*i*<=≀<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≀<=*a**i*<=≀<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*).
In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*.
[ "3\n2 2 3\n", "5\n1 2 3 4 5\n", "7\n4 4 4 4 7 7 7\n" ]
[ "0 1 2 \n", "0 1 2 3 4 \n", "0 1 2 1 2 3 3 \n" ]
In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample caseΒ β€” consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
[ { "input": "3\n2 2 3", "output": "0 1 2 " }, { "input": "5\n1 2 3 4 5", "output": "0 1 2 3 4 " }, { "input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3 " }, { "input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 90 90 90 90 90 90 90 90 90 90 90 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 95 95 95 95 95 97 98 98", "output": "0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 4 4 5 6 5 6 7 8 " }, { "input": "91\n4 6 23 23 23 23 23 28 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 47 47 47 54 54 54 54 54 54 54 58 58 58 58 58 58 69 69 69 69 69 69 69 69 69 69 69 69 70 70 70 70 70 70 70 70 70 70 71 72 72 72 73 75 77 77 77 82 82 84 84 84 84 84 85 86 87 89 89 90 91", "output": "0 1 2 1 2 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 3 4 5 6 5 6 7 8 9 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 10 9 8 7 6 5 4 5 6 7 6 7 8 9 10 11 10 9 8 7 6 5 6 6 7 8 9 10 11 11 12 13 14 14 13 14 14 15 16 17 18 19 20 21 " }, { "input": "82\n1 5 11 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 39 39 39 39 39 45 45 45 45 45 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 71 71 71 71 71 71 71 73 73 75 75 76 77 79 81 81 81 82", "output": "0 1 2 3 2 3 4 5 5 4 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 9 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 6 6 7 8 9 10 11 12 13 14 15 15 16 " }, { "input": "4\n2 3 3 4", "output": "0 1 2 3 " } ]
46
0
0
7,154
628
Bear and Fair Set
[ "flows", "graphs" ]
null
null
Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate your mathematical skills. To test you, Limak is going to give you a puzzle to solve. It's a well-known fact that Limak, as every bear, owns a set of numbers. You know some information about the set: - The elements of the set are distinct positive integers. - The number of elements in the set is *n*. The number *n* is divisible by 5. - All elements are between 1 and *b*, inclusive: bears don't know numbers greater than *b*. - For each *r* in {0,<=1,<=2,<=3,<=4}, the set contains exactly elements that give remainder *r* when divided by 5. (That is, there are elements divisible by 5, elements of the form 5*k*<=+<=1, elements of the form 5*k*<=+<=2, and so on.) Limak smiles mysteriously and gives you *q* hints about his set. The *i*-th hint is the following sentence: "If you only look at elements that are between 1 and *upTo**i*, inclusive, you will find exactly *quantity**i* such elements in my set." In a moment Limak will tell you the actual puzzle, but something doesn't seem right... That smile was very strange. You start to think about a possible reason. Maybe Limak cheated you? Or is he a fair grizzly bear? Given *n*, *b*, *q* and hints, check whether Limak can be fair, i.e. there exists at least one set satisfying the given conditions. If it's possible then print ''fair". Otherwise, print ''unfair".
The first line contains three integers *n*, *b* and *q* (5<=≀<=*n*<=≀<=*b*<=≀<=104, 1<=≀<=*q*<=≀<=104, *n* divisible by 5) β€” the size of the set, the upper limit for numbers in the set and the number of hints. The next *q* lines describe the hints. The *i*-th of them contains two integers *upTo**i* and *quantity**i* (1<=≀<=*upTo**i*<=≀<=*b*, 0<=≀<=*quantity**i*<=≀<=*n*).
Print ''fair" if there exists at least one set that has all the required properties and matches all the given hints. Otherwise, print ''unfair".
[ "10 20 1\n10 10\n", "10 20 3\n15 10\n5 0\n10 5\n", "10 20 2\n15 3\n20 10\n" ]
[ "fair\n", "fair\n", "unfair\n" ]
In the first example there is only one set satisfying all conditions: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. In the second example also there is only one set satisfying all conditions: {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}. Easy to see that there is no set satisfying all conditions from the third example. So Limak lied to you :-(
[ { "input": "10 20 1\n10 10", "output": "fair" }, { "input": "10 20 3\n15 10\n5 0\n10 5", "output": "fair" }, { "input": "10 20 2\n15 3\n20 10", "output": "unfair" }, { "input": "15 27 2\n6 4\n23 5", "output": "unfair" }, { "input": "50 7654 4\n1273 11\n6327 38\n1244 3\n5208 22", "output": "fair" }, { "input": "50 7654 4\n2899 15\n3848 26\n2718 12\n5511 36", "output": "fair" }, { "input": "50 7654 4\n4881 20\n4957 6\n4764 50\n944 44", "output": "unfair" }, { "input": "50 6457 1\n945 41", "output": "fair" }, { "input": "500 5000 5\n1289 221\n694 178\n2179 454\n160 11\n1398 232", "output": "fair" }, { "input": "500 5000 10\n2905 421\n573 82\n1602 205\n4523 491\n970 100\n3810 453\n2553 418\n2033 364\n1664 245\n1924 311", "output": "fair" }, { "input": "500 5000 20\n875 49\n73 16\n2405 136\n811 33\n2477 140\n3475 303\n4640 496\n4025 369\n4482 440\n3475 272\n3594 346\n3945 368\n3807 346\n2605 159\n4045 382\n2861 270\n4488 448\n1894 61\n2388 113\n4071 383", "output": "unfair" }, { "input": "500 5000 50\n687 73\n3816 389\n4333 436\n1660 177\n2238 231\n2936 312\n899 96\n541 55\n4218 425\n4512 457\n1302 132\n2322 239\n688 73\n4423 449\n2765 284\n3755 382\n4192 422\n2718 277\n2254 231\n1354 140\n4891 490\n2722 277\n344 35\n4774 479\n988 101\n2530 256\n3679 375\n3258 341\n1870 201\n1391 146\n643 68\n1040 105\n2607 266\n906 97\n4790 480\n2390 245\n3101 326\n2616 267\n1064 107\n1091 110\n1735 187\n2434 247\n3887 397\n1335 137\n2073 219\n450 45\n480 47\n3519 359\n157 16\n4316 434", "output": "fair" }, { "input": "15 40 3\n2 0\n13 9\n4 1", "output": "fair" }, { "input": "15 41 3\n16 8\n14 2\n40 9", "output": "unfair" }, { "input": "15 40 3\n8 0\n38 14\n28 9", "output": "fair" }, { "input": "15 40 3\n1 9\n24 0\n35 7", "output": "unfair" }, { "input": "15 40 2\n23 4\n36 7", "output": "unfair" }, { "input": "15 41 2\n19 12\n2 0", "output": "fair" }, { "input": "15 40 2\n35 13\n36 14", "output": "fair" }, { "input": "15 40 2\n15 4\n24 4", "output": "fair" }, { "input": "5 6 2\n4 4\n5 4", "output": "unfair" }, { "input": "10 20 4\n3 3\n5 3\n9 7\n17 7", "output": "unfair" }, { "input": "5 10 3\n2 1\n5 4\n7 4", "output": "unfair" }, { "input": "5 30 10\n1 1\n5 1\n6 2\n10 2\n11 3\n15 3\n16 4\n20 4\n21 5\n30 5", "output": "unfair" }, { "input": "10 13 2\n3 3\n5 4", "output": "unfair" }, { "input": "5 10 3\n1 1\n5 1\n9 5", "output": "unfair" }, { "input": "10 14 2\n4 4\n5 4", "output": "unfair" } ]
46
0
0
7,168
441
Valera and Fruits
[ "greedy", "implementation" ]
null
null
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
The first line contains two space-separated integers *n* and *v* (1<=≀<=*n*,<=*v*<=≀<=3000) β€” the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=3000) β€” the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Print a single integer β€” the maximum number of fruit that Valera can collect.
[ "2 3\n1 5\n2 3\n", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n" ]
[ "8\n", "60\n" ]
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
[ { "input": "2 3\n1 5\n2 3", "output": "8" }, { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60" }, { "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "output": "10596" }, { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "output": "4740" }, { "input": "2 1500\n2 575\n1 2522", "output": "3097" }, { "input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772", "output": "18465" }, { "input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757", "output": "25893" }, { "input": "1 10\n3000 30", "output": "20" }, { "input": "2 1\n30 3\n31 2", "output": "3" }, { "input": "4 2061\n1 426\n3 2522\n1 772\n1 1447", "output": "5167" }, { "input": "2 1\n1 1\n1 1", "output": "2" }, { "input": "1 10\n3000 20", "output": "20" }, { "input": "1 1000\n3000 2000", "output": "2000" }, { "input": "2 100\n3000 100\n3000 100", "output": "200" }, { "input": "2 3\n1 6\n3 6", "output": "12" }, { "input": "1 40\n3000 42", "output": "42" }, { "input": "1 100\n3000 200", "output": "200" }, { "input": "1 50\n3000 100", "output": "100" }, { "input": "1 1\n3000 2", "output": "2" }, { "input": "2 3000\n3000 3000\n3000 3000", "output": "6000" }, { "input": "2 2\n2999 3\n3000 2", "output": "5" }, { "input": "1 2\n3000 3", "output": "3" }, { "input": "2 5\n2999 10\n3000 5", "output": "15" }, { "input": "1 3\n5 3", "output": "3" }, { "input": "2 1000\n2999 2000\n3000 1000", "output": "3000" }, { "input": "1 5\n3000 10", "output": "10" }, { "input": "1 10\n3000 15", "output": "15" }, { "input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100", "output": "10" }, { "input": "1 1\n3000 3000", "output": "2" }, { "input": "2 10\n2999 100\n3000 100", "output": "30" }, { "input": "1 10\n3000 100", "output": "20" } ]
77
204,800
0
7,176
245
Mishap in Club
[ "greedy", "implementation" ]
null
null
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
[ "+-+-+\n", "---" ]
[ "1\n", "3" ]
none
[ { "input": "+-+-+", "output": "1" }, { "input": "---", "output": "3" }, { "input": "-", "output": "1" }, { "input": "--", "output": "2" }, { "input": "---", "output": "3" }, { "input": "----", "output": "4" }, { "input": "---+", "output": "3" }, { "input": "--+-", "output": "2" }, { "input": "--++", "output": "2" }, { "input": "-+--", "output": "2" }, { "input": "-++", "output": "2" }, { "input": "-++-", "output": "2" }, { "input": "+", "output": "1" }, { "input": "+-", "output": "1" }, { "input": "+--", "output": "2" }, { "input": "+--+", "output": "2" }, { "input": "++--", "output": "2" }, { "input": "-+++--+-++--+-+--+-+", "output": "3" }, { "input": "++-++--+++++-+++++---+++-++-++-", "output": "12" }, { "input": "----+-+--++---++---++-+-----+--", "output": "11" }, { "input": "-+++---+++++++++++++-++-++++++-++-+-+++-", "output": "22" }, { "input": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "300" }, { "input": "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", "output": "300" }, { "input": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "298" }, { "input": "++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "296" }, { "input": "+++++++++++++++++++++++++++++++++++++++++-++++++++-++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++-++++++++++++++++++++++++-++++-+++++++++++++-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++-+++++++++++++++++", "output": "280" }, { "input": "++++-+---+++--++++-++-++++++++-++-++++-++++++-+-+-+++--+-++++++-+++-++-+++-++++-++++-+-+----+++++---++++-+---+++--+++++-+++-+-++++++----+--+++++++++-+--+++-+-+-++++++--+-+-+-+-++--+-+-----++++++-+++-++--+++++++++---+-++++++-++-++++-+--+-++-++++-+-+--++-+--+++-+-++++++++++++-+++-+----++++++++--+-+-++", "output": "100" }, { "input": "+----++-----+----+++--++---+++--+-++++-++---++++++--++++--++-++--++--++----++++---+--+++----++--++--++--+--++++++++--++--+++----+++----++----++-+--+---+--+-++--+--+--+-+--+---++-+-++--+++++-++------+++-++--+--+--+++++++--++-+--+-+--++++-++--+---+-+-++-+-++----+-++++++-+++--+----++-+--++-----+++-++-+", "output": "15" }, { "input": "-+++----+-++--+-+----+--+++++----+---+-++-+---+++--+---++-+-----+----+------+--+----++-++-----+++--+---+-+-----++++------+--+-----++---+---+---+-++------++++--+-+-------------+---+--+-+--------++---+-++---+-----+++--+---+-++-+---+-+---+++--++-----++------+----+---+---+--+-+-++-+---++--------+----++", "output": "103" }, { "input": "----------+-----------------------------------------------------------+-+-------------+--------------------------------------------------------------------------------+--+-----+-+-------------------------------------------+-----------------------------------------------------------------+-----------", "output": "280" } ]
248
0
0
7,182
288
Polo the Penguin and Houses
[ "combinatorics" ]
null
null
Little penguin Polo loves his home village. The village has *n* houses, indexed by integers from 1 to *n*. Each house has a plaque containing an integer, the *i*-th house has a plaque containing integer *p**i* (1<=≀<=*p**i*<=≀<=*n*). Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number *x*. Then he goes to the house whose number is written on the plaque of house *x* (that is, to house *p**x*), then he goes to the house whose number is written on the plaque of house *p**x* (that is, to house *p**p**x*), and so on. We know that: 1. When the penguin starts walking from any house indexed from 1 to *k*, inclusive, he can walk to house number 1. 1. When the penguin starts walking from any house indexed from *k*<=+<=1 to *n*, inclusive, he definitely cannot walk to house number 1. 1. When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house. You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109<=+<=7).
The single line contains two space-separated integers *n* and *k* (1<=≀<=*n*<=≀<=1000,<=1<=≀<=*k*<=≀<=*min*(8,<=*n*)) β€” the number of the houses and the number *k* from the statement.
In a single line print a single integer β€” the answer to the problem modulo 1000000007 (109<=+<=7).
[ "5 2\n", "7 4\n" ]
[ "54\n", "1728\n" ]
none
[ { "input": "5 2", "output": "54" }, { "input": "7 4", "output": "1728" }, { "input": "8 5", "output": "16875" }, { "input": "8 1", "output": "823543" }, { "input": "10 7", "output": "3176523" }, { "input": "12 8", "output": "536870912" }, { "input": "50 2", "output": "628702797" }, { "input": "100 8", "output": "331030906" }, { "input": "1000 8", "output": "339760446" }, { "input": "999 7", "output": "490075342" }, { "input": "685 7", "output": "840866481" }, { "input": "975 8", "output": "531455228" }, { "input": "475 5", "output": "449471303" }, { "input": "227 6", "output": "407444135" }, { "input": "876 8", "output": "703293724" }, { "input": "1000 1", "output": "760074701" }, { "input": "1000 2", "output": "675678679" }, { "input": "1000 3", "output": "330155123" }, { "input": "1000 4", "output": "660270610" }, { "input": "1000 5", "output": "583047503" }, { "input": "1000 6", "output": "834332109" }, { "input": "657 3", "output": "771999480" }, { "input": "137 5", "output": "160909830" }, { "input": "8 8", "output": "2097152" }, { "input": "9 8", "output": "2097152" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "3 3", "output": "9" }, { "input": "473 4", "output": "145141007" } ]
217
22,323,200
-1
7,203
429
Tricky Function
[ "data structures", "divide and conquer", "geometry" ]
null
null
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task. You're given an (1-based) array *a* with *n* elements. Let's define function *f*(*i*,<=*j*) (1<=≀<=*i*,<=*j*<=≀<=*n*) as (*i*<=-<=*j*)2<=+<=*g*(*i*,<=*j*)2. Function g is calculated by the following pseudo-code: Find a value *min**i*<=β‰ <=*j*Β Β *f*(*i*,<=*j*). Probably by now Iahub already figured out the solution to this problem. Can you?
The first line of input contains a single integer *n* (2<=≀<=*n*<=≀<=100000). Next line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (<=-<=104<=≀<=*a*[*i*]<=≀<=104).
Output a single integer β€” the value of *min**i*<=β‰ <=*j*Β Β *f*(*i*,<=*j*).
[ "4\n1 0 0 -1\n", "2\n1 -1\n" ]
[ "1\n", "2\n" ]
none
[ { "input": "4\n1 0 0 -1", "output": "1" }, { "input": "2\n1 -1", "output": "2" }, { "input": "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -55 92 3 -22 43 -30 48 -27 88 -58 41 36 8 -40 -30 -18 16 22 -66 -91 -46 48 -60 -45 -89 37 -76 52 81 81 15 1 -43 -45 -19 9 -75 -75 -63 41 29", "output": "2" }, { "input": "100\n-1 -3 -3 0 -1 -1 -1 1 2 1 0 -1 -2 0 -2 -2 3 -2 -1 -2 2 -2 -2 3 0 2 3 -1 2 -1 -2 2 -3 2 1 0 -1 1 3 -1 0 2 -3 -2 2 2 3 -2 2 3 0 -3 -2 1 -1 0 3 0 2 0 1 1 0 -3 1 -3 3 0 -1 -3 3 3 1 -2 2 -2 -3 -1 -2 2 -1 0 2 1 2 -1 2 3 -2 -1 0 -3 0 -1 3 2 -2 2 3 0", "output": "1" }, { "input": "4\n200 100 -200 100", "output": "9" }, { "input": "2\n3 -9", "output": "82" }, { "input": "3\n0 -10 10", "output": "4" }, { "input": "2\n10000 10000", "output": "100000001" }, { "input": "2\n5 5", "output": "26" }, { "input": "3\n10 10 -10", "output": "4" }, { "input": "6\n10000 10000 10000 10000 10000 6904", "output": "47665217" }, { "input": "3\n0 10000 -10000", "output": "4" }, { "input": "3\n0 2 3", "output": "5" }, { "input": "2\n0 1", "output": "2" }, { "input": "5\n5865 6072 -4563 5913 -7926", "output": "254032" }, { "input": "2\n1 10000", "output": "100000001" }, { "input": "5\n10 11 12 13 -40", "output": "32" }, { "input": "21\n10 10 10 10 10 10 10 10 10 10 -95 10 10 10 10 10 10 10 10 10 10", "output": "101" }, { "input": "5\n0 4 10 -5 -5", "output": "9" }, { "input": "2\n0 10000", "output": "100000001" }, { "input": "4\n0 100 100 -200", "output": "9" }, { "input": "4\n0 10 -5 -5", "output": "9" }, { "input": "4\n10 10 -10 -10", "output": "4" }, { "input": "3\n1 10 10", "output": "101" }, { "input": "3\n1000 1000 -800", "output": "40004" }, { "input": "3\n0 10 -10", "output": "4" }, { "input": "2\n0 100", "output": "10001" } ]
2,000
17,817,600
0
7,205
46
Parking Lot
[ "data structures", "implementation" ]
D. Parking Lot
2
256
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as *L* meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of the tasks come from the driving is right side!). Every driver when parking wants to leave for themselves some extra space to move their car freely, that's why a driver is looking for a place where the distance between his car and the one behind his will be no less than *b* meters and the distance between his car and the one in front of his will be no less than *f* meters (if there's no car behind then the car can be parked at the parking lot segment edge; the same is true for the case when there're no cars parked in front of the car). Let's introduce an axis of coordinates along the pavement. Let the parking lot begin at point 0 and end at point *L*. The drivers drive in the direction of the coordinates' increasing and look for the earliest place (with the smallest possible coordinate) where they can park the car. In case there's no such place, the driver drives on searching for his perfect peaceful haven. Sometimes some cars leave the street and free some space for parking. Considering that there never are two moving cars on a street at a time write a program that can use the data on the drivers, entering the street hoping to park there and the drivers leaving it, to model the process and determine a parking lot space for each car.
The first line contains three integers *L*, *b* ΠΈ *f* (10<=≀<=*L*<=≀<=100000,<=1<=≀<=*b*,<=*f*<=≀<=100). The second line contains an integer *n* (1<=≀<=*n*<=≀<=100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number represents the request type. If the request type is equal to 1, then in that case the second number indicates the length of a car (in meters) that enters the street looking for a place to park. And if the request type is equal to 2, then the second number identifies the number of such a request (starting with 1) that the car whose arrival to the parking lot was described by a request with this number, leaves the parking lot. It is guaranteed that that car was parked at the moment the request of the 2 type was made. The lengths of cars are integers from 1 to 1000.
For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.
[ "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n", "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n", "10 1 1\n1\n1 12\n" ]
[ "0\n6\n11\n17\n23\n", "0\n6\n11\n17\n6\n", "-1\n" ]
none
[ { "input": "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n23" }, { "input": "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "output": "0\n6\n11\n17\n6" }, { "input": "10 1 1\n1\n1 12", "output": "-1" }, { "input": "10 1 1\n1\n1 9", "output": "0" }, { "input": "10 1 1\n1\n1 10", "output": "0" }, { "input": "10 1 1\n2\n1 3\n1 6", "output": "0\n4" }, { "input": "10 1 1\n2\n1 3\n1 7", "output": "0\n-1" }, { "input": "10 1 1\n5\n1 1\n1 2\n1 3\n2 2\n1 4", "output": "0\n2\n5\n-1" }, { "input": "10 1 1\n5\n1 4\n2 1\n1 3\n2 3\n1 1", "output": "0\n0\n0" }, { "input": "10 1 1\n5\n1 2\n1 3\n1 1\n1 4\n1 2", "output": "0\n3\n7\n-1\n-1" }, { "input": "20 1 2\n10\n1 3\n1 2\n2 2\n2 1\n1 4\n1 2\n1 2\n2 7\n1 2\n1 1", "output": "0\n4\n0\n5\n8\n8\n11" }, { "input": "20 2 1\n10\n1 5\n1 2\n1 1\n1 1\n1 2\n2 4\n1 3\n1 1\n2 5\n1 5", "output": "0\n7\n11\n14\n17\n-1\n14\n-1" }, { "input": "20 2 2\n10\n1 2\n1 3\n1 3\n1 5\n1 5\n1 1\n1 2\n1 5\n1 5\n1 5", "output": "0\n4\n9\n14\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "30 2 1\n10\n1 4\n2 1\n1 1\n1 3\n1 1\n1 1\n1 2\n1 5\n2 4\n2 7", "output": "0\n0\n3\n8\n11\n14\n18" }, { "input": "30 1 2\n10\n1 1\n1 1\n2 1\n1 5\n1 2\n2 4\n1 6\n2 5\n2 2\n2 7", "output": "0\n2\n4\n10\n13" }, { "input": "50 2 3\n15\n1 7\n1 6\n1 1\n2 3\n2 1\n2 2\n1 1\n1 4\n1 6\n1 2\n1 8\n1 6\n2 7\n1 8\n2 9", "output": "0\n9\n17\n0\n3\n9\n17\n21\n31\n39" }, { "input": "50 2 4\n15\n1 4\n1 4\n2 1\n2 2\n1 8\n1 7\n2 5\n1 2\n1 7\n2 8\n1 7\n2 11\n1 3\n2 6\n2 9", "output": "0\n6\n0\n10\n0\n19\n28\n0" }, { "input": "50 3 3\n20\n1 4\n2 1\n1 1\n2 3\n1 1\n2 5\n1 7\n2 7\n1 4\n1 1\n1 10\n1 5\n1 2\n2 9\n2 11\n1 1\n1 9\n2 13\n1 8\n1 1", "output": "0\n0\n0\n0\n0\n7\n11\n24\n32\n0\n11\n32\n43" }, { "input": "50 3 2\n20\n1 6\n1 1\n2 2\n1 2\n1 3\n1 1\n1 2\n2 4\n1 7\n1 1\n2 6\n1 9\n2 12\n2 9\n1 8\n1 6\n1 1\n1 8\n2 15\n1 2", "output": "0\n9\n9\n14\n20\n24\n29\n9\n39\n29\n40\n20\n-1\n29" }, { "input": "50 3 1\n30\n1 9\n2 1\n1 6\n1 5\n1 8\n1 1\n2 6\n1 7\n2 3\n2 8\n1 7\n2 4\n2 5\n2 11\n1 2\n2 15\n1 6\n1 3\n2 17\n1 9\n1 3\n2 18\n1 3\n2 23\n2 21\n1 8\n1 2\n2 27\n1 8\n2 29", "output": "0\n0\n9\n17\n28\n28\n0\n0\n0\n9\n15\n0\n6\n0\n11\n27" } ]
248
2,252,800
-1
7,207
633
A Trivial Problem
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
The only line of input contains an integer *m* (1<=≀<=*m*<=≀<=100<=000)Β β€” the required number of trailing zeroes in factorial.
First print *k*Β β€” the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
[ "1\n", "5\n" ]
[ "5\n5 6 7 8 9 ", "0" ]
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1Β·2Β·3Β·...Β·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
[ { "input": "1", "output": "5\n5 6 7 8 9 " }, { "input": "5", "output": "0" }, { "input": "2", "output": "5\n10 11 12 13 14 " }, { "input": "3", "output": "5\n15 16 17 18 19 " }, { "input": "7", "output": "5\n30 31 32 33 34 " }, { "input": "12", "output": "5\n50 51 52 53 54 " }, { "input": "15", "output": "5\n65 66 67 68 69 " }, { "input": "18", "output": "5\n75 76 77 78 79 " }, { "input": "38", "output": "5\n155 156 157 158 159 " }, { "input": "47", "output": "5\n195 196 197 198 199 " }, { "input": "58", "output": "5\n240 241 242 243 244 " }, { "input": "66", "output": "5\n270 271 272 273 274 " }, { "input": "70", "output": "5\n285 286 287 288 289 " }, { "input": "89", "output": "5\n365 366 367 368 369 " }, { "input": "417", "output": "5\n1675 1676 1677 1678 1679 " }, { "input": "815", "output": "5\n3265 3266 3267 3268 3269 " }, { "input": "394", "output": "5\n1585 1586 1587 1588 1589 " }, { "input": "798", "output": "0" }, { "input": "507", "output": "5\n2035 2036 2037 2038 2039 " }, { "input": "406", "output": "5\n1630 1631 1632 1633 1634 " }, { "input": "570", "output": "5\n2290 2291 2292 2293 2294 " }, { "input": "185", "output": "0" }, { "input": "765", "output": "0" }, { "input": "967", "output": "0" }, { "input": "112", "output": "5\n455 456 457 458 459 " }, { "input": "729", "output": "5\n2925 2926 2927 2928 2929 " }, { "input": "4604", "output": "5\n18425 18426 18427 18428 18429 " }, { "input": "8783", "output": "5\n35140 35141 35142 35143 35144 " }, { "input": "1059", "output": "0" }, { "input": "6641", "output": "5\n26575 26576 26577 26578 26579 " }, { "input": "9353", "output": "5\n37425 37426 37427 37428 37429 " }, { "input": "1811", "output": "5\n7250 7251 7252 7253 7254 " }, { "input": "2528", "output": "0" }, { "input": "8158", "output": "5\n32640 32641 32642 32643 32644 " }, { "input": "3014", "output": "5\n12070 12071 12072 12073 12074 " }, { "input": "7657", "output": "5\n30640 30641 30642 30643 30644 " }, { "input": "4934", "output": "0" }, { "input": "9282", "output": "5\n37140 37141 37142 37143 37144 " }, { "input": "2610", "output": "5\n10450 10451 10452 10453 10454 " }, { "input": "2083", "output": "5\n8345 8346 8347 8348 8349 " }, { "input": "26151", "output": "5\n104620 104621 104622 104623 104624 " }, { "input": "64656", "output": "5\n258640 258641 258642 258643 258644 " }, { "input": "46668", "output": "5\n186690 186691 186692 186693 186694 " }, { "input": "95554", "output": "5\n382235 382236 382237 382238 382239 " }, { "input": "37320", "output": "0" }, { "input": "52032", "output": "5\n208140 208141 208142 208143 208144 " }, { "input": "11024", "output": "5\n44110 44111 44112 44113 44114 " }, { "input": "63218", "output": "5\n252885 252886 252887 252888 252889 " }, { "input": "40095", "output": "5\n160390 160391 160392 160393 160394 " }, { "input": "42724", "output": "5\n170910 170911 170912 170913 170914 " }, { "input": "24381", "output": "5\n97530 97531 97532 97533 97534 " }, { "input": "73138", "output": "5\n292570 292571 292572 292573 292574 " }, { "input": "93346", "output": "5\n373400 373401 373402 373403 373404 " }, { "input": "18338", "output": "5\n73370 73371 73372 73373 73374 " }, { "input": "42662", "output": "5\n170660 170661 170662 170663 170664 " }, { "input": "81221", "output": "5\n324900 324901 324902 324903 324904 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "99998", "output": "0" }, { "input": "30", "output": "0" }, { "input": "11", "output": "0" }, { "input": "780", "output": "0" }, { "input": "97656", "output": "5\n390625 390626 390627 390628 390629 " }, { "input": "12499", "output": "5\n50000 50001 50002 50003 50004 " }, { "input": "65", "output": "5\n265 266 267 268 269 " }, { "input": "41", "output": "5\n170 171 172 173 174 " }, { "input": "31", "output": "5\n125 126 127 128 129 " }, { "input": "86577", "output": "0" } ]
171
6,553,600
3
7,218
74
Chessboard Billiard
[ "dfs and similar", "dsu", "graphs", "number theory" ]
C. Chessboard Billiard
2
256
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving. More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed. It is considered that one billiard ball *a* beats another billiard ball *b* if *a* can reach a point where *b* is located. You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard *n*<=Γ—<=*m* in size.
The first line contains two integers *n* and *m* (2<=≀<=*n*,<=*m*<=≀<=106).
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other. Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
[ "3 4\n", "3 3\n" ]
[ "2", "3" ]
none
[ { "input": "3 4", "output": "2" }, { "input": "3 3", "output": "3" }, { "input": "2 2", "output": "2" }, { "input": "4 3", "output": "2" }, { "input": "2 3", "output": "2" }, { "input": "4 4", "output": "4" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "4" }, { "input": "5 7", "output": "3" }, { "input": "5 13", "output": "5" }, { "input": "7 10", "output": "4" }, { "input": "7 21", "output": "3" }, { "input": "7 61", "output": "7" }, { "input": "8 50", "output": "8" }, { "input": "8 8", "output": "8" }, { "input": "9 9", "output": "9" }, { "input": "9 256", "output": "2" }, { "input": "10 10", "output": "10" }, { "input": "999 999", "output": "999" }, { "input": "1000000 1000000", "output": "1000000" }, { "input": "2311 7771", "output": "211" }, { "input": "146412 710630", "output": "3572" }, { "input": "943547 987965", "output": "1347" }, { "input": "35329 689665", "output": "1537" }, { "input": "672961 948978", "output": "2" }, { "input": "524288 131072", "output": "2" }, { "input": "293492 654942", "output": "2" }, { "input": "962963 1000000", "output": "37038" }, { "input": "7 1000000", "output": "4" }, { "input": "999999 1000000", "output": "2" }, { "input": "666667 1000000", "output": "333334" }, { "input": "384 187", "output": "2" }, { "input": "238 116", "output": "2" }, { "input": "993 342", "output": "32" }, { "input": "848 271", "output": "2" }, { "input": "702 200", "output": "2" }, { "input": "9516 2202", "output": "2" }, { "input": "1498 9704", "output": "2" }, { "input": "2482 6269", "output": "2" }, { "input": "3466 4770", "output": "2" }, { "input": "4449 1336", "output": "2" }, { "input": "604630 225648", "output": "2" }, { "input": "503832 242363", "output": "2" }, { "input": "403034 430556", "output": "2" }, { "input": "302237 618749", "output": "5" }, { "input": "201439 635463", "output": "3" }, { "input": "576709 834208", "output": "562" }, { "input": "97905 599257", "output": "233" }, { "input": "364915 516421", "output": "343" }, { "input": "222403 592339", "output": "2203" }, { "input": "543425 776321", "output": "77633" }, { "input": "977965 896468", "output": "81498" }, { "input": "829981 586711", "output": "14311" }, { "input": "429181 515017", "output": "85837" }, { "input": "198441 446491", "output": "49611" }, { "input": "117806 188489", "output": "23562" }, { "input": "893011 315181", "output": "52531" }, { "input": "701905 526429", "output": "175477" }, { "input": "863029 287677", "output": "287677" }, { "input": "871866 348747", "output": "174374" }, { "input": "12 5", "output": "2" }, { "input": "21 15", "output": "3" }, { "input": "12 9", "output": "2" }, { "input": "720 972", "output": "2" } ]
218
614,400
-1
7,236
0
none
[ "none" ]
null
null
Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string *s*. Namely, he remembers, that string *t**i* occurs in string *s* at least *k**i* times or more, he also remembers exactly *k**i* positions where the string *t**i* occurs in string *s*: these positions are *x**i*,<=1,<=*x**i*,<=2,<=...,<=*x**i*,<=*k**i*. He remembers *n* such strings *t**i*. You are to reconstruct lexicographically minimal string *s* such that it fits all the information Ivan remembers. Strings *t**i* and string *s* consist of small English letters only.
The first line contains single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of strings Ivan remembers. The next *n* lines contain information about the strings. The *i*-th of these lines contains non-empty string *t**i*, then positive integer *k**i*, which equal to the number of times the string *t**i* occurs in string *s*, and then *k**i* distinct positive integers *x**i*,<=1,<=*x**i*,<=2,<=...,<=*x**i*,<=*k**i* in increasing order β€” positions, in which occurrences of the string *t**i* in the string *s* start. It is guaranteed that the sum of lengths of strings *t**i* doesn't exceed 106, 1<=≀<=*x**i*,<=*j*<=≀<=106, 1<=≀<=*k**i*<=≀<=106, and the sum of all *k**i* doesn't exceed 106. The strings *t**i* can coincide. It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.
Print lexicographically minimal string that fits all the information Ivan remembers.
[ "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n", "1\na 1 3\n", "3\nab 1 1\naba 1 3\nab 2 3 5\n" ]
[ "abacaba\n", "aaa\n", "ababab\n" ]
none
[ { "input": "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4", "output": "abacaba" }, { "input": "1\na 1 3", "output": "aaa" }, { "input": "3\nab 1 1\naba 1 3\nab 2 3 5", "output": "ababab" }, { "input": "6\nba 2 16 18\na 1 12\nb 3 4 13 20\nbb 2 6 8\nababbbbbaab 1 3\nabababbbbb 1 1", "output": "abababbbbbaabaababab" }, { "input": "17\na 4 2 7 8 9\nbbaa 1 5\nba 2 1 6\naa 2 7 8\nb 6 1 3 4 5 6 10\nbbbaa 1 4\nbbba 1 4\nbab 1 1\nbba 1 5\nbbb 2 3 4\nbb 3 3 4 5\nab 1 2\nabbb 1 2\nbbbb 1 3\nabb 1 2\nabbbba 1 2\nbbbbaaa 1 3", "output": "babbbbaaab" }, { "input": "9\nfab 1 32\nb 2 38 54\nbadab 1 38\nba 1 62\na 1 25\nab 1 37\nbacaba 1 26\ncabaeab 1 12\nacab 1 3", "output": "aaacabaaaaacabaeabaaaaaaabacabafabaaabadabaaaaaaaaaaabaaaaaaaba" }, { "input": "18\nabacab 2 329 401\nabadabacabae 1 293\nbacab 1 2\nabacabadabacabaga 1 433\nc 1 76\nbaca 1 26\ndab 1 72\nabagabaca 1 445\nabaea 1 397\ndabac 1 280\nab 2 201 309\nca 1 396\nabacabadab 1 497\nac 1 451\ncaba 1 444\nad 1 167\nbadab 1 358\naba 1 421", "output": "abacabaaaaaaaaaaaaaaaaaaabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadabacaaaaaaaaabadabacabaeaaaaabaaaaaaaaaaaaaaaaaaabacabaaaaaaaaaaaaaaaaaaaaaaabadabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacabaeabacabaaaaaaaaaaaaaaabaaaaaaaaaaabacabadabacabagabacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabacabadab" }, { "input": "10\ndabacabafa 1 24\nbacabadab 1 18\ndabaca 1 8\nbacabaea 1 42\nbacaba 1 34\nabadabaca 1 5\nbadabacaba 1 54\nbacabaeaba 1 10\nabacabaeab 1 9\nadabacaba 1 23", "output": "aaaaabadabacabaeabacabadabacabafabacabaaabacabaeaaaaabadabacaba" }, { "input": "20\nadabacabaeabacabada 1 359\nabadabacabafabaca 1 213\nacabagabacaba 1 315\ncabaeabacabadabacab 1 268\nfabacabadabacabaeab 1 352\ncabafabacabada 1 28\nacabadabacabaea 1 67\ncabadabacabaeabacaba 1 484\nabacabadabacaba 1 209\nacabaiabacaba 1 251\nacabafabacabadabac 1 475\nabacabaeabacabadaba 1 105\ncabadabacabaeaba 1 68\nafabacabadabacab 1 287\nacabafab 1 91\ndabacabaea 1 328\nabaeabacabadab 1 461\nabadabacabaeabaca 1 421\nabadabacabafabac 1 277\nfabacabadabac 1 96", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaacabafabacabadaaaaaaaaaaaaaaaaaaaaaaaaaaacabadabacabaeabaaaaaaaaacabafabacabadabacabaeabacabadabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabacabadabacabafabacaaaaaaaaaaaaaaaaaaaaaaacabaiabacabaaaaacabaeabacabadabacabafabacabadabacabaaaaaaaaaaaaacabagabacabadabacabaeaaaaaaaaaaaaaaafabacabadabacabaeabacabadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabadabacabaeabacaaaaaaaaaaaaaaaaaaaaaaaaabaeabacabadabacabafabacabadabacabaeabacaba" }, { "input": "4\na 2 1 10\na 3 1 2 9\na 2 3 8\na 2 4 7", "output": "aaaaaaaaaa" }, { "input": "10\nvvvvvvv 2 63649 456347\nvvvv 3 779 201571 458642\nvvvv 4 283450 377377 534312 583774\nvvvvv 10 78946 79066 346469 509974 665096 705906 711499 764350 815149 841106\nvvvvvvvvv 4 337796 374187 593756 618501\nvvvvvvvvv 3 89760 647846 984050\nvv 10 24048 93536 143218 211825 350809 406501 428953 572318 584177 839086\nvvvvvv 2 558325 764134\nvvvvvvv 9 174822 379712 412113 521028 542452 565481 678944 681435 747267\nvvvvv 9 43091 80962 212547 261108 528620 824068 873847 892141 974878", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }, { "input": "2\naba 1 1\nb 1 2", "output": "aba" } ]
2,000
143,974,400
0
7,239
125
Simple XML
[ "implementation" ]
null
null
Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's define the notion of a XML-text: - an empty string is a XML-text - if *s* is a XML-text, then *s*'=&lt;a&gt;+*s*+&lt;/a&gt; also is a XML-text, where *a* is any small Latin letter - if *s*1, *s*2 are XML-texts, then *s*1+*s*2 also is a XML-text You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form: - each tag (opening and closing) is located on a single line - print before the tag 2<=*<=*h* spaces, where *h* is the level of the tag's nestedness.
The input data consists on the only non-empty string β€” the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces.
Print the given XML-text according to the above-given rules.
[ "&lt;a&gt;&lt;b&gt;&lt;c&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;\n", "&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;d&gt;&lt;c&gt;&lt;/c&gt;&lt;/d&gt;&lt;/a&gt;\n" ]
[ "&lt;a&gt;\n &lt;b&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/b&gt;\n&lt;/a&gt;\n", "&lt;a&gt;\n &lt;b&gt;\n &lt;/b&gt;\n &lt;d&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/d&gt;\n&lt;/a&gt;\n" ]
none
[ { "input": "<a><b><c></c></b></a>", "output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>" }, { "input": "<a><b></b><d><c></c></d></a>", "output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>" }, { "input": "<z></z>", "output": "<z>\n</z>" }, { "input": "<u><d></d></u><j></j>", "output": "<u>\n <d>\n </d>\n</u>\n<j>\n</j>" }, { "input": "<a></a><n></n><v><r></r></v><z></z>", "output": "<a>\n</a>\n<n>\n</n>\n<v>\n <r>\n </r>\n</v>\n<z>\n</z>" }, { "input": "<c><l></l><b><w><f><t><m></m></t></f><w></w></w></b></c>", "output": "<c>\n <l>\n </l>\n <b>\n <w>\n <f>\n <t>\n <m>\n </m>\n </t>\n </f>\n <w>\n </w>\n </w>\n </b>\n</c>" }, { "input": "<u><d><g><k><m><a><u><j><d></d></j></u></a></m><m></m></k></g></d></u>", "output": "<u>\n <d>\n <g>\n <k>\n <m>\n <a>\n <u>\n <j>\n <d>\n </d>\n </j>\n </u>\n </a>\n </m>\n <m>\n </m>\n </k>\n </g>\n </d>\n</u>" }, { "input": "<x><a><l></l></a><g><v></v><d></d></g><z></z><y></y></x><q><h></h><s></s></q><c></c><w></w><q></q>", "output": "<x>\n <a>\n <l>\n </l>\n </a>\n <g>\n <v>\n </v>\n <d>\n </d>\n </g>\n <z>\n </z>\n <y>\n </y>\n</x>\n<q>\n <h>\n </h>\n <s>\n </s>\n</q>\n<c>\n</c>\n<w>\n</w>\n<q>\n</q>" }, { "input": "<b><k><t></t></k><j></j><t></t><q></q></b><x><h></h></x><r></r><k></k><i></i><t><b></b></t><z></z><x></x><p></p><u></u>", "output": "<b>\n <k>\n <t>\n </t>\n </k>\n <j>\n </j>\n <t>\n </t>\n <q>\n </q>\n</b>\n<x>\n <h>\n </h>\n</x>\n<r>\n</r>\n<k>\n</k>\n<i>\n</i>\n<t>\n <b>\n </b>\n</t>\n<z>\n</z>\n<x>\n</x>\n<p>\n</p>\n<u>\n</u>" }, { "input": "<c><l><i><h><z></z></h><y><k></k><o></o></y></i><a></a><x></x></l><r><y></y><k><s></s></k></r><j><a><f></f></a></j><h></h><p></p></c><h></h>", "output": "<c>\n <l>\n <i>\n <h>\n <z>\n </z>\n </h>\n <y>\n <k>\n </k>\n <o>\n </o>\n </y>\n </i>\n <a>\n </a>\n <x>\n </x>\n </l>\n <r>\n <y>\n </y>\n <k>\n <s>\n </s>\n </k>\n </r>\n <j>\n <a>\n <f>\n </f>\n </a>\n </j>\n <h>\n </h>\n <p>\n </p>\n</c>\n<h>\n</h>" }, { "input": "<p><q><l></l><q><k><r><n></n></r></k></q></q><x><z></z><r><k></k></r><h></h></x><c><p></p><o></o></c><n></n><c></c></p><b><c><z></z></c><u><u><f><a><d></d><q></q></a><x><i></i></x><r></r></f></u></u></b><j></j>", "output": "<p>\n <q>\n <l>\n </l>\n <q>\n <k>\n <r>\n <n>\n </n>\n </r>\n </k>\n </q>\n </q>\n <x>\n <z>\n </z>\n <r>\n <k>\n </k>\n </r>\n <h>\n </h>\n </x>\n <c>\n <p>\n </p>\n <o>\n </o>\n </c>\n <n>\n </n>\n <c>\n </c>\n</p>\n<b>\n <c>\n <z>\n </z>\n </c>\n <u>\n <u>\n <f>\n <a>\n <d>\n </d>\n <q>\n </q>\n </a>\n <x>\n <i>\n ..." }, { "input": "<w><q><x></x></q><r></r><o></o><u></u><o></o></w><d><z></z><n><x></x></n><y></y><s></s><k></k><q></q><a></a></d><h><u></u><s></s><y></y><t></t><f></f></h><v><w><q></q></w><s></s><h></h></v><q><o></o><k></k><w></w></q><c></c><p><j></j></p><c><u></u></c><s></s><x></x><b></b><i></i>", "output": "<w>\n <q>\n <x>\n </x>\n </q>\n <r>\n </r>\n <o>\n </o>\n <u>\n </u>\n <o>\n </o>\n</w>\n<d>\n <z>\n </z>\n <n>\n <x>\n </x>\n </n>\n <y>\n </y>\n <s>\n </s>\n <k>\n </k>\n <q>\n </q>\n <a>\n </a>\n</d>\n<h>\n <u>\n </u>\n <s>\n </s>\n <y>\n </y>\n <t>\n </t>\n <f>\n </f>\n</h>\n<v>\n <w>\n <q>\n </q>\n </w>\n <s>\n </s>\n <h>\n </h>\n</v>\n<q>\n <o>\n </o>\n <k>\n </k>\n <w>\n </w>\n</q>\n<c>\n</c>\n<p>\n <j>\n </j>\n</p>\n<c>\n <u>\n </u..." }, { "input": "<g><t><m><x><f><w><z><b><d><j></j><g><z></z><q><l><j></j><l><k></k><l><n><d></d><m></m></n></l><i><m><j></j></m></i></l></l><w><t><h><r><h></h><b></b></r></h></t><d><j></j></d><x><w><r><s><s></s></s></r></w><x></x></x></w><m><m><d></d><x><r><x><o><v></v><d><n></n></d></o></x></r></x></m></m></q></g><y></y></d></b></z></w></f></x><a></a></m></t></g>", "output": "<g>\n <t>\n <m>\n <x>\n <f>\n <w>\n <z>\n <b>\n <d>\n <j>\n </j>\n <g>\n <z>\n </z>\n <q>\n <l>\n <j>\n </j>\n <l>\n <k>\n </k>\n <l>\n <n>\n ..." }, { "input": "<d><d><w><v><g><m></m></g><b><u></u><j><h><n><q><q><c></c></q></q></n></h><c></c><l><r><l></l><b><d></d><x><k><o><w><q><x></x></q></w></o></k><p></p></x><g><m></m></g></b></r></l></j><k><l></l></k><c><v><g><p><p><d><e><z><x></x></z></e><v></v></d><u><o><u></u><k></k></o></u><m><x><h><z><f></f></z></h></x><w></w></m></p></p></g></v><t><n><u><b><h></h></b></u><r><m><k><z></z></k></m><j><e><w><s></s><e><s><p></p><o></o></s><g></g></e><u></u></w></e></j></r></n></t></c></b></v></w></d></d>", "output": "<d>\n <d>\n <w>\n <v>\n <g>\n <m>\n </m>\n </g>\n <b>\n <u>\n </u>\n <j>\n <h>\n <n>\n <q>\n <q>\n <c>\n </c>\n </q>\n </q>\n </n>\n </h>\n <c>\n </c>\n <l>\n <r>\n <l>\n </l>\n <b>\n ..." } ]
216
307,200
0
7,262
305
Ivan and Powers of Two
[ "greedy", "implementation" ]
null
null
Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=β‰₯<=0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2*v*<=-<=1 for some integer *v* (*v*<=β‰₯<=0). Help Ivan, find the required quantity of numbers.
The first line contains integer *n* (1<=≀<=*n*<=≀<=105). The second input line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=2Β·109). It is guaranteed that *a*1<=≀<=*a*2<=≀<=...<=≀<=*a**n*.
Print a single integer β€” the answer to the problem.
[ "4\n0 1 1 1\n", "1\n3\n" ]
[ "0\n", "3\n" ]
In the first sample you do not need to add anything, the sum of numbers already equals 2<sup class="upper-index">3</sup> - 1 = 7. In the second sample you need to add numbers 2<sup class="upper-index">0</sup>, 2<sup class="upper-index">1</sup>, 2<sup class="upper-index">2</sup>.
[ { "input": "4\n0 1 1 1", "output": "0" }, { "input": "1\n3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "1\n2000000000", "output": "2000000000" }, { "input": "1\n1", "output": "1" }, { "input": "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "output": "5" } ]
500
6,656,000
0
7,277
331
Escaping on Beaveractor
[ "dfs and similar", "implementation" ]
null
null
Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a *b*<=Γ—<=*b* square on a plane. Each point *x*,<=*y* (0<=≀<=*x*,<=*y*<=≀<=*b*) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfortable types of transport. The campus obeys traffic rules: there are *n* arrows, parallel to the coordinate axes. The arrows do not intersect and do not touch each other. When the Beaveractor reaches some arrow, it turns in the arrow's direction and moves on until it either reaches the next arrow or gets outside the campus. The Beaveractor covers exactly one unit of space per one unit of time. You can assume that there are no obstacles to the Beaveractor. The BSA scientists want to transport the brand new Beaveractor to the "Academic Tractor" research institute and send the Smart Beaver to do his postgraduate studies and sharpen pencils. They have *q* plans, representing the Beaveractor's initial position (*x**i*,<=*y**i*), the initial motion vector *w**i* and the time *t**i* that have passed after the escape started. Your task is for each of the *q* plans to determine the Smart Beaver's position after the given time.
The first line contains two integers: the number of traffic rules *n* and the size of the campus *b*, 0<=≀<=*n*, 1<=≀<=*b*. Next *n* lines contain the rules. Each line of the rules contains four space-separated integers *x*0, *y*0, *x*1, *y*1 β€” the beginning and the end of the arrow. It is guaranteed that all arrows are parallel to the coordinate axes and have no common points. All arrows are located inside the campus, that is, 0<=≀<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≀<=*b* holds. Next line contains integer *q* β€” the number of plans the scientists have, 1<=≀<=*q*<=≀<=105. The *i*-th plan is represented by two integers, *x**i*, *y**i* are the Beaveractor's coordinates at the initial time, 0<=≀<=*x**i*,<=*y**i*<=≀<=*b*, character *w**i*, that takes value U, D, L, R and sets the initial direction up, down, to the left or to the right correspondingly (the Y axis is directed upwards), and *t**i* β€” the time passed after the escape started, 0<=≀<=*t**i*<=≀<=1015. - to get 30 points you need to solve the problem with constraints *n*,<=*b*<=≀<=30 (subproblem D1); - to get 60 points you need to solve the problem with constraints *n*,<=*b*<=≀<=1000 (subproblems D1+D2); - to get 100 points you need to solve the problem with constraints *n*,<=*b*<=≀<=105 (subproblems D1+D2+D3).
Print *q* lines. Each line should contain two integers β€” the Beaveractor's coordinates at the final moment of time for each plan. If the Smart Beaver manages to leave the campus in time *t**i*, print the coordinates of the last point in the campus he visited.
[ "3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n" ]
[ "0 0\n0 1\n0 2\n1 2\n2 2\n3 2\n3 2\n2 2\n3 2\n1 3\n2 2\n1 3\n" ]
none
[]
3,462
62,771,200
0
7,278
463
Gargari and Permutations
[ "dfs and similar", "dp", "graphs", "implementation" ]
null
null
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari? You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=1000;Β 2<=≀<=*k*<=≀<=5). Each of the next *k* lines contains integers 1,<=2,<=...,<=*n* in some order β€” description of the current permutation.
Print the length of the longest common subsequence.
[ "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n" ]
[ "3\n" ]
The answer for the first test sample is subsequence [1, 2, 3].
[ { "input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "output": "3" }, { "input": "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1", "output": "3" }, { "input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "output": "4" }, { "input": "1 2\n1\n1", "output": "1" }, { "input": "28 5\n3 14 12 16 13 27 20 8 1 10 24 11 5 9 7 18 17 23 22 25 28 19 4 21 26 6 15 2\n7 12 23 27 22 26 16 18 19 5 6 9 11 28 25 4 10 3 1 14 8 17 15 2 20 13 24 21\n21 20 2 5 19 15 12 4 18 9 23 16 11 14 8 6 25 27 13 17 10 26 7 24 28 1 3 22\n12 2 23 11 20 18 25 21 13 27 14 8 4 6 9 16 7 3 10 1 22 15 26 19 5 17 28 24\n13 2 6 19 22 23 4 1 28 10 18 17 21 8 9 3 26 11 12 27 14 20 24 25 15 5 16 7", "output": "3" }, { "input": "6 3\n2 5 1 4 6 3\n5 1 4 6 2 3\n5 4 2 6 3 1", "output": "4" }, { "input": "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 20 6 28\n31 27 39 16 22 12 13 32 6 10 19 29 37 7 18 33 24 21 1 9 36 4 34 41 25 28 17 40 30 35 23 14 11 8 2 15 38 20 26 5 3\n8 18 39 38 7 34 16 31 15 1 40 20 37 4 25 11 17 19 33 26 6 14 13 41 12 32 2 21 10 35 27 9 28 5 30 24 22 23 29 3 36", "output": "4" }, { "input": "37 3\n6 3 19 20 15 4 1 35 8 24 12 21 34 26 18 14 23 33 28 9 36 11 37 31 25 32 29 22 13 27 16 17 10 7 5 30 2\n10 3 35 17 34 21 14 8 26 28 11 19 27 7 4 23 24 22 12 13 16 1 25 29 5 31 30 20 32 18 15 9 2 36 37 33 6\n19 9 22 32 26 35 29 23 5 6 14 34 33 10 2 28 15 11 24 4 13 7 8 31 37 36 1 27 3 16 30 25 20 21 18 17 12", "output": "7" } ]
93
4,403,200
3
7,280
551
GukiZ and GukiZiana
[ "binary search", "data structures", "implementation" ]
null
null
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called *GukiZiana*. For given array *a*, indexed with integers from 1 to *n*, and number *y*, *GukiZiana*(*a*,<=*y*) represents maximum value of *j*<=-<=*i*, such that *a**j*<==<=*a**i*<==<=*y*. If there is no *y* as an element in *a*, then *GukiZiana*(*a*,<=*y*) is equal to <=-<=1. GukiZ also prepared a problem for you. This time, you have two types of queries: 1. First type has form 1 *l* *r* *x* and asks you to increase values of all *a**i* such that *l*<=≀<=*i*<=≀<=*r* by the non-negative integer *x*. 1. Second type has form 2 *y* and asks you to find value of *GukiZiana*(*a*,<=*y*). For each query of type 2, print the answer and make GukiZ happy!
The first line contains two integers *n*, *q* (1<=≀<=*n*<=≀<=5<=*<=105,<=1<=≀<=*q*<=≀<=5<=*<=104), size of array *a*, and the number of queries. The second line contains *n* integers *a*1,<=*a*2,<=... *a**n* (1<=≀<=*a**i*<=≀<=109), forming an array *a*. Each of next *q* lines contain either four or two numbers, as described in statement: If line starts with 1, then the query looks like 1 *l* *r* *x* (1<=≀<=*l*<=≀<=*r*<=≀<=*n*, 0<=≀<=*x*<=≀<=109), first type query. If line starts with 2, then th query looks like 2 *y* (1<=≀<=*y*<=≀<=109), second type query.
For each query of type 2, print the value of *GukiZiana*(*a*,<=*y*), for *y* value for that query.
[ "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3\n", "2 3\n1 2\n1 2 2 1\n2 3\n2 4\n" ]
[ "2\n", "0\n-1\n" ]
none
[ { "input": "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3", "output": "2" }, { "input": "2 3\n1 2\n1 2 2 1\n2 3\n2 4", "output": "0\n-1" }, { "input": "8 5\n1 1 1 2 1 3 1 1\n2 1\n1 1 8 1\n2 2\n1 2 5 2\n2 4", "output": "7\n7\n4" }, { "input": "8 8\n1 9 1 9 2 3 4 5\n1 3 7 1\n2 6\n2 8\n2 9\n1 1 7 3\n2 11\n2 1000000000\n1 1 1 1", "output": "-1\n-1\n0\n-1\n-1" }, { "input": "7 3\n2 4 5 2 3 2 8\n2 2\n1 3 4 1\n2 4", "output": "5\n0" }, { "input": "2 2\n1000000000 1000000000\n1 1 2 1\n2 1000000000", "output": "-1" }, { "input": "4 4\n1000000000 1000000000 1000000000 1000000000\n2 1000000000\n1 1 2 1000000000\n1 1 3 1000000000\n2 1000000000", "output": "3\n0" }, { "input": "6 4\n1 9 9 2 3 4\n1 2 6 6\n1 5 6 5\n2 15\n2 1", "output": "4\n0" }, { "input": "1 5\n1\n2 4\n2 1\n1 1 1 999\n2 1000\n2 1000", "output": "-1\n0\n0\n0" }, { "input": "9 10\n1 1 2 1 3 3 7 8 9\n1 4 6 5\n2 8\n1 1 3 6\n2 1001212\n2 7\n1 3 3 1\n2 9\n2 8\n1 1 9 0\n2 6", "output": "3\n-1\n6\n6\n3\n0" }, { "input": "1 1\n1\n2 1", "output": "0" }, { "input": "1 1\n1\n2 5", "output": "-1" } ]
140
0
0
7,287
774
Lie or Truth
[ "*special", "constructive algorithms", "implementation", "sortings" ]
null
null
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to *b*1,<=*b*2,<=...,<=*b**n*. Stepan said that he swapped only cubes which where on the positions between *l* and *r*, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions *l* and *r*, inclusive, in some way). Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
The first line contains three integers *n*, *l*, *r* (1<=≀<=*n*<=≀<=105, 1<=≀<=*l*<=≀<=*r*<=≀<=*n*) β€” the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≀<=*b**i*<=≀<=*n*) β€” the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
[ "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n" ]
[ "TRUTH\n", "LIE\n", "TRUTH\n" ]
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]). In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother. In the third example for any values *l* and *r* there is a situation when Stepan said the truth.
[ { "input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH" }, { "input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE" }, { "input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH" }, { "input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "output": "TRUTH" }, { "input": "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4", "output": "TRUTH" }, { "input": "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6", "output": "TRUTH" }, { "input": "1 1 1\n1\n1", "output": "TRUTH" }, { "input": "4 3 4\n1 2 3 4\n2 1 3 4", "output": "LIE" }, { "input": "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7", "output": "LIE" }, { "input": "5 1 2\n1 2 3 4 5\n1 2 3 5 4", "output": "LIE" }, { "input": "8 3 6\n5 3 1 1 1 1 3 5\n3 3 1 1 1 1 5 5", "output": "LIE" }, { "input": "4 2 2\n2 1 2 2\n1 2 2 2", "output": "LIE" } ]
140
19,046,400
3
7,288
580
Kefa and Company
[ "binary search", "sortings", "two pointers" ]
null
null
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least *d* units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!
The first line of the input contains two space-separated integers, *n* and *d* (1<=≀<=*n*<=≀<=105, ) β€” the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next *n* lines contain the descriptions of Kefa's friends, the (*i*<=+<=1)-th line contains the description of the *i*-th friend of type *m**i*, *s**i* (0<=≀<=*m**i*,<=*s**i*<=≀<=109) β€” the amount of money and the friendship factor, respectively.
Print the maximum total friendship factir that can be reached.
[ "4 5\n75 5\n0 100\n150 20\n75 1\n", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n" ]
[ "100\n", "111\n" ]
In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse. In the second sample test we can take all the friends.
[ { "input": "4 5\n75 5\n0 100\n150 20\n75 1", "output": "100" }, { "input": "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "output": "111" }, { "input": "1 1000000000\n15 12", "output": "12" }, { "input": "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "output": "12" }, { "input": "3 3\n4 15\n0 17\n9 11", "output": "17" }, { "input": "5 10\n8 90\n1009 1000000\n9 121\n10 298\n0 109092", "output": "1000000" }, { "input": "5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989", "output": "3989899086" }, { "input": "4 2\n10909234 9\n10909236 8\n10909237 10\n10909235 98", "output": "107" }, { "input": "3 1\n801 10101\n802 134509124\n801 1", "output": "134509124" }, { "input": "4 1\n2 4\n2 2\n3 3\n3 3", "output": "6" }, { "input": "8 5\n3 227589091\n12 131068951\n8 492784630\n20 918918112\n11 6972428\n20 585402296\n12 220234661\n1 225083234", "output": "1504320408" }, { "input": "15 1234\n2738 322313356\n1160 970909702\n2594 902749351\n3126 324754476\n3151 177963947\n3424 396145897\n5578 737768323\n3423 687640543\n381 848813098\n1058 197211286\n936 650181776\n1025 776492538\n3598 142176544\n3595 680519527\n1191 32199940", "output": "3634263641" }, { "input": "5 6\n5 11\n10 11\n11 11\n12 11\n100 1", "output": "33" }, { "input": "7 6\n5 11\n9 11\n10 11\n11 11\n12 11\n13 11\n100 1", "output": "55" }, { "input": "4 2\n1 1\n2 100\n3 100\n4 1", "output": "200" } ]
0
0
0
7,294
3
Tic-tac-toe
[ "brute force", "games", "implementation" ]
C. Tic-tac-toe
1
64
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=Γ—<=3 grid (one player always draws crosses, the other β€” noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced. You are given a 3<=Γ—<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below: - illegal β€” if the given board layout can't appear during a valid game; - the first player won β€” if in the given board layout the first player has just won; - the second player won β€” if in the given board layout the second player has just won; - draw β€” if the given board layout has just let to a draw.
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
[ "X0X\n.0.\n.X.\n" ]
[ "second\n" ]
none
[ { "input": "X0X\n.0.\n.X.", "output": "second" }, { "input": "0.X\nXX.\n000", "output": "illegal" }, { "input": "XXX\n.0.\n000", "output": "illegal" }, { "input": "XXX\n...\n000", "output": "illegal" }, { "input": "X.X\nX..\n00.", "output": "second" }, { "input": "X.X\nX.0\n0.0", "output": "first" }, { "input": "XXX\nX00\nX00", "output": "the first player won" }, { "input": "000\nX.X\nX.X", "output": "illegal" }, { "input": "XXX\n0.0\n0..", "output": "illegal" }, { "input": "X0X\n0X0\nX0X", "output": "the first player won" }, { "input": "XX.\nX0X\nX..", "output": "illegal" }, { "input": "X0X\n0X0\nX..", "output": "the first player won" }, { "input": "XX0\n0..\n000", "output": "illegal" }, { "input": "XXX\n0..\n.0.", "output": "the first player won" }, { "input": "XXX\nX..\n.00", "output": "illegal" }, { "input": "X00\n0.0\nXX0", "output": "illegal" }, { "input": "0.0\n0XX\n..0", "output": "illegal" }, { "input": ".00\nX.X\n0..", "output": "illegal" }, { "input": "..0\n.00\n.0X", "output": "illegal" }, { "input": "..0\n0..\n00X", "output": "illegal" }, { "input": "..0\n.XX\nX..", "output": "illegal" }, { "input": "0.X\n0X0\n.00", "output": "illegal" }, { "input": "..X\n0X0\n0X.", "output": "first" }, { "input": "0X0\nX..\nX.0", "output": "first" }, { "input": ".0.\nX.X\n0..", "output": "first" }, { "input": "0X0\n00X\n.00", "output": "illegal" }, { "input": ".0.\n.X0\nX..", "output": "first" }, { "input": "00X\n0.X\n00X", "output": "illegal" }, { "input": "00X\n0XX\n0X.", "output": "the second player won" }, { "input": "X00\n..0\nX.X", "output": "first" }, { "input": "X00\nX00\n.X0", "output": "illegal" }, { "input": "X0X\n.X0\n0..", "output": "first" }, { "input": "..0\nXXX\n000", "output": "illegal" }, { "input": "XXX\n...\n.0.", "output": "illegal" }, { "input": "0..\n000\nX0X", "output": "illegal" }, { "input": ".00\n0X.\n0.0", "output": "illegal" }, { "input": "X..\nX00\n0.0", "output": "illegal" }, { "input": ".X0\nXX0\nX.X", "output": "illegal" }, { "input": "X.X\n0.0\nX..", "output": "second" }, { "input": "00X\n.00\n..0", "output": "illegal" }, { "input": "..0\n0.X\n00.", "output": "illegal" }, { "input": "0.X\nX0X\n.X0", "output": "illegal" }, { "input": "0X.\n.X.\n0X0", "output": "illegal" }, { "input": "00.\nX0.\n..X", "output": "illegal" }, { "input": "..X\n.00\nXX.", "output": "second" }, { "input": ".00\n.0.\n.X.", "output": "illegal" }, { "input": "XX0\nX.0\nXX0", "output": "illegal" }, { "input": "00.\n00.\nX.X", "output": "illegal" }, { "input": "X00\nX.0\nX.0", "output": "illegal" }, { "input": "0X.\n0XX\n000", "output": "illegal" }, { "input": "00.\n00.\n.X.", "output": "illegal" }, { "input": "X0X\n00.\n0.X", "output": "illegal" }, { "input": "XX0\nXXX\n0X0", "output": "illegal" }, { "input": "XX0\n..X\nXX0", "output": "illegal" }, { "input": "0X.\n..X\nX..", "output": "illegal" }, { "input": "...\nX0.\nXX0", "output": "second" }, { "input": "..X\n.0.\n0..", "output": "illegal" }, { "input": "00X\nXX.\n00X", "output": "first" }, { "input": "..0\nXX0\n..X", "output": "second" }, { "input": ".0.\n.00\nX00", "output": "illegal" }, { "input": "X00\n.XX\n00.", "output": "illegal" }, { "input": ".00\n0.X\n000", "output": "illegal" }, { "input": "X0.\n..0\nX.0", "output": "illegal" }, { "input": "X0X\n.XX\n00.", "output": "second" }, { "input": "0X.\n00.\n.X.", "output": "illegal" }, { "input": ".0.\n...\n0.0", "output": "illegal" }, { "input": "..X\nX00\n0.0", "output": "illegal" }, { "input": "0XX\n...\nX0.", "output": "second" }, { "input": "X.X\n0X.\n.0X", "output": "illegal" }, { "input": "XX0\nX.X\n00.", "output": "second" }, { "input": ".0X\n.00\n00.", "output": "illegal" }, { "input": ".XX\nXXX\n0..", "output": "illegal" }, { "input": "XX0\n.X0\n.0.", "output": "first" }, { "input": "X00\n0.X\nX..", "output": "first" }, { "input": "X..\n.X0\nX0.", "output": "second" }, { "input": ".0X\nX..\nXXX", "output": "illegal" }, { "input": "X0X\nXXX\nX.X", "output": "illegal" }, { "input": ".00\nX0.\n00X", "output": "illegal" }, { "input": "0XX\n.X0\n0.0", "output": "illegal" }, { "input": "00X\nXXX\n..0", "output": "the first player won" }, { "input": "X0X\n...\n.X.", "output": "illegal" }, { "input": ".X0\n...\n0X.", "output": "first" }, { "input": "X..\n0X0\nX.0", "output": "first" }, { "input": "..0\n.00\nX.0", "output": "illegal" }, { "input": ".XX\n.0.\nX0X", "output": "illegal" }, { "input": "00.\n0XX\n..0", "output": "illegal" }, { "input": ".0.\n00.\n00.", "output": "illegal" }, { "input": "00.\n000\nX.X", "output": "illegal" }, { "input": "0X0\n.X0\n.X.", "output": "illegal" }, { "input": "00X\n0..\n0..", "output": "illegal" }, { "input": ".X.\n.X0\nX.0", "output": "second" }, { "input": ".0.\n0X0\nX0X", "output": "illegal" }, { "input": "...\nX.0\n0..", "output": "illegal" }, { "input": "..0\nXX.\n00X", "output": "first" }, { "input": "0.X\n.0X\nX00", "output": "illegal" }, { "input": "..X\n0X.\n.0.", "output": "first" }, { "input": "..X\nX.0\n.0X", "output": "second" }, { "input": "X0.\n.0X\nX0X", "output": "illegal" }, { "input": "...\n.0.\n.X0", "output": "illegal" }, { "input": ".X0\nXX0\n0..", "output": "first" }, { "input": "0X.\n...\nX..", "output": "second" }, { "input": ".0.\n0.0\n0.X", "output": "illegal" }, { "input": "XX.\n.X0\n.0X", "output": "illegal" }, { "input": ".0.\nX0X\nX00", "output": "illegal" }, { "input": "0X.\n.X0\nX..", "output": "second" }, { "input": "..0\n0X.\n000", "output": "illegal" }, { "input": "0.0\nX.X\nXX.", "output": "illegal" }, { "input": ".X.\n.XX\nX0.", "output": "illegal" }, { "input": "X.X\n.XX\n0X.", "output": "illegal" }, { "input": "X.0\n0XX\n..0", "output": "first" }, { "input": "X.0\n0XX\n.X0", "output": "second" }, { "input": "X00\n0XX\n.X0", "output": "first" }, { "input": "X00\n0XX\nXX0", "output": "draw" }, { "input": "X00\n0XX\n0X0", "output": "illegal" }, { "input": "XXX\nXXX\nXXX", "output": "illegal" }, { "input": "000\n000\n000", "output": "illegal" }, { "input": "XX0\n00X\nXX0", "output": "draw" }, { "input": "X00\n00X\nXX0", "output": "illegal" }, { "input": "X.0\n00.\nXXX", "output": "the first player won" }, { "input": "X..\nX0.\nX0.", "output": "the first player won" }, { "input": ".XX\n000\nXX0", "output": "the second player won" }, { "input": "X0.\nX.X\nX00", "output": "the first player won" }, { "input": "00X\nX00\nXXX", "output": "the first player won" }, { "input": "XXX\n.00\nX0.", "output": "the first player won" }, { "input": "XX0\n000\nXX.", "output": "the second player won" }, { "input": ".X0\n0.0\nXXX", "output": "the first player won" }, { "input": "0XX\nX00\n0XX", "output": "draw" }, { "input": "0XX\nX0X\n00X", "output": "the first player won" }, { "input": "XX0\n0XX\n0X0", "output": "the first player won" }, { "input": "0X0\nX0X\nX0X", "output": "draw" }, { "input": "X0X\n0XX\n00X", "output": "the first player won" }, { "input": "0XX\nX0.\nX00", "output": "the second player won" }, { "input": "X.0\n0X0\nXX0", "output": "the second player won" }, { "input": "X0X\nX0X\n0X0", "output": "draw" }, { "input": "X.0\n00X\n0XX", "output": "the second player won" }, { "input": "00X\nX0X\n.X0", "output": "the second player won" }, { "input": "X0X\n.00\nX0X", "output": "the second player won" }, { "input": "0XX\nX00\nX0X", "output": "draw" }, { "input": "000\nX0X\n.XX", "output": "the second player won" }, { "input": "0.0\n0.X\nXXX", "output": "the first player won" }, { "input": "X.0\nX0.\n0X.", "output": "the second player won" }, { "input": "X0X\n0X0\n..X", "output": "the first player won" }, { "input": "0X0\nXX0\n.X.", "output": "the first player won" }, { "input": "X0.\n.X.\n0.X", "output": "the first player won" }, { "input": "0XX\nX00\n.X0", "output": "the second player won" }, { "input": "0.0\nXXX\n0.X", "output": "the first player won" }, { "input": ".0X\n.X.\nX.0", "output": "the first player won" }, { "input": "XXX\nX.0\n0.0", "output": "the first player won" }, { "input": "XX0\nX..\nX00", "output": "the first player won" }, { "input": "XXX\n00X\n00X", "output": "the first player won" }, { "input": "X00\n00X\nXXX", "output": "the first player won" }, { "input": "0X0\nX0X\n0X.", "output": "the second player won" }, { "input": "XX0\nX00\n0X.", "output": "the second player won" }, { "input": "..X\n0X0\nX..", "output": "the first player won" }, { "input": "X0.\n00.\nXXX", "output": "the first player won" }, { "input": "0.X\nX00\nXX0", "output": "the second player won" }, { "input": "X0.\n0X.\n..X", "output": "the first player won" }, { "input": "00X\nX0.\nXX0", "output": "the second player won" }, { "input": "XX.\n000\n0XX", "output": "the second player won" }, { "input": "..X\n0.X\n.0X", "output": "the first player won" }, { "input": "X00\n.0X\n0XX", "output": "the second player won" }, { "input": "00X\n0X.\nXX.", "output": "the first player won" }, { "input": "X00\nXX.\n0.X", "output": "the first player won" }, { "input": "XXX\n00X\n0X0", "output": "the first player won" }, { "input": "X00\nXX0\n0XX", "output": "the first player won" }, { "input": "0X0\nX00\nXXX", "output": "the first player won" }, { "input": "XX0\nX00\n.X0", "output": "the second player won" } ]
218
0
0
7,297
512
Fox And Travelling
[ "dp", "trees" ]
null
null
Fox Ciel is going to travel to New Foxland during this summer. New Foxland has *n* attractions that are linked by *m* undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has *k* days to visit this city and each day she will visit exactly one attraction. There is one important rule in New Foxland: you can't visit an attraction if it has more than one adjacent attraction that you haven't visited yet. At the beginning Fox Ciel haven't visited any attraction. During her travelling she may move aribtrarly between attraction. After visiting attraction *a*, she may travel to any attraction *b* satisfying conditions above that hasn't been visited yet, even if it is not reachable from *a* by using the roads (Ciel uses boat for travelling between attractions, so it is possible). She wants to know how many different travelling plans she can make. Calculate this number modulo 109<=+<=9 for every *k* from 0 to *n* since she hasn't decided for how many days she is visiting New Foxland.
First line contains two integers: *n*, *m* (1<=≀<=*n*<=≀<=100, ), the number of attractions and number of undirected roads. Then next *m* lines each contain two integers *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n* and *a**i*<=β‰ <=*b**i*), describing a road. There is no more than one road connecting each pair of attractions.
Output *n*<=+<=1 integer: the number of possible travelling plans modulo 109<=+<=9 for all *k* from 0 to *n*.
[ "3 2\n1 2\n2 3\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9\n", "13 0\n" ]
[ "1\n2\n4\n4\n", "1\n0\n0\n0\n0\n", "1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0\n", "1\n13\n156\n1716\n17160\n154440\n1235520\n8648640\n51891840\n259459200\n37836791\n113510373\n227020746\n227020746\n" ]
In the first sample test for *k* = 3 there are 4 travelling plans: {1, 2, 3}, {1, 3, 2}, {3, 1, 2}, {3, 2, 1}. In the second sample test Ciel can't visit any attraction in the first day, so for *k* &gt; 0 the answer is 0. In the third sample test Foxlands look like this:
[ { "input": "3 2\n1 2\n2 3", "output": "1\n2\n4\n4" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "1\n0\n0\n0\n0" }, { "input": "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9", "output": "1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0" }, { "input": "13 0", "output": "1\n13\n156\n1716\n17160\n154440\n1235520\n8648640\n51891840\n259459200\n37836791\n113510373\n227020746\n227020746" }, { "input": "1 0", "output": "1\n1" }, { "input": "2 0", "output": "1\n2\n2" }, { "input": "2 1\n1 2", "output": "1\n2\n2" }, { "input": "4 4\n1 2\n2 3\n3 1\n1 4", "output": "1\n1\n0\n0\n0" }, { "input": "10 9\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10", "output": "1\n6\n30\n126\n456\n1440\n3840\n8640\n17280\n34560\n34560" }, { "input": "5 10\n1 2\n2 3\n3 4\n4 5\n5 1\n1 3\n2 4\n3 5\n4 1\n5 2", "output": "1\n0\n0\n0\n0\n0" }, { "input": "100 0", "output": "1\n100\n9900\n970200\n94109400\n34502319\n277720278\n105705898\n830648433\n419655152\n188618490\n975663956\n834091310\n400034623\n803011895\n59022349\n16899620\n419568071\n824149587\n580265531\n1507588\n120607040\n527956079\n180573793\n904181944\n717827132\n837034423\n940546753\n659912357\n513689281\n471938627\n35703593\n463547899\n521256853\n924208845\n997783230\n855909374\n778199450\n26564909\n647024349\n468484938\n109096028\n436665598\n326604459\n616454001\n521423750\n678305998\n628523568\n311748807\n21..." }, { "input": "100 2\n12 34\n12 56", "output": "1\n99\n9704\n941680\n90458320\n600842488\n346513039\n88126817\n142825254\n372744346\n640812455\n127920061\n952453050\n626691132\n442123857\n302303579\n906937960\n495773343\n501003222\n227553343\n909691654\n49271904\n985878757\n996818267\n125698678\n984367292\n310098640\n691072079\n256138586\n993386986\n577692998\n649307769\n925719562\n98866779\n369987499\n157629902\n768620285\n597655701\n415740627\n581826595\n39990893\n216450750\n339433948\n542198165\n931909567\n624114603\n496806559\n693746271\n944360371\n..." }, { "input": "87 14\n6 3\n41 74\n42 60\n13 29\n81 50\n22 31\n2 18\n76 21\n23 14\n82 20\n30 51\n30 55\n28 80\n2 41", "output": "1\n84\n6976\n572700\n46471400\n726706453\n316070145\n265228551\n650766217\n397694580\n810490016\n588766114\n486939677\n23301479\n69854128\n435879533\n534425387\n176302137\n336389003\n700458175\n694321423\n776580617\n83316821\n704801977\n783786908\n628610450\n159822561\n200235489\n973461472\n97174\n426820671\n312050405\n113809085\n781983585\n206089750\n531282185\n727609686\n762987206\n198914948\n735829661\n849861129\n350151479\n310068089\n364975144\n503290486\n481587910\n403550011\n642896373\n610874464\n795..." }, { "input": "11 9\n3 6\n6 1\n10 9\n9 8\n5 2\n7 9\n3 2\n11 7\n7 2", "output": "1\n6\n31\n138\n532\n1792\n5320\n14016\n33200\n73040\n146080\n146080" }, { "input": "39 67\n21 38\n34 3\n28 10\n30 32\n4 12\n36 32\n22 30\n14 11\n25 33\n6 9\n21 10\n35 20\n34 21\n2 35\n12 13\n8 10\n1 17\n31 14\n31 16\n9 22\n12 25\n22 17\n1 14\n35 18\n33 21\n3 21\n30 5\n20 17\n34 22\n19 23\n18 3\n22 12\n38 27\n18 32\n13 11\n4 7\n32 2\n33 30\n4 28\n20 31\n39 37\n7 30\n2 34\n10 3\n15 17\n2 1\n37 31\n14 19\n24 30\n12 37\n8 2\n8 35\n38 25\n25 20\n27 15\n21 9\n22 25\n12 27\n33 6\n37 13\n37 10\n7 36\n7 2\n29 21\n1 37\n13 33\n12 30", "output": "1\n7\n43\n228\n1020\n3720\n10440\n20160\n20160\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "15 16\n8 12\n9 3\n4 10\n4 12\n5 10\n14 11\n7 13\n14 10\n4 8\n3 8\n6 14\n9 11\n11 3\n10 2\n15 5\n4 9", "output": "1\n6\n31\n135\n480\n1320\n2520\n2520\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "39 5\n4 26\n16 32\n2 36\n38 30\n18 35", "output": "1\n39\n1482\n54834\n1974024\n69090840\n349088542\n519921787\n637497040\n762408069\n872241872\n295014063\n260393692\n30629621\n796370146\n909253479\n822083307\n907915899\n974149607\n457141567\n142831259\n713793903\n848290146\n420932356\n734917642\n23764531\n332703434\n325144606\n901735245\n919087614\n190876059\n717884522\n743076131\n201532872\n209197223\n45986106\n183944424\n551833272\n103666535\n103666535" }, { "input": "18 73\n15 9\n8 17\n17 18\n2 17\n9 17\n17 15\n5 2\n15 8\n2 7\n8 2\n10 12\n7 11\n16 1\n18 7\n11 18\n2 13\n16 3\n12 1\n13 5\n8 6\n7 8\n15 1\n17 16\n9 1\n16 12\n3 13\n16 4\n6 14\n18 16\n12 15\n6 2\n9 3\n4 10\n3 4\n3 1\n6 7\n16 5\n15 13\n13 8\n1 6\n2 3\n16 10\n1 8\n18 3\n3 7\n12 11\n15 4\n11 5\n16 9\n12 5\n18 14\n6 13\n9 11\n18 9\n6 4\n8 11\n1 5\n8 4\n12 9\n3 11\n12 7\n4 18\n4 11\n4 17\n18 10\n6 18\n9 14\n13 12\n8 9\n3 14\n8 12\n13 9\n13 11", "output": "1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "46 59\n37 41\n9 28\n16 3\n3 45\n4 24\n14 3\n31 10\n39 29\n44 22\n21 31\n36 17\n8 44\n28 25\n4 40\n21 3\n31 20\n20 42\n34 25\n28 24\n25 36\n32 34\n45 10\n33 15\n17 37\n27 21\n20 33\n12 40\n38 15\n26 10\n12 28\n5 2\n22 19\n6 17\n39 26\n28 5\n33 44\n23 19\n17 33\n3 18\n28 11\n26 15\n1 8\n34 12\n21 38\n14 27\n40 1\n36 24\n21 5\n17 16\n6 27\n45 24\n37 36\n30 37\n41 9\n46 6\n46 35\n46 40\n14 15\n11 7", "output": "1\n11\n113\n1081\n9598\n78770\n594450\n4097730\n25576320\n142853760\n702475200\n970475182\n418284710\n540511748\n486431514\n486431514\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "46 39\n5 1\n20 10\n15 12\n23 39\n5 46\n7 20\n10 15\n14 13\n10 29\n4 9\n24 11\n23 4\n9 17\n45 35\n14 41\n11 36\n37 45\n26 43\n23 30\n9 24\n40 8\n18 42\n27 43\n26 1\n10 44\n13 2\n40 28\n41 22\n34 8\n30 45\n18 31\n30 39\n27 13\n16 8\n15 16\n46 39\n33 26\n46 34\n45 6", "output": "1\n21\n426\n8340\n157418\n2861600\n50041676\n840802388\n556159899\n447731031\n742162112\n541656432\n665855465\n213762995\n551018805\n487408985\n480483467\n499783200\n137325023\n286243386\n783547189\n757667150\n782491787\n35652955\n936552213\n909332468\n24025205\n533542820\n606700069\n265469096\n581125006\n211502771\n232630734\n314473517\n840164188\n850530410\n52488472\n420469406\n10142705\n373315703\n207418995\n617272390\n378994942\n378994942\n0\n0\n0" }, { "input": "94 4\n35 64\n49 54\n91 49\n72 1", "output": "1\n93\n8558\n779146\n70173376\n251459706\n799378730\n419325370\n771116412\n660012486\n653197338\n143771116\n223815061\n617837913\n980113090\n357967627\n346369250\n103250856\n434035711\n781983878\n703509953\n999549027\n693798803\n823947146\n560177124\n287657333\n890709029\n363526123\n51575057\n904755963\n359677149\n152822293\n770387110\n318964236\n199684960\n67368257\n892160696\n121599305\n626527417\n635357834\n85288535\n917195751\n503733974\n812146618\n700506875\n514770166\n226794059\n26697633\n581019188\n..." }, { "input": "22 17\n2 4\n4 1\n19 10\n22 16\n14 9\n9 15\n15 3\n9 10\n14 3\n7 8\n10 11\n14 12\n16 10\n3 6\n12 20\n10 22\n5 13", "output": "1\n13\n159\n1822\n19460\n192480\n1749120\n14459760\n107412480\n705801600\n18895964\n279814229\n804082534\n21399620\n891452085\n891452085\n0\n0\n0\n0\n0\n0\n0" }, { "input": "39 38\n7 14\n37 7\n31 37\n30 31\n28 30\n27 28\n4 27\n29 4\n13 29\n1 13\n21 1\n17 21\n9 17\n20 9\n39 20\n32 39\n26 32\n25 26\n10 25\n5 10\n24 5\n16 24\n35 16\n18 35\n23 18\n22 23\n38 22\n3 38\n8 3\n19 8\n34 19\n36 34\n33 36\n15 33\n6 15\n12 6\n11 12\n2 11", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n877904478" }, { "input": "59 58\n5 1\n30 1\n26 1\n18 30\n16 30\n51 5\n17 18\n55 30\n11 18\n42 26\n56 51\n43 55\n14 55\n40 43\n15 14\n23 55\n25 43\n13 15\n41 40\n48 15\n6 13\n4 23\n22 23\n50 25\n20 50\n52 22\n12 50\n21 48\n53 22\n10 20\n34 21\n57 21\n46 10\n58 57\n7 58\n27 34\n31 10\n45 57\n3 57\n39 46\n2 31\n8 7\n54 7\n47 3\n44 45\n29 47\n38 54\n19 29\n37 29\n9 44\n36 54\n35 36\n24 29\n28 36\n49 36\n32 9\n59 24\n33 49", "output": "1\n23\n516\n11292\n241023\n5016998\n101818269\n14061402\n817490396\n633882406\n285001086\n183039112\n338612173\n792374071\n570319663\n91353477\n742936146\n59684303\n537267253\n779877440\n842744292\n767853666\n902018306\n839151657\n439548607\n271764295\n669160207\n459191311\n513622274\n127447115\n128981623\n81460327\n630746939\n777700007\n531624847\n393938348\n612659345\n274750631\n223423576\n151550052\n358559376\n462650502\n668983593\n834839016\n276856191\n569766603\n710550568\n420747346\n222118690\n199646..." }, { "input": "39 38\n28 9\n36 28\n35 36\n3 36\n32 3\n29 32\n5 35\n8 3\n38 36\n21 8\n2 32\n25 29\n7 35\n12 32\n1 28\n24 28\n10 7\n31 32\n27 25\n30 29\n23 25\n34 36\n18 30\n20 23\n39 21\n15 28\n22 21\n13 15\n14 34\n17 35\n37 20\n26 27\n11 20\n19 17\n6 35\n33 20\n4 26\n16 26", "output": "1\n21\n425\n8284\n155414\n2804386\n48636098\n810031976\n944606932\n294597738\n928529900\n180377354\n963153140\n68785234\n189448879\n775885272\n732622867\n655693824\n661296430\n405881220\n513811982\n13768630\n953745260\n927622528\n616718217\n340614776\n363282265\n184687710\n120603613\n651360302\n716491054\n830663411\n132215301\n858416707\n948092327\n830807545\n808714833\n617429657\n234859305\n234859305" }, { "input": "59 58\n41 49\n19 41\n48 19\n36 48\n7 36\n54 7\n44 54\n22 44\n6 22\n14 6\n45 14\n42 45\n24 42\n2 24\n27 2\n51 27\n57 51\n59 57\n50 59\n9 50\n37 9\n43 37\n53 43\n52 53\n5 52\n39 5\n35 39\n29 35\n33 29\n34 33\n17 34\n47 17\n18 47\n8 18\n31 8\n12 31\n21 12\n13 21\n26 13\n46 26\n58 46\n3 58\n56 3\n10 56\n4 10\n20 4\n16 20\n25 16\n38 25\n32 38\n1 32\n23 1\n40 23\n30 40\n11 30\n28 11\n55 28\n15 55", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n755808947\n511617885\n23235761\n46471522\n92943044\n185886088\n371772176\n743544352\n487088695\n974177390\n948354771\n896709533\n793419057\n586838105\n173676201\n347352402\n694704804\n389409599\n778819198\n..." }, { "input": "15 14\n10 8\n6 8\n2 8\n1 8\n13 8\n15 8\n4 8\n11 8\n14 8\n3 8\n7 8\n5 8\n9 8\n12 8", "output": "1\n14\n182\n2184\n24024\n240240\n2162160\n17297280\n121080960\n726485760\n632428773\n529715074\n589145213\n178290417\n356580834\n356580834" }, { "input": "39 38\n1 38\n31 38\n16 38\n35 38\n13 38\n15 38\n4 38\n23 38\n34 38\n6 38\n10 38\n36 38\n21 38\n39 38\n17 38\n22 38\n2 38\n9 38\n33 38\n24 38\n20 38\n29 38\n14 38\n32 38\n26 38\n7 38\n3 38\n12 38\n27 38\n28 38\n5 38\n30 38\n19 38\n37 38\n8 38\n11 38\n18 38\n25 38", "output": "1\n38\n1406\n50616\n1771560\n60233040\n987690311\n606089673\n788779701\n663390823\n238333696\n673343434\n180272556\n687086420\n177160347\n251848292\n792510671\n435234609\n139926708\n798534142\n172148563\n98674107\n677459810\n839356870\n590352942\n264941116\n444234481\n330813727\n638950970\n389509646\n505586787\n44694260\n312859820\n877158911\n385794519\n543178067\n629534192\n259068375\n518136750\n518136750" }, { "input": "18 17\n12 13\n6 13\n10 13\n7 13\n3 13\n11 13\n1 13\n14 13\n18 13\n17 13\n5 13\n8 13\n4 13\n2 13\n15 13\n16 13\n9 13", "output": "1\n17\n272\n4080\n57120\n742560\n8910720\n98017920\n980179200\n821612728\n572901770\n10312354\n61874124\n309370620\n237482471\n712447413\n424894817\n849789634\n849789634" }, { "input": "46 45\n13 15\n36 15\n40 15\n33 15\n45 15\n32 15\n11 15\n10 15\n1 15\n46 15\n2 15\n7 15\n43 15\n26 15\n3 15\n6 15\n39 15\n44 15\n38 15\n12 15\n23 15\n37 15\n21 15\n19 15\n25 15\n16 15\n4 15\n31 15\n34 15\n35 15\n22 15\n18 15\n9 15\n14 15\n20 15\n8 15\n5 15\n27 15\n17 15\n28 15\n42 15\n29 15\n30 15\n24 15\n41 15", "output": "1\n45\n1980\n85140\n3575880\n146611080\n864443155\n713282748\n104744181\n875534670\n519247841\n173674273\n904925237\n862532560\n601041677\n632291825\n968754588\n93882800\n628718382\n975396170\n360300195\n7504794\n180115056\n142646252\n138217517\n902567839\n51356618\n975775742\n563963203\n587374370\n397989839\n969847540\n577865443\n512250696\n147008298\n617091269\n170912636\n538213715\n305709684\n139967770\n839806620\n199033064\n796132256\n388396750\n776793500\n553586991\n553586991" }, { "input": "42 42\n22 27\n21 27\n37 27\n30 27\n40 27\n38 27\n31 27\n5 27\n2 27\n12 27\n26 27\n33 27\n6 27\n32 27\n28 27\n35 27\n13 27\n29 27\n1 27\n41 27\n17 27\n34 27\n23 27\n14 27\n15 27\n36 27\n7 27\n25 27\n9 27\n19 27\n18 27\n20 27\n8 27\n39 27\n16 27\n10 27\n3 27\n24 27\n11 27\n42 27\n4 27\n4 42", "output": "1\n39\n1482\n54834\n1974024\n69090840\n349088542\n519921787\n637497040\n762408069\n872241872\n295014063\n260393692\n30629621\n796370146\n909253479\n822083307\n907915899\n974149607\n457141567\n142831259\n713793903\n848290146\n420932356\n734917642\n23764531\n332703434\n325144606\n901735245\n919087614\n190876059\n717884522\n743076131\n201532872\n209197223\n45986106\n183944424\n551833272\n103666535\n103666535\n0\n0\n0" }, { "input": "45 45\n24 28\n27 24\n1 27\n12 1\n18 12\n22 18\n2 22\n5 2\n38 5\n39 38\n3 39\n19 3\n11 19\n31 11\n9 31\n8 9\n23 8\n21 23\n15 21\n44 15\n17 44\n7 17\n13 7\n30 13\n42 30\n36 42\n4 36\n45 4\n10 45\n32 10\n33 32\n34 33\n29 34\n43 29\n25 43\n40 25\n14 40\n41 14\n16 41\n35 16\n6 35\n26 6\n20 28\n37 28\n37 20", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0" }, { "input": "46 45\n16 27\n19 16\n17 19\n13 17\n36 13\n21 36\n45 21\n8 45\n22 8\n40 22\n26 40\n33 26\n34 33\n23 34\n42 23\n44 42\n3 44\n37 3\n39 37\n10 39\n11 10\n28 11\n35 28\n18 35\n5 18\n24 5\n9 24\n25 9\n29 25\n2 29\n31 2\n20 31\n7 20\n30 7\n32 30\n12 32\n6 12\n46 6\n15 46\n43 15\n38 43\n41 38\n4 41\n14 4\n1 14", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n755808947\n511617885\n23235761\n46471522\n92943044\n185886088\n371772176\n371772176" }, { "input": "74 73\n73 43\n70 43\n1 43\n49 43\n20 43\n22 43\n7 43\n57 43\n63 43\n13 43\n42 43\n23 43\n59 43\n52 43\n18 43\n15 43\n54 43\n50 43\n48 43\n36 43\n6 43\n61 43\n31 43\n66 43\n37 43\n28 43\n65 43\n14 43\n17 43\n8 43\n60 43\n55 43\n71 43\n9 43\n19 43\n58 43\n11 43\n53 43\n64 43\n5 43\n10 43\n67 43\n51 43\n4 43\n35 43\n2 43\n16 43\n44 43\n72 43\n46 43\n47 43\n32 43\n25 43\n69 43\n41 43\n33 43\n27 43\n39 43\n34 43\n24 43\n21 43\n45 43\n3 43\n62 43\n74 43\n29 43\n26 43\n30 43\n40 43\n38 43\n56 43\n68 43\n12 43", "output": "1\n73\n5256\n373176\n26122320\n802440071\n565924342\n916930581\n517417806\n632157093\n458053592\n857376044\n157314251\n596169230\n770153485\n439055210\n465201955\n516511201\n924627004\n854484770\n142177166\n535389735\n840265977\n853564449\n678222072\n232881231\n178298989\n380052411\n482410753\n708483696\n173282345\n451140772\n947912262\n864402400\n576095694\n467731868\n773810831\n631000495\n716017622\n60616545\n60962512\n11762878\n376412096\n668774877\n63246130\n834137761\n355857101\n608141646\n811682661\n..." }, { "input": "22 21\n1 14\n20 1\n8 20\n5 20\n2 20\n16 1\n9 5\n21 2\n3 16\n19 21\n17 8\n7 8\n4 2\n18 14\n15 17\n6 16\n12 21\n11 2\n22 9\n13 11\n10 13", "output": "1\n10\n94\n834\n7007\n55860\n422815\n3036565\n20652380\n132614160\n800643900\n521108864\n727072393\n847932174\n47535428\n244196721\n893595849\n73275447\n428168034\n676624531\n353249053\n706498106\n706498106" }, { "input": "46 45\n26 5\n33 26\n37 33\n44 37\n9 37\n40 44\n7 9\n39 40\n46 39\n45 39\n41 46\n32 41\n23 32\n21 23\n20 21\n34 20\n30 34\n18 30\n29 18\n36 29\n24 36\n28 36\n4 24\n22 4\n38 4\n27 22\n17 38\n11 17\n16 11\n6 11\n19 6\n12 6\n25 19\n3 12\n8 3\n31 3\n14 8\n15 31\n35 15\n10 35\n2 10\n42 2\n1 2\n43 1\n13 1", "output": "1\n11\n115\n1143\n10792\n96628\n818302\n6532404\n48959810\n342959330\n234396662\n472822633\n856514624\n98651432\n192761141\n636669608\n855658653\n12337986\n582650181\n269698369\n476276845\n629508581\n591981146\n818492896\n194569467\n979693754\n450466973\n49176348\n255386210\n873786214\n906404921\n298267461\n631573671\n280502764\n927325964\n136762366\n857168053\n618075447\n359198421\n921128794\n464830913\n651546886\n86658148\n956880690\n913761371\n827522733\n827522733" }, { "input": "40 39\n5 9\n14 9\n8 9\n25 9\n3 9\n30 9\n4 9\n11 9\n31 9\n26 9\n16 9\n37 9\n12 9\n1 9\n2 9\n22 9\n13 9\n32 9\n19 9\n17 9\n29 9\n27 9\n35 9\n24 9\n21 9\n18 9\n23 9\n33 9\n34 9\n7 9\n6 9\n15 9\n28 9\n20 9\n39 9\n40 9\n38 9\n36 9\n10 9", "output": "1\n39\n1482\n54834\n1974024\n69090840\n349088542\n519921787\n637497040\n762408069\n872241872\n295014063\n260393692\n30629621\n796370146\n909253479\n822083307\n907915899\n974149607\n457141567\n142831259\n713793903\n848290146\n420932356\n734917642\n23764531\n332703434\n325144606\n901735245\n919087614\n190876059\n717884522\n743076131\n201532872\n209197223\n45986106\n183944424\n551833272\n103666535\n207333070\n207333070" }, { "input": "69 68\n23 50\n49 50\n69 50\n4 50\n28 50\n2 50\n42 4\n62 28\n9 28\n25 42\n12 9\n54 42\n10 62\n67 42\n65 42\n53 9\n47 67\n29 54\n41 12\n14 29\n17 14\n15 29\n55 67\n37 53\n51 29\n44 41\n11 51\n64 55\n21 11\n35 15\n13 21\n66 55\n52 37\n57 44\n33 66\n60 64\n27 66\n19 21\n34 66\n48 60\n45 48\n31 27\n22 27\n61 19\n1 48\n59 19\n58 1\n18 45\n68 22\n46 58\n20 59\n16 20\n26 20\n39 59\n40 68\n38 20\n24 39\n5 39\n6 39\n30 39\n3 26\n43 6\n7 39\n36 30\n32 36\n63 36\n56 63\n8 32", "output": "1\n29\n824\n22936\n625301\n16693622\n436314973\n161554721\n383029354\n542175747\n647805613\n572590515\n918671512\n937956462\n609873167\n705047227\n344964089\n492706709\n472326660\n576306578\n556147428\n889649554\n506728503\n652890369\n623100530\n861847867\n500467182\n94265816\n389888700\n567995832\n575036705\n973089590\n53275431\n327870782\n414502149\n8286559\n20451677\n920874011\n49213700\n879350138\n131928670\n72777869\n459508459\n909914824\n146421978\n633690789\n132239860\n835364780\n937692668\n23187593..." }, { "input": "17 16\n4 8\n13 8\n12 8\n9 8\n2 8\n17 8\n10 8\n14 8\n11 8\n16 8\n7 8\n6 8\n15 8\n5 8\n1 8\n3 8", "output": "1\n16\n240\n3360\n43680\n524160\n5765760\n57657600\n518918400\n151347164\n59430139\n356580834\n782904161\n131616617\n394849851\n789699702\n579399395\n579399395" }, { "input": "41 40\n9 22\n8 9\n3 9\n28 9\n35 3\n39 22\n40 35\n14 3\n25 8\n6 8\n36 25\n5 22\n34 35\n21 5\n33 21\n12 35\n27 6\n7 39\n20 28\n10 27\n13 14\n31 12\n32 39\n2 36\n18 36\n15 28\n16 34\n26 8\n4 25\n23 12\n30 31\n29 16\n17 6\n38 21\n11 2\n37 33\n1 33\n19 6\n41 31\n24 18", "output": "1\n20\n385\n7134\n127252\n2184954\n36109212\n574256586\n785817104\n266120511\n163758452\n278863753\n199676489\n965719182\n842948552\n832992662\n555090591\n132658387\n646298727\n611119931\n360951449\n333722212\n813273262\n98796257\n674407660\n310960237\n733522450\n334454742\n907847707\n54357002\n553243408\n825009522\n812126365\n779430185\n933111878\n491489880\n448152476\n704763274\n842007507\n684015005\n368030001\n368030001" }, { "input": "67 67\n58 26\n10 26\n36 26\n8 26\n31 26\n48 26\n41 26\n35 26\n30 26\n51 26\n64 26\n38 26\n65 26\n46 26\n42 26\n2 26\n66 26\n29 26\n1 26\n16 26\n3 26\n14 26\n23 26\n40 26\n59 26\n47 26\n12 26\n21 26\n44 26\n28 26\n45 26\n24 26\n50 26\n43 26\n62 26\n55 26\n25 26\n7 26\n53 26\n61 26\n33 26\n22 26\n11 26\n27 26\n4 26\n54 26\n32 26\n52 26\n19 26\n9 26\n18 26\n49 26\n6 26\n34 26\n67 26\n63 26\n37 26\n56 26\n57 26\n13 26\n60 26\n17 26\n5 26\n15 26\n20 26\n39 26\n39 20", "output": "1\n64\n4032\n249984\n15249024\n914941440\n981544483\n929579510\n986031602\n217769217\n977306836\n774568676\n52139459\n711251850\n273844026\n692201183\n917857670\n57167764\n686884890\n596704661\n851709511\n475218151\n434380313\n243972984\n2892254\n115690160\n511916204\n452815581\n754176353\n150348465\n262196230\n914671748\n184167414\n893357203\n694073050\n822191320\n843548073\n619345837\n722337455\n780773668\n519341529\n464196588\n676521434\n883471422\n552899700\n57993901\n101884110\n833913971\n176537381\n8..." }, { "input": "71 71\n47 64\n45 47\n29 45\n61 29\n3 61\n53 3\n40 53\n65 40\n34 65\n33 34\n31 33\n41 31\n6 41\n38 6\n5 38\n70 5\n7 70\n30 7\n17 30\n55 17\n27 55\n62 27\n44 62\n18 44\n26 18\n15 26\n13 15\n51 13\n10 51\n12 10\n36 12\n24 36\n43 24\n63 43\n67 63\n60 67\n22 60\n39 22\n58 39\n14 58\n32 14\n37 32\n69 37\n68 69\n9 68\n16 9\n20 16\n4 20\n52 4\n42 52\n25 42\n57 25\n49 57\n19 49\n59 19\n46 59\n56 46\n23 56\n2 23\n11 2\n1 11\n48 1\n35 48\n8 35\n66 8\n28 66\n21 28\n50 21\n71 64\n54 64\n54 71", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0" }, { "input": "17 16\n6 10\n13 10\n15 13\n9 10\n12 6\n3 12\n17 13\n14 3\n1 17\n2 17\n16 2\n7 1\n4 1\n5 4\n8 4\n11 7", "output": "1\n7\n45\n267\n1463\n7380\n34115\n143885\n551775\n1919540\n6046950\n17224375\n44400650\n104039250\n223316450\n446632900\n893265800\n893265800" }, { "input": "45 44\n38 9\n4 38\n40 4\n3 40\n31 3\n1 31\n24 1\n27 24\n35 27\n23 35\n39 23\n14 39\n6 14\n13 6\n16 13\n37 16\n36 37\n17 36\n5 17\n41 5\n45 41\n30 45\n29 30\n32 29\n19 32\n26 19\n10 26\n34 10\n15 34\n44 15\n22 44\n12 22\n33 12\n11 33\n28 11\n42 28\n21 42\n8 21\n2 8\n7 2\n20 7\n43 20\n25 43\n18 25", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n755808947\n511617885\n23235761\n46471522\n92943044\n185886088\n185886088" }, { "input": "69 68\n38 57\n41 38\n18 41\n59 18\n23 59\n8 23\n50 8\n42 50\n4 42\n49 4\n54 49\n69 54\n45 69\n39 45\n26 39\n30 26\n35 30\n27 35\n61 27\n68 61\n22 68\n1 22\n12 1\n29 12\n47 29\n25 47\n6 25\n34 6\n5 34\n10 5\n44 10\n62 44\n11 62\n52 11\n7 52\n2 7\n65 2\n33 65\n17 33\n21 17\n9 21\n24 9\n3 24\n48 3\n14 48\n13 14\n20 13\n43 20\n64 43\n58 64\n63 58\n19 63\n15 19\n60 15\n28 60\n51 28\n16 51\n31 16\n37 31\n53 37\n40 53\n36 40\n56 36\n55 56\n66 55\n67 66\n46 67\n32 46", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n755808947\n511617885\n23235761\n46471522\n92943044\n185886088\n371772176\n743544352\n487088695\n974177390\n948354771\n896709533\n793419057\n586838105\n173676201\n347352402\n694704804\n389409599\n778819198\n..." }, { "input": "55 54\n51 20\n55 51\n32 55\n25 32\n42 25\n19 42\n49 19\n50 49\n1 50\n8 1\n24 8\n39 24\n14 39\n46 14\n43 46\n5 43\n53 5\n17 53\n16 17\n13 16\n54 13\n44 54\n6 44\n38 6\n10 38\n11 10\n23 11\n7 23\n15 7\n52 15\n35 52\n33 35\n12 33\n22 12\n9 22\n30 9\n37 30\n36 37\n4 36\n34 4\n45 34\n31 45\n26 31\n40 26\n41 40\n2 41\n18 2\n27 18\n28 27\n48 28\n29 48\n21 29\n47 21\n3 47", "output": "1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n73741815\n147483630\n294967260\n589934520\n179869031\n359738062\n719476124\n438952239\n877904478\n755808947\n511617885\n23235761\n46471522\n92943044\n185886088\n371772176\n743544352\n487088695\n974177390\n948354771\n896709533\n793419057\n586838105\n173676201\n347352402\n347352402" }, { "input": "65 65\n22 45\n29 22\n10 29\n30 10\n28 30\n33 28\n37 33\n21 37\n12 21\n61 12\n60 61\n48 60\n26 48\n6 26\n54 6\n11 54\n5 11\n18 5\n25 18\n53 25\n51 53\n2 51\n47 2\n3 47\n24 3\n42 24\n55 42\n35 55\n1 35\n56 1\n39 56\n49 39\n52 49\n44 52\n13 44\n17 13\n16 17\n31 16\n32 31\n58 32\n46 58\n38 46\n34 38\n43 34\n40 43\n23 40\n64 23\n57 64\n36 57\n20 36\n63 20\n59 63\n65 59\n14 65\n15 14\n8 15\n27 8\n41 27\n62 41\n19 62\n7 19\n9 7\n4 45\n50 45\n50 4", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0" }, { "input": "18 18\n1 15\n17 15\n6 15\n8 6\n18 17\n16 8\n2 17\n3 8\n5 8\n4 2\n14 1\n12 2\n7 1\n13 3\n9 1\n11 15\n10 15\n10 11", "output": "1\n9\n73\n530\n3422\n19540\n98322\n436002\n1711584\n5977440\n18536112\n50572368\n119617344\n235243008\n363242880\n363242880\n0\n0\n0" }, { "input": "31 30\n26 4\n10 4\n25 26\n22 4\n5 25\n1 22\n30 25\n27 4\n17 10\n23 1\n3 23\n16 17\n18 22\n6 1\n9 26\n28 1\n29 16\n24 5\n11 16\n19 24\n31 4\n7 25\n21 11\n15 3\n12 15\n8 7\n13 16\n14 29\n2 1\n20 10", "output": "1\n15\n215\n2942\n38393\n477250\n5643140\n63369445\n674570290\n793077276\n566127314\n774493757\n724076274\n193911614\n448938849\n991892401\n284241326\n314349704\n707657555\n444495354\n392327600\n369751381\n217331280\n437641678\n458894187\n95316270\n867327254\n939454921\n738820706\n477641403\n955282806\n955282806" }, { "input": "55 54\n20 52\n22 52\n27 52\n24 52\n43 52\n48 52\n36 52\n46 52\n53 52\n17 52\n41 52\n51 52\n37 52\n38 52\n40 52\n35 52\n55 52\n4 52\n42 52\n21 52\n39 52\n44 52\n15 52\n25 52\n28 52\n19 52\n54 52\n12 52\n14 52\n34 52\n9 52\n31 52\n50 52\n13 52\n49 52\n18 52\n29 52\n30 52\n16 52\n6 52\n3 52\n5 52\n47 52\n2 52\n10 52\n23 52\n32 52\n26 52\n7 52\n1 52\n33 52\n45 52\n8 52\n11 52", "output": "1\n54\n2862\n148824\n7590024\n379501200\n595558638\n586814372\n580275241\n692660852\n169738061\n468474621\n144408523\n65157912\n671474374\n858974726\n500014017\n532475\n19701575\n709256700\n823984284\n15465404\n510358332\n331466480\n275460790\n263823628\n650885149\n224784010\n69168216\n798373607\n959340004\n24159889\n555677447\n224903726\n722978210\n459564074\n731717334\n170911895\n905502197\n488035026\n320525327\n487354542\n335608992\n27307868\n300386548\n3865453\n34789077\n278312616\n948188303\n689129773..." }, { "input": "3 2\n3 2\n1 2", "output": "1\n2\n4\n4" }, { "input": "32 31\n5 30\n29 30\n21 30\n17 30\n24 30\n12 30\n2 30\n20 30\n19 30\n3 30\n13 30\n16 30\n26 30\n15 30\n11 30\n1 30\n8 30\n9 30\n18 30\n14 30\n28 30\n10 30\n4 30\n31 30\n23 30\n27 30\n32 30\n22 30\n25 30\n6 30\n7 30", "output": "1\n31\n930\n26970\n755160\n20389320\n530122320\n253057883\n73389138\n687950165\n134903495\n832973377\n659467396\n529880416\n537847407\n143405838\n294493390\n417400814\n843611351\n966947473\n603369577\n637065293\n370652876\n335875857\n687006838\n809047830\n854286944\n271434684\n85738727\n257216181\n514432362\n28864715\n28864715" }, { "input": "51 51\n47 42\n36 42\n22 42\n19 22\n33 47\n32 47\n23 22\n40 22\n16 40\n49 40\n10 16\n2 40\n51 2\n12 16\n17 2\n48 51\n13 48\n20 12\n5 17\n26 48\n38 48\n50 38\n14 50\n11 50\n6 11\n44 38\n24 6\n28 44\n18 28\n37 24\n46 37\n25 18\n39 37\n31 46\n30 39\n7 30\n41 31\n8 30\n21 31\n1 7\n3 7\n27 41\n35 8\n15 3\n45 35\n34 35\n43 34\n29 15\n9 42\n4 42\n4 9", "output": "1\n19\n348\n6142\n104420\n1709415\n26937580\n408494940\n959571531\n625735279\n414720144\n139482523\n324919873\n451723534\n17139509\n412011044\n767710164\n494287451\n997195961\n534543812\n127250510\n429319674\n638780430\n41794649\n336581900\n793883501\n520202276\n394485319\n281545317\n285697654\n412819512\n49791506\n911942868\n180776304\n855478164\n545059033\n991677358\n202031887\n871580844\n985301168\n862820490\n148074236\n811438573\n879222703\n96102798\n663048087\n692939551\n304415801\n304415801\n0\n0\n0\n..." } ]
15
0
0
7,300
248
Chilly Willy
[ "math", "number theory" ]
null
null
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneously divisible by all numbers Willy already knows (2, 3, 5 and 7). Help him with that. A number's length is the number of digits in its decimal representation without leading zeros.
A single input line contains a single integer *n* (1<=≀<=*n*<=≀<=105).
Print a single integer β€” the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
[ "1\n", "5\n" ]
[ "-1\n", "10080" ]
none
[ { "input": "1", "output": "-1" }, { "input": "5", "output": "10080" }, { "input": "6", "output": "100170" }, { "input": "4", "output": "1050" }, { "input": "15", "output": "100000000000110" }, { "input": "16", "output": "1000000000000050" }, { "input": "17", "output": "10000000000000080" }, { "input": "7", "output": "1000020" }, { "input": "120", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000170" }, { "input": "8", "output": "10000200" }, { "input": "3", "output": "210" }, { "input": "2", "output": "-1" }, { "input": "9", "output": "100000110" }, { "input": "10", "output": "1000000050" }, { "input": "11", "output": "10000000080" }, { "input": "12", "output": "100000000170" }, { "input": "13", "output": "1000000000020" }, { "input": "14", "output": "10000000000200" }, { "input": "100000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99998", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99997", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99996", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99995", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99994", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99993", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99992", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99991", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99990", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99989", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99988", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99987", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99988", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99987", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99986", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "10000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "5000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "5001", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "5002", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "121", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020" }, { "input": "122", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200" }, { "input": "123", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110" }, { "input": "18", "output": "100000000000000170" }, { "input": "19", "output": "1000000000000000020" }, { "input": "20", "output": "10000000000000000200" }, { "input": "21", "output": "100000000000000000110" }, { "input": "22", "output": "1000000000000000000050" }, { "input": "23", "output": "10000000000000000000080" }, { "input": "24", "output": "100000000000000000000170" }, { "input": "25", "output": "1000000000000000000000020" }, { "input": "31", "output": "1000000000000000000000000000020" }, { "input": "33", "output": "100000000000000000000000000000110" }, { "input": "65", "output": "10000000000000000000000000000000000000000000000000000000000000080" }, { "input": "2345", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "5522", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "8824", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "9003", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "88888", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "77777", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "66666", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "55553", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "34532", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "27324", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "45332", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "12398", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." } ]
122
0
0
7,312
656
Without Text
[ "*special" ]
null
null
You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png)
The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".".
Output the required answer.
[ "Codeforces\n", "APRIL.1st\n" ]
[ "-87\n", "17\n" ]
none
[ { "input": "Codeforces", "output": "-87" }, { "input": "APRIL.1st", "output": "17" }, { "input": ".0.1.2.", "output": "0" }, { "input": "CODEcode", "output": "0" }, { "input": "A", "output": "1" }, { "input": "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", "output": "1300" }, { "input": ".5i7kqPokKqEsLMn8ib", "output": "-67" }, { "input": "Bgh", "output": "-13" }, { "input": "LHg25JHfDf74yUj2rezrsTGBzsVZKyFMikyesiW", "output": "-95" }, { "input": "XugVHXi3RqJWXaP9i6g.0fP", "output": "108" }, { "input": "vTUvjiXvQbCUrJ5tbAblMtPZ6r8RVFFXrV6CL", "output": "88" }, { "input": "uVVcZsrSe", "output": "23" }, { "input": "rXVKP0A.qQnv9ATzvUxSz.eMD6ZoIIvb", "output": "0" }, { "input": "sVmF.LOJCNrkn2iupiiou", "output": "-93" }, { "input": "rXoypUjrOofxvzuSUrNfhxn490ZBwQZ0mMHYFlY4DCNQW", "output": "-11" }, { "input": "oZndfd2PbCT85u6081", "output": "-1" }, { "input": "K1mOToYzavp3Kaeacv", "output": "-43" }, { "input": "K3n5JwuWoJdFUVq8H5QldFqDD2B9yCUDFY1TTMN10", "output": "118" }, { "input": "J5pm96D11kPTf", "output": "4" }, { "input": "G7pT.FXaC9ChoODEaRkTGL41NIcXmG9FiiS", "output": "137" }, { "input": "G45OZakwa5JVOES9UdXq9Edpj", "output": "82" }, { "input": "F646Pj3RlX5iZ9ei8oCh.IDjGCcvPQofAPCpNRwkBa6uido8w", "output": "-44" }, { "input": "D86oFsPzzwtuj5oEoxrYo", "output": "-191" }, { "input": "D5LkqCdKJsy", "output": "-36" }, { "input": "C7NRgNxtXJlwSuEhNJHkWH0LmEpUwcKbs", "output": "17" }, { "input": "B9O9WWF", "output": "69" }, { "input": "M1TEc65C1h", "output": "30" }, { "input": "L3TuSHPiE7oQPhOnQlHZhsknMEO5.2.R", "output": "99" }, { "input": "L5VbIQ", "output": "58" }, { "input": "I9WJ8Z4neyQpjakuk6bIJyzbWVnT", "output": "-14" }, { "input": "I6lEiuI6zuUfJQ0peI", "output": "-36" }, { "input": "H8nxY2bfCKIrUMANJT2V1v7JPOnoQGMuk7SZp.oS", "output": "121" }, { "input": "FApeOAvCPk64", "output": "-12" }, { "input": "F7", "output": "6" }, { "input": "E94HphU3y4z6Q3nMYz8YYuvvtR", "output": "-43" }, { "input": "DB6zepob9WnHY0zvC8nPOzVpSYDZsTgLfzdvj4L8DrRPCdHS", "output": "6" }, { "input": "O", "output": "15" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "-1300" }, { "input": "kKKKKKkkkkkKKKKKkkkKKKKKkkkkkkkkkkkKKKKKkkkkkKKKKK", "output": "0" } ]
156
0
3
7,321
468
Two Sets
[ "2-sat", "dfs and similar", "dsu", "graph matchings", "greedy" ]
null
null
Little X has *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n*. He wants to divide all of them into two sets *A* and *B*. The following two conditions must be satisfied: - If number *x* belongs to set *A*, then number *a*<=-<=*x* must also belong to set *A*. - If number *x* belongs to set *B*, then number *b*<=-<=*x* must also belong to set *B*. Help Little X divide the numbers into two sets or determine that it's impossible.
The first line contains three space-separated integers *n*,<=*a*,<=*b* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*a*,<=*b*<=≀<=109). The next line contains *n* space-separated distinct integers *p*1,<=*p*2,<=...,<=*p**n*Β (1<=≀<=*p**i*<=≀<=109).
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print *n* integers: *b*1,<=*b*2,<=...,<=*b**n* (*b**i* equals either 0, or 1), describing the division. If *b**i* equals to 0, then *p**i* belongs to set *A*, otherwise it belongs to set *B*. If it's impossible, print "NO" (without the quotes).
[ "4 5 9\n2 3 4 5\n", "3 3 4\n1 2 4\n" ]
[ "YES\n0 0 1 1\n", "NO\n" ]
It's OK if all the numbers are in the same set, and the other one is empty.
[ { "input": "4 5 9\n2 3 4 5", "output": "YES\n0 0 1 1" }, { "input": "3 3 4\n1 2 4", "output": "NO" }, { "input": "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 2420 3361 3035 956 2539 1056 1837 477 1894 1762 1835 3577 2730 950 2960 1004 3293 2401 1271 2388 3950 1908 2804 2011 4952 3075 2507 2992 1883 1591 1095 959 1611 4749 3717 2245 207 814 4862 3525 2371 3277 817 701 574 2964 1278 705 1397 415 2892", "output": "NO" }, { "input": "53 7311 233\n163 70 172 6330 5670 33 59 7 3432 199 197 3879 145 226 117 26 116 98 981 6054 114 48 36 135 174 185 7249 192 150 11 65 83 62 61 88 7291 222 41 1257 20 6551 119 34 7246 6830 200 760 207 1641 97 118 115 481", "output": "NO" }, { "input": "70 416035 416023\n70034 70322 345689 345965 345701 70046 345737 345713 70166 345821 70010 345749 345677 345725 69962 345869 70178 70310 345785 69998 70070 69974 70058 346001 70106 345953 70226 70154 345929 69950 70298 346049 70346 345989 70286 69986 345893 70082 70238 345797 70250 345833 70334 345845 70094 70118 70202 345977 70262 70274 70190 345941 346025 345761 345773 70142 70022 70130 345881 345917 70358 345905 345665 346013 346061 345809 345857 346037 346073 70214", "output": "YES\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" }, { "input": "1 2 2\n1", "output": "YES\n0" }, { "input": "1 2 3\n1", "output": "YES\n0" }, { "input": "2 2 3\n1 2", "output": "YES\n1 1" }, { "input": "1 527802320 589732288\n418859112", "output": "NO" }, { "input": "1 1 1\n1", "output": "NO" }, { "input": "4 10 9\n6 5 4 3", "output": "YES\n1 1 1 1" }, { "input": "8 12 13\n2 10 3 9 4 8 5 7", "output": "YES\n0 0 0 0 0 0 0 0" }, { "input": "4 7 9\n2 4 5 7", "output": "YES\n1 1 1 1" }, { "input": "3 6 8\n3 5 1", "output": "YES\n0 0 0" } ]
140
409,600
0
7,325
25
Test
[ "hashing", "strings" ]
E. Test
2
256
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings β€” input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop if the input data contains the substring *s*2, and the third requires too much memory if the input data contains the substring *s*3. Bob wants these solutions to fail single test. What is the minimal length of test, which couldn't be passed by all three Bob's solutions?
There are exactly 3 lines in the input data. The *i*-th line contains string *s**i*. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.
Output one number β€” what is minimal length of the string, containing *s*1, *s*2 and *s*3 as substrings.
[ "ab\nbc\ncd\n", "abacaba\nabaaba\nx\n" ]
[ "4\n", "11\n" ]
none
[ { "input": "ab\nbc\ncd", "output": "4" }, { "input": "abacaba\nabaaba\nx", "output": "11" }, { "input": "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls", "output": "100" }, { "input": "jwdezvgfm\nmdoqvylpuvyk\nqylldbziva", "output": "30" }, { "input": "ujgquqxdlowuwnqkmbd\nwdwkhkdgsujgqu\njlxqvcuivagmw", "output": "40" }, { "input": "rdtevvmiqmfgvafkdypxjthzhfsbavmhgkavkfonscaokdxoscenpxrc\nijbvueenzsmgkmkrskjspvfchwkqdglkxnrdtevvmiqmfgvafkdypxjthz\nkqdglkxnrdtevvmiqmfgvafkdypxjthzhfsbavmhgkavkfonscaokdxoscenpxrcivydtkrxjy", "output": "100" }, { "input": "xufuzdlsjxmevrtessfbwlnzzclcqwevnnucxyvhngnxhcbdfwq\nwlwobhnmmgtfolfaeckbrnnglylydxtgtvrlmeeszoiuatzzzxufuzdlsjxmevrt\nbrnnglylydxtgtvrlmeeszoiuatzzzx", "output": "100" }, { "input": "iefouqzxoyuieqdzalfktehtvdbvjmeubju\nocotspetkkhvwfgaqynhovjwjhciefouqzxoyuieqdzalfktehtvdbvjmeubjubcmnvpwgdpnchqhzjrchyrfpvigubp\nycnhjwgbocotspetkkhvwfgaqynhovjwjhcief", "output": "100" } ]
30
0
0
7,326
745
Hongcow Solves A Puzzle
[ "implementation" ]
null
null
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified. The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap. You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.
The first line of input will contain two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=500), the dimensions of the puzzle piece. The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
[ "2 3\nXXX\nXXX\n", "2 2\n.X\nXX\n", "5 5\n.....\n..X..\n.....\n.....\n.....\n" ]
[ "YES\n", "NO\n", "YES\n" ]
For the first sample, one example of a rectangle we can form is as follows For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle. In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
[ { "input": "2 3\nXXX\nXXX", "output": "YES" }, { "input": "2 2\n.X\nXX", "output": "NO" }, { "input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.", "output": "YES" }, { "input": "10 1\n.\n.\n.\n.\nX\n.\n.\n.\n.\n.", "output": "YES" }, { "input": "8 5\nXX.XX\nX.XXX\nX.XXX\nXXX.X\nXX.XX\nXX..X\nXXX.X\nXXXX.", "output": "NO" }, { "input": "6 8\nXXXXXX..\nXXXXXXXX\n.X.X..X.\n.XXXX..X\nXX.XXXXX\nX...X..X", "output": "NO" }, { "input": "10 2\n.X\n.X\nXX\nXX\nX.\nXX\nX.\nX.\n..\n..", "output": "NO" }, { "input": "1 1\nX", "output": "YES" }, { "input": "3 3\nXXX\nX.X\nX..", "output": "NO" }, { "input": "3 3\nXX.\nXXX\n.XX", "output": "NO" }, { "input": "4 4\nXXXX\nXXXX\nXX..\nXX..", "output": "NO" }, { "input": "3 3\nX.X\nX.X\nXXX", "output": "NO" }, { "input": "3 2\nX.\nXX\n.X", "output": "NO" }, { "input": "2 1\nX\nX", "output": "YES" }, { "input": "1 2\nXX", "output": "YES" }, { "input": "2 3\n.XX\nXX.", "output": "NO" }, { "input": "5 5\nXXX..\n.XXX.\n..XXX\nXXX..\n.XXX.", "output": "NO" }, { "input": "2 4\nXX..\n.XX.", "output": "NO" }, { "input": "4 4\nXXX.\nXXX.\nX.X.\n..X.", "output": "NO" }, { "input": "2 3\nXX.\n.XX", "output": "NO" }, { "input": "3 5\nXXXX.\n.XXXX\nXXXX.", "output": "NO" }, { "input": "2 4\nXXX.\n.XXX", "output": "NO" }, { "input": "3 3\n...\n.X.\nXXX", "output": "NO" }, { "input": "3 3\n.X.\nXX.\nX..", "output": "NO" }, { "input": "3 4\nXXX.\nX.X.\nXXX.", "output": "NO" }, { "input": "4 4\n....\n....\n.XX.\n..X.", "output": "NO" }, { "input": "4 4\n....\n....\n.XXX\n..X.", "output": "NO" }, { "input": "2 6\nXXXXX.\nXXXXXX", "output": "NO" }, { "input": "3 3\nX.X\nXXX\n.X.", "output": "NO" }, { "input": "3 3\nXXX\nX.X\n..X", "output": "NO" }, { "input": "3 3\n.XX\nXX.\n.XX", "output": "NO" }, { "input": "3 8\n.XXXXXX.\nXXX..XXX\n.XXXXXX.", "output": "NO" }, { "input": "3 3\nXX.\n.XX\nXX.", "output": "NO" }, { "input": "3 3\n.XX\nXX.\nXX.", "output": "NO" }, { "input": "4 4\n....\nXXX.\nX.XX\nXXX.", "output": "NO" }, { "input": "2 2\nX.\nX.", "output": "YES" }, { "input": "2 5\n...XX\n..XX.", "output": "NO" }, { "input": "3 5\nXXX..\n.XXX.\n..XXX", "output": "NO" }, { "input": "2 6\n...XXX\n.XXX..", "output": "NO" }, { "input": "5 5\n.X.XX\n.XXX.\n.XXX.\n.XXX.\n.XXX.", "output": "NO" }, { "input": "4 4\n....\n.XXX\n..X.\n.XX.", "output": "NO" }, { "input": "2 4\n..XX\n.XX.", "output": "NO" }, { "input": "3 6\nXXX...\n.XXX..\n..XXX.", "output": "NO" }, { "input": "3 4\n.XXX\nXXX.\n.XXX", "output": "NO" } ]
420
614,400
3
7,330
584
Dima and Lisa
[ "brute force", "math", "number theory" ]
null
null
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≀<=*i*<=≀<=*k*), such that 1. 1<=≀<=*k*<=≀<=31. *p**i* is a prime1. The numbers *p**i* do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
The single line contains an odd number *n* (3<=≀<=*n*<=&lt;<=109).
In the first line print *k* (1<=≀<=*k*<=≀<=3), showing how many numbers are in the representation you found. In the second line print numbers *p**i* in any order. If there are multiple possible solutions, you can print any of them.
[ "27\n" ]
[ "3\n5 11 11\n" ]
A prime is an integer strictly larger than one that is divisible only by one and by itself.
[ { "input": "27", "output": "3\n2 2 23" }, { "input": "3", "output": "1\n3" }, { "input": "25", "output": "2\n2 23" }, { "input": "9", "output": "2\n2 7" }, { "input": "91", "output": "2\n2 89" }, { "input": "57", "output": "3\n2 2 53" }, { "input": "31", "output": "1\n31" }, { "input": "555", "output": "3\n3 5 547" }, { "input": "700000001", "output": "1\n700000001" }, { "input": "5", "output": "1\n5" }, { "input": "7", "output": "1\n7" }, { "input": "11", "output": "1\n11" }, { "input": "13", "output": "1\n13" }, { "input": "15", "output": "2\n2 13" }, { "input": "17", "output": "1\n17" }, { "input": "19", "output": "1\n19" }, { "input": "21", "output": "2\n2 19" }, { "input": "23", "output": "1\n23" }, { "input": "29", "output": "1\n29" }, { "input": "79", "output": "1\n79" }, { "input": "99", "output": "2\n2 97" }, { "input": "27", "output": "3\n2 2 23" }, { "input": "55", "output": "2\n2 53" }, { "input": "79", "output": "1\n79" }, { "input": "585", "output": "3\n3 5 577" }, { "input": "245", "output": "3\n2 2 241" }, { "input": "793", "output": "3\n3 3 787" }, { "input": "133", "output": "2\n2 131" }, { "input": "681", "output": "3\n2 2 677" }, { "input": "981399", "output": "2\n2 981397" }, { "input": "867773", "output": "1\n867773" }, { "input": "654141", "output": "3\n3 11 654127" }, { "input": "202985", "output": "3\n2 2 202981" }, { "input": "784533", "output": "3\n3 17 784513" }, { "input": "370359", "output": "3\n19 79 370261" }, { "input": "396831", "output": "3\n19 79 396733" }, { "input": "492211", "output": "3\n19 79 492113" }, { "input": "838347", "output": "3\n19 79 838249" }, { "input": "1098945", "output": "3\n19 79 1098847" }, { "input": "1313565", "output": "3\n19 79 1313467" }, { "input": "1349631", "output": "3\n19 79 1349533" }, { "input": "1357299", "output": "3\n19 79 1357201" }, { "input": "1357323", "output": "3\n13 109 1357201" }, { "input": "1357329", "output": "3\n19 109 1357201" }, { "input": "1388581", "output": "3\n19 79 1388483" }, { "input": "5275", "output": "2\n2 5273" }, { "input": "9515", "output": "3\n2 2 9511" }, { "input": "7847", "output": "3\n3 3 7841" }, { "input": "7077", "output": "3\n3 5 7069" }, { "input": "9531", "output": "3\n3 7 9521" }, { "input": "7865", "output": "3\n5 7 7853" }, { "input": "9675", "output": "3\n3 11 9661" }, { "input": "8909", "output": "3\n3 13 8893" }, { "input": "7147", "output": "3\n5 13 7129" }, { "input": "8487", "output": "3\n3 17 8467" }, { "input": "436273289", "output": "3\n3 277 436273009" }, { "input": "649580445", "output": "3\n3 271 649580171" }, { "input": "944193065", "output": "3\n7 251 944192807" }, { "input": "630045387", "output": "3\n11 239 630045137" }, { "input": "931103229", "output": "3\n3 223 931103003" }, { "input": "950664039", "output": "3\n3 197 950663839" }, { "input": "996104777", "output": "3\n7 173 996104597" }, { "input": "997255617", "output": "3\n7 157 997255453" }, { "input": "999962901", "output": "3\n19 109 999962773" }, { "input": "999995529", "output": "3\n19 79 999995431" }, { "input": "999995339", "output": "3\n5 43 999995291" }, { "input": "999998367", "output": "3\n5 23 999998339" }, { "input": "999999891", "output": "3\n3 5 999999883" }, { "input": "999999935", "output": "3\n3 3 999999929" }, { "input": "999999755", "output": "3\n2 2 999999751" }, { "input": "999999759", "output": "2\n2 999999757" }, { "input": "999999191", "output": "1\n999999191" }, { "input": "999999999", "output": "3\n3 59 999999937" }, { "input": "409449117", "output": "3\n2 2 409449113" }, { "input": "882499837", "output": "3\n3 3 882499831" }, { "input": "765615965", "output": "3\n5 23 765615937" }, { "input": "648732093", "output": "3\n3 11 648732079" }, { "input": "826815517", "output": "3\n3 11 826815503" }, { "input": "4898941", "output": "2\n2 4898939" }, { "input": "182982365", "output": "3\n5 13 182982347" }, { "input": "66098493", "output": "3\n3 41 66098449" }, { "input": "539149213", "output": "1\n539149213" }, { "input": "655957385", "output": "3\n3 13 655957369" }, { "input": "199999581", "output": "3\n19 79 199999483" }, { "input": "199998345", "output": "3\n19 79 199998247" }, { "input": "199991935", "output": "3\n19 79 199991837" }, { "input": "199986207", "output": "3\n19 79 199986109" }, { "input": "499991589", "output": "3\n19 79 499991491" }, { "input": "499984689", "output": "3\n19 79 499984591" }, { "input": "499984159", "output": "3\n19 79 499984061" }, { "input": "499966179", "output": "3\n19 79 499966081" }, { "input": "999995529", "output": "3\n19 79 999995431" }, { "input": "999995085", "output": "3\n19 79 999994987" }, { "input": "999991817", "output": "3\n11 137 999991669" }, { "input": "999991797", "output": "3\n19 109 999991669" }, { "input": "999991791", "output": "3\n13 109 999991669" }, { "input": "748859699", "output": "3\n3 3 748859693" }, { "input": "323845235", "output": "3\n3 3 323845229" }, { "input": "462409937", "output": "3\n2 2 462409933" }, { "input": "618047403", "output": "3\n3 13 618047387" }, { "input": "501148647", "output": "3\n2 2 501148643" }, { "input": "998017623", "output": "2\n2 998017621" }, { "input": "436273289", "output": "3\n3 277 436273009" }, { "input": "999999965", "output": "3\n5 23 999999937" }, { "input": "5", "output": "1\n5" }, { "input": "1000037", "output": "1\n1000037" }, { "input": "989898987", "output": "3\n2 2 989898983" }, { "input": "999999999", "output": "3\n3 59 999999937" }, { "input": "100000003", "output": "3\n3 11 99999989" } ]
124
4,096,000
3
7,332
678
The Same Calendar
[ "implementation" ]
null
null
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help Taylor to find that year. Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 ([https://en.wikipedia.org/wiki/Leap_year](https://en.wikipedia.org/wiki/Leap_year)).
The only line contains integer *y* (1000<=≀<=*y*<=&lt;<=100'000) β€” the year of the calendar.
Print the only integer *y*' β€” the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar.
[ "2016\n", "2000\n", "50501\n" ]
[ "2044\n", "2028\n", "50507\n" ]
Today is Monday, the 13th of June, 2016.
[ { "input": "2016", "output": "2044" }, { "input": "2000", "output": "2028" }, { "input": "50501", "output": "50507" }, { "input": "1000", "output": "1006" }, { "input": "1900", "output": "1906" }, { "input": "1899", "output": "1905" }, { "input": "99999", "output": "100010" }, { "input": "50000", "output": "50028" }, { "input": "99900", "output": "99906" }, { "input": "12345", "output": "12351" }, { "input": "1004", "output": "1032" }, { "input": "2100", "output": "2106" }, { "input": "1313", "output": "1319" }, { "input": "1872", "output": "1912" }, { "input": "2098", "output": "2110" }, { "input": "2072", "output": "2112" }, { "input": "2002", "output": "2013" }, { "input": "1179", "output": "1190" }, { "input": "2096", "output": "2108" }, { "input": "1096", "output": "1108" }, { "input": "1796", "output": "1808" }, { "input": "2014", "output": "2025" }, { "input": "2006", "output": "2017" }, { "input": "1874", "output": "1885" }, { "input": "1884", "output": "1924" }, { "input": "2342", "output": "2353" }, { "input": "2010", "output": "2021" }, { "input": "2097", "output": "2109" }, { "input": "1072", "output": "1112" }, { "input": "1191", "output": "1202" }, { "input": "2896", "output": "2908" }, { "input": "1797", "output": "1809" }, { "input": "1002", "output": "1013" }, { "input": "99988", "output": "100016" }, { "input": "1788", "output": "1828" }, { "input": "1994", "output": "2005" }, { "input": "5094", "output": "5100" }, { "input": "99996", "output": "100024" }, { "input": "3998", "output": "4009" }, { "input": "49376", "output": "49416" } ]
109
0
0
7,340
169
Replacing Digits
[ "greedy" ]
null
null
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≀<=*j*<=≀<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≀<=*i*<=≀<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation. Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*.
The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain leading zeroes.
Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes.
[ "1024\n010\n", "987\n1234567\n" ]
[ "1124\n", "987\n" ]
none
[ { "input": "1024\n010", "output": "1124" }, { "input": "987\n1234567", "output": "987" }, { "input": "10\n1", "output": "11" }, { "input": "11\n1", "output": "11" }, { "input": "12\n2", "output": "22" }, { "input": "1\n0", "output": "1" }, { "input": "123456\n9999", "output": "999956" }, { "input": "909090\n000111", "output": "919191" }, { "input": "588\n24", "output": "588" }, { "input": "25206\n88", "output": "88206" }, { "input": "9776247464\n8629", "output": "9986647464" }, { "input": "3666566898\n3001", "output": "3666566898" }, { "input": "3338860467\n5848", "output": "8858864467" }, { "input": "9768757689\n1010", "output": "9768757689" }, { "input": "6669490269\n6240849376", "output": "9879696469" }, { "input": "1794210278\n50931901955213461294", "output": "9999965578" }, { "input": "6997854871\n15113453341706470344", "output": "7997876875" }, { "input": "8947769539\n22900332144661023400", "output": "9967769649" }, { "input": "9885783638\n20241242140301231211", "output": "9885784648" }, { "input": "1\n2", "output": "2" }, { "input": "1\n1234567890", "output": "9" }, { "input": "123\n987987", "output": "998" }, { "input": "1000\n32119", "output": "9321" }, { "input": "31\n4", "output": "41" }, { "input": "504\n91111", "output": "914" }, { "input": "100001\n23", "output": "320001" }, { "input": "87\n9", "output": "97" }, { "input": "786796787566545376\n00101", "output": "786796787566545376" }, { "input": "123456789012345678905764345\n00001", "output": "123456789112345678905764345" }, { "input": "111\n2222222299999999", "output": "999" }, { "input": "111\n789", "output": "987" }, { "input": "1\n99", "output": "9" }, { "input": "1099\n9", "output": "9099" }, { "input": "123\n456", "output": "654" } ]
216
3,481,600
-1
7,353
985
Chess Placing
[ "implementation" ]
null
null
You are given a chessboard of size 1<=Γ—<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied. Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).
The first line of the input contains one integer *n* (2<=≀<=*n*<=≀<=100, *n* is even) β€” the size of the chessboard. The second line of the input contains integer numbers (1<=≀<=*p**i*<=≀<=*n*) β€” initial positions of the pieces. It is guaranteed that all the positions are distinct.
Print one integer β€” the minimum number of moves you have to make to place all the pieces in the cells of the same color.
[ "6\n1 2 6\n", "10\n1 2 3 4 5\n" ]
[ "2\n", "10\n" ]
In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3. In the second example the possible strategy is to move <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1e06f6a15cce30628c7a2360c4ffa57a8ba0ebd.png" style="max-width: 100.0%;max-height: 100.0%;"/> in 4 moves, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c84dfbe0c6a917b45fc3f69467c256c4ac460eeb.png" style="max-width: 100.0%;max-height: 100.0%;"/> in 3 moves, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/598731d81393332209d914cb0bbe97d8566c887d.png" style="max-width: 100.0%;max-height: 100.0%;"/> in 2 moves and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png" style="max-width: 100.0%;max-height: 100.0%;"/> in 1 move.
[ { "input": "6\n1 2 6", "output": "2" }, { "input": "10\n1 2 3 4 5", "output": "10" }, { "input": "2\n2", "output": "0" }, { "input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100", "output": "0" }, { "input": "100\n93 54 57 61 68 66 70 96 64 82 80 75 69 77 76 94 67 86 90 73 74 58 100 83 92 89 56 99 88 59 95 72 81 51 85 71 97 60 91 63 65 98 79 84 53 62 87 55 52 78", "output": "1225" }, { "input": "100\n41 13 29 11 25 15 6 23 28 50 48 17 3 9 44 24 5 19 34 22 33 32 20 16 35 37 4 10 46 2 39 40 47 49 36 42 1 30 43 21 14 7 18 45 31 8 12 26 27 38", "output": "1225" }, { "input": "96\n12 58 70 19 65 61 41 46 15 92 64 72 9 26 53 37 2 3 1 40 10 8 94 66 50 34 36 96 47 78 7 57 5 6 17 69 28 88 89 49 55 81 35 22 25 79 86 59", "output": "152" }, { "input": "10\n5 6 7 8 9", "output": "7" }, { "input": "20\n1 2 3 4 5 6 7 8 9 10", "output": "45" }, { "input": "10\n6 7 8 9 10", "output": "10" }, { "input": "10\n9 8 7 6 5", "output": "7" }, { "input": "6\n1 5 6", "output": "2" }, { "input": "12\n1 7 8 9 10 12", "output": "7" }, { "input": "6\n1 4 5", "output": "1" }, { "input": "24\n10 21 15 3 11 4 18 24 16 22 14 9", "output": "11" }, { "input": "20\n3 4 6 7 8 10 11 13 14 17", "output": "15" }, { "input": "10\n10 9 8 1 5", "output": "5" }, { "input": "100\n84 10 26 79 58 93 67 85 7 2 99 4 47 45 75 22 32 82 65 53 63 49 42 52 12 69 86 46 25 76 40 15 13 78 8 81 62 28 60 21 27 80 98 56 3 36 54 16 50 43", "output": "104" }, { "input": "10\n1 7 8 9 10", "output": "7" }, { "input": "10\n1 4 6 8 10", "output": "1" }, { "input": "80\n41 70 18 53 32 79 51 49 21 27 47 65 50 15 62 60 5 40 14 25 64 9 19 58 38 76 66 52 17 34 13 2 80 43 3 42 33 36 6 72", "output": "47" }, { "input": "50\n27 42 41 4 10 45 44 26 49 50 17 28 2 36 18 39 23 12 21 24 19 29 22 40 37", "output": "59" }, { "input": "10\n2 3 4 5 6", "output": "7" }, { "input": "6\n3 5 6", "output": "2" }, { "input": "100\n9 63 62 88 3 67 54 33 79 51 71 80 37 46 43 57 69 17 34 6 18 40 59 83 76 86 8 55 90 89 45 42 28 98 30 38 77 91 73 58 23 61 41 65 64 93 14 44 16 24", "output": "160" }, { "input": "10\n1 6 7 8 9", "output": "5" }, { "input": "6\n3 4 5", "output": "2" } ]
109
0
0
7,379
706
Vasiliy's Multiset
[ "binary search", "bitmasks", "data structures", "trees" ]
null
null
Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given *q* queries and a multiset *A*, initially containing only integer 0. There are three types of queries: 1. "+ x"Β β€” add integer *x* to multiset *A*.1. "- x"Β β€” erase one occurrence of integer *x* from multiset *A*. It's guaranteed that at least one *x* is present in the multiset *A* before this query.1. "? x"Β β€” you are given integer *x* and need to compute the value , i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer *x* and some integer *y* from the multiset *A*. Multiset is a set, where equal elements are allowed.
The first line of the input contains a single integer *q* (1<=≀<=*q*<=≀<=200<=000)Β β€” the number of queries Vasiliy has to perform. Each of the following *q* lines of the input contains one of three characters '+', '-' or '?' and an integer *x**i* (1<=≀<=*x**i*<=≀<=109). It's guaranteed that there is at least one query of the third type. Note, that the integer 0 will always be present in the set *A*.
For each query of the type '?' print one integerΒ β€” the maximum value of bitwise exclusive OR (XOR) of integer *x**i* and some integer from the multiset *A*.
[ "10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11\n" ]
[ "11\n10\n14\n13\n" ]
After first five operations multiset *A* contains integers 0, 8, 9, 11, 6 and 1. The answer for the sixth query is integer <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9e2f3d4f1a7c134a5695ba1d548df2b4f9292206.png" style="max-width: 100.0%;max-height: 100.0%;"/>Β β€” maximum among integers <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6cb1b5a0f9bbad177b1de700e918187c8fb3e972.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7644536d2010111824755b5dd2b6043340b2bf4d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9a437d1611f6c2ae5cd9a275a6ab2df61296988e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4e3eeab99fa495ecdcd103c68de47dd72943016f.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/97b73b0f3e59862ed9f80fa83527d97e0ed0a084.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11", "output": "11\n10\n14\n13" }, { "input": "12\n+ 4\n+ 4\n+ 5\n? 3\n- 4\n? 3\n- 4\n? 3\n? 3\n- 5\n+ 10\n? 1", "output": "7\n7\n6\n6\n11" }, { "input": "10\n? 1\n+ 1\n+ 8\n- 1\n+ 2\n+ 7\n+ 4\n+ 7\n+ 3\n? 7", "output": "1\n15" }, { "input": "7\n? 1\n+ 941492387\n+ 72235422\n+ 449924898\n+ 783332532\n- 941492387\n- 72235422", "output": "1" }, { "input": "3\n? 5\n? 4\n? 3", "output": "5\n4\n3" }, { "input": "1\n? 4", "output": "4" }, { "input": "14\n+ 4\n+ 4\n+ 4\n+ 4\n? 3\n- 4\n- 4\n- 4\n? 3\n+ 5\n? 3\n- 4\n+ 4\n? 3", "output": "7\n7\n7\n7" }, { "input": "12\n? 4\n+ 4\n? 4\n+ 4\n? 3\n- 4\n- 4\n? 3\n+ 4\n? 4\n+ 1\n+ 1", "output": "4\n4\n7\n3\n4" } ]
46
0
0
7,386
426
Sereja and Mugs
[ "implementation" ]
null
null
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost. As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (*n*<=-<=1) friends. Determine if Sereja's friends can play the game so that nobody loses.
The first line contains integers *n* and *s* (2<=≀<=*n*<=≀<=100;Β 1<=≀<=*s*<=≀<=1000) β€” the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=10). Number *a**i* means the volume of the *i*-th mug.
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
[ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
[ { "input": "3 4\n1 1 1", "output": "YES" }, { "input": "3 4\n3 1 3", "output": "YES" }, { "input": "3 4\n4 4 4", "output": "NO" }, { "input": "2 1\n1 10", "output": "YES" }, { "input": "3 12\n5 6 6", "output": "YES" }, { "input": "4 10\n6 3 8 7", "output": "NO" }, { "input": "5 16\n3 3 2 7 9", "output": "YES" }, { "input": "6 38\n9 10 3 8 10 6", "output": "YES" }, { "input": "7 12\n4 4 5 2 2 4 9", "output": "NO" }, { "input": "8 15\n8 10 4 2 10 9 7 6", "output": "NO" }, { "input": "9 22\n1 3 5 9 7 6 1 10 1", "output": "NO" }, { "input": "10 30\n9 10 4 5 5 7 1 7 7 2", "output": "NO" }, { "input": "38 83\n9 9 3 10 2 4 6 10 9 5 1 8 7 4 7 2 6 5 3 1 10 8 4 8 3 7 1 2 7 6 8 6 5 2 3 1 1 2", "output": "NO" }, { "input": "84 212\n6 2 3 1 2 7 5 1 7 2 9 10 9 5 2 5 4 10 9 9 1 9 8 8 9 4 9 4 8 2 1 8 4 5 10 7 6 2 1 10 10 7 9 4 5 9 5 10 10 3 6 6 4 4 4 8 5 4 9 1 9 9 1 7 9 2 10 9 10 8 3 3 9 3 9 10 1 8 9 2 6 9 7 2", "output": "NO" }, { "input": "8 50\n8 8 8 4 4 6 10 10", "output": "YES" }, { "input": "7 24\n1 4 9 1 2 3 6", "output": "YES" }, { "input": "47 262\n3 7 6 4 10 3 5 7 2 9 3 2 2 10 8 7 3 10 6 3 1 1 4 10 2 9 2 10 6 4 3 6 3 6 9 7 8 8 3 3 10 5 2 10 7 10 9", "output": "YES" }, { "input": "42 227\n3 6 1 9 4 10 4 10 7 8 10 10 8 7 10 4 6 8 7 7 6 9 3 6 5 5 2 7 2 7 4 4 6 6 4 3 9 3 6 4 7 2", "output": "NO" }, { "input": "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 1 4 5 1 1 6 4 2 1 7 8 6 1 1 5 6 5 10 6 7 5", "output": "NO" }, { "input": "94 279\n2 5 9 5 10 3 1 8 1 7 1 8 1 6 7 8 4 9 5 10 3 7 6 8 8 5 6 8 10 9 4 1 3 3 4 7 8 2 6 6 5 1 3 7 1 7 2 2 2 8 4 1 1 5 9 4 1 2 3 10 1 4 9 9 6 8 8 1 9 10 4 1 8 5 8 9 4 8 2 1 1 9 4 5 6 1 2 5 6 7 3 1 4 6", "output": "NO" }, { "input": "58 70\n8 2 10 2 7 3 8 3 8 7 6 2 4 10 10 6 10 3 7 6 4 3 5 5 5 3 8 10 3 4 8 4 2 6 8 9 6 9 4 3 5 2 2 6 10 6 2 1 7 5 6 4 1 9 10 2 4 5", "output": "NO" }, { "input": "6 14\n3 9 2 1 4 2", "output": "YES" }, { "input": "78 400\n5 9 3 4 7 4 1 4 6 3 9 1 8 3 3 6 10 2 1 9 6 1 8 10 1 6 4 5 2 1 5 9 6 10 3 6 5 2 4 10 6 9 3 8 10 7 2 8 8 2 10 1 4 5 2 8 6 4 4 3 5 2 3 10 1 9 8 5 6 7 9 1 8 8 5 4 2 4", "output": "YES" }, { "input": "41 181\n5 3 10 4 2 5 9 3 1 6 6 10 4 3 9 8 5 9 2 5 4 6 6 3 7 9 10 3 10 6 10 5 6 1 6 9 9 1 2 4 3", "output": "NO" }, { "input": "2 4\n4 4", "output": "YES" }, { "input": "29 71\n4 8 9 4 8 10 4 10 2 9 3 9 1 2 9 5 9 7 1 10 4 1 1 9 8 7 4 6 7", "output": "NO" }, { "input": "49 272\n4 10 8 7 5 6 9 7 2 6 6 2 10 7 5 6 5 3 6 4 3 7 9 3 7 7 4 10 5 6 7 3 6 4 6 7 7 2 5 5 7 3 7 9 3 6 6 2 1", "output": "YES" }, { "input": "91 486\n1 3 5 4 4 7 3 9 3 4 5 4 5 4 7 9 5 8 4 10 9 1 1 9 9 1 6 2 5 4 7 4 10 3 2 10 9 3 4 5 1 3 4 2 10 9 10 9 10 2 4 6 2 5 3 6 4 9 10 3 9 8 1 2 5 9 2 10 4 6 10 8 10 9 1 2 5 8 6 6 6 1 10 3 9 3 5 6 1 5 5", "output": "YES" }, { "input": "80 78\n1 9 4 9 8 3 7 10 4 9 2 1 4 4 9 5 9 1 2 6 5 2 4 8 4 6 9 6 7 10 1 9 10 4 7 1 7 10 8 9 10 5 2 6 7 7 7 7 7 8 2 5 1 7 2 3 2 5 10 6 3 4 5 2 6 3 4 2 7 9 9 3 8 8 2 3 7 1 5 10", "output": "NO" }, { "input": "53 245\n5 6 9 9 2 3 2 5 10 9 3 5 6 3 10 10 9 4 9 7 10 9 7 7 3 4 9 3 7 3 8 6 8 9 3 8 9 1 3 1 9 10 3 9 3 1 6 6 3 8 7 8 9", "output": "NO" }, { "input": "50 271\n6 9 10 1 1 1 8 3 6 6 3 2 5 9 7 5 7 9 10 9 4 6 6 2 6 6 9 5 1 6 5 8 3 2 5 10 10 1 4 1 4 6 1 8 7 8 9 4 7 5", "output": "YES" }, { "input": "38 214\n5 8 4 5 1 9 9 2 6 3 4 3 5 7 7 7 3 10 1 5 10 4 2 2 10 10 6 6 6 7 1 6 10 5 7 4 5 10", "output": "YES" }, { "input": "100 1\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 100\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 989\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 990\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "YES" }, { "input": "100 1000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "YES" }, { "input": "2 1\n1 1", "output": "YES" }, { "input": "2 1\n2 2", "output": "NO" }, { "input": "2 1000\n1 1", "output": "YES" }, { "input": "10 89\n10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "10 44\n1 10 2 3 4 5 6 7 8 9", "output": "NO" } ]
77
6,758,400
3
7,388
550
Divisibility by Eight
[ "brute force", "dp", "math" ]
null
null
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits. If a solution exists, you should print it.
The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
Print "NO" (without quotes), if there is no such way to remove some digits from number *n*. Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8. If there are multiple possible answers, you may print any of them.
[ "3454\n", "10\n", "111111\n" ]
[ "YES\n344\n", "YES\n0\n", "NO\n" ]
none
[ { "input": "3454", "output": "YES\n344" }, { "input": "10", "output": "YES\n0" }, { "input": "111111", "output": "NO" }, { "input": "8996988892", "output": "YES\n8" }, { "input": "5555555555", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188", "output": "YES\n8" }, { "input": "8", "output": "YES\n8" }, { "input": "14", "output": "NO" }, { "input": "2363", "output": "NO" }, { "input": "3554", "output": "NO" }, { "input": "312", "output": "YES\n32" }, { "input": "7674", "output": "YES\n64" }, { "input": "126", "output": "YES\n16" }, { "input": "344", "output": "YES\n344" }, { "input": "976", "output": "YES\n96" }, { "input": "3144", "output": "YES\n344" }, { "input": "1492", "output": "YES\n192" }, { "input": "1000", "output": "YES\n0" }, { "input": "303", "output": "YES\n0" }, { "input": "111111111111111111111171111111111111111111111111111112", "output": "YES\n72" }, { "input": "3111111111111111111111411111111111111111111141111111441", "output": "YES\n344" }, { "input": "7486897358699809313898215064443112428113331907121460549315254356705507612143346801724124391167293733", "output": "YES\n8" }, { "input": "1787075866", "output": "YES\n8" }, { "input": "836501278190105055089734832290981", "output": "YES\n8" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "NO" }, { "input": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222", "output": "NO" }, { "input": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", "output": "NO" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "YES\n0" }, { "input": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555", "output": "NO" }, { "input": "66666666666666666666666666666666666666666666666666666666666666666666666666666", "output": "NO" }, { "input": "88888888888888888888888888888888888888888888888888888888888888888888888888888888", "output": "YES\n8" }, { "input": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "NO" }, { "input": "353", "output": "NO" }, { "input": "39", "output": "NO" }, { "input": "3697519", "output": "NO" }, { "input": "6673177113", "output": "NO" }, { "input": "6666351371557713735", "output": "NO" }, { "input": "17943911115335733153157373517", "output": "NO" }, { "input": "619715515939999957957971971757533319177373", "output": "NO" }, { "input": "4655797151375799393395377959959573533195153397997597195199777159133", "output": "NO" }, { "input": "5531399953495399131957773999751571911139197159755793777773799119333593915333593153173775755771193715", "output": "NO" }, { "input": "1319571733331774579193199551977735199771153997797535591739153377377111795579371959933533573517995559", "output": "NO" }, { "input": "3313393139519343957311771319713797711159791515393917539133957799131393735795317131513557337319131993", "output": "NO" }, { "input": "526", "output": "YES\n56" }, { "input": "513", "output": "NO" }, { "input": "674", "output": "YES\n64" }, { "input": "8353", "output": "YES\n8" }, { "input": "3957", "output": "NO" }, { "input": "4426155776626276881222352363321488266188669874572115686737742545442766138617391954346963915982759371", "output": "YES\n8" }, { "input": "9592419524227735697379444145348135927975358347769514686865768941989693174565893724972575152874281772", "output": "YES\n8" }, { "input": "94552498866729239313265973246288189853135485783461", "output": "YES\n8" }, { "input": "647934465937812", "output": "YES\n8" }, { "input": "1327917795375366484539554526312125336", "output": "YES\n8" }, { "input": "295971811535848297878828225646878276486982655866912496735794542", "output": "YES\n8" }, { "input": "7217495392264549817889283233368819844137671271383133997418139697797385729777632527678136", "output": "YES\n8" }, { "input": "11111111111111111111112111111111", "output": "YES\n112" }, { "input": "262626262626262626262626262626262626", "output": "NO" }, { "input": "1000000000000000000000000000000000000", "output": "YES\n0" }, { "input": "9969929446", "output": "YES\n96" }, { "input": "43523522125549722432232256557771715456345544922144", "output": "YES\n32" }, { "input": "9344661521956564755454992376342544254667536539463277572111263273131199437332443253296774957", "output": "YES\n96" }, { "input": "1946374341357914632311595531429723377642197432217137651552992479954116463332543456759911377223599715", "output": "YES\n16" }, { "input": "461259", "output": "NO" }, { "input": "461592", "output": "YES\n152" }, { "input": "46159237", "output": "YES\n152" }, { "input": "42367", "output": "NO" }, { "input": "42376", "output": "YES\n376" }, { "input": "42376159", "output": "YES\n376" }, { "input": "444444444444444444444444444444666666666666666666666666666666222222222222222222222222222222", "output": "NO" }, { "input": "0", "output": "YES\n0" }, { "input": "33332", "output": "YES\n32" }, { "input": "6499999999", "output": "YES\n64" } ]
46
0
0
7,401
610
Harmony Analysis
[ "constructive algorithms" ]
null
null
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or <=-<=1 and any two vectors are orthogonal. Just as a reminder, two vectors in *n*-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is: Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2*k* vectors in 2*k*-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?
The only line of the input contains a single integer *k* (0<=≀<=*k*<=≀<=9).
Print 2*k* lines consisting of 2*k* characters each. The *j*-th character of the *i*-th line must be equal to '<=*<=' if the *j*-th coordinate of the *i*-th vector is equal to <=-<=1, and must be equal to '<=+<=' if it's equal to <=+<=1. It's guaranteed that the answer always exists. If there are many correct answers, print any.
[ "2\n" ]
[ "++**\n+*+*\n++++\n+**+" ]
Consider all scalar products in example: - Vectors 1 and 2: ( + 1)Β·( + 1) + ( + 1)Β·( - 1) + ( - 1)Β·( + 1) + ( - 1)Β·( - 1) = 0 - Vectors 1 and 3: ( + 1)Β·( + 1) + ( + 1)Β·( + 1) + ( - 1)Β·( + 1) + ( - 1)Β·( + 1) = 0 - Vectors 1 and 4: ( + 1)Β·( + 1) + ( + 1)Β·( - 1) + ( - 1)Β·( - 1) + ( - 1)Β·( + 1) = 0 - Vectors 2 and 3: ( + 1)Β·( + 1) + ( - 1)Β·( + 1) + ( + 1)Β·( + 1) + ( - 1)Β·( + 1) = 0 - Vectors 2 and 4: ( + 1)Β·( + 1) + ( - 1)Β·( - 1) + ( + 1)Β·( - 1) + ( - 1)Β·( + 1) = 0 - Vectors 3 and 4: ( + 1)Β·( + 1) + ( + 1)Β·( - 1) + ( + 1)Β·( - 1) + ( + 1)Β·( + 1) = 0
[ { "input": "2", "output": "++++\n+*+*\n++**\n+**+" }, { "input": "1", "output": "++\n+*" }, { "input": "3", "output": "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*" }, { "input": "0", "output": "+" }, { "input": "4", "output": "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n++****++++****++\n+**+*++*+**+*++*\n++++++++********\n+*+*+*+**+*+*+*+\n++**++****++**++\n+**++**+*++**++*\n++++********++++\n+*+**+*+*+*++*+*\n++****++**++++**\n+**+*++**++*+**+" }, { "input": "5", "output": "++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**+\n++++****++++****++++****++++****\n+*+**+*++*+**+*++*+**+*++*+**+*+\n++****++++****++++****++++****++\n+**+*++*+**+*++*+**+*++*+**+*++*\n++++++++********++++++++********\n+*+*+*+**+*+*+*++*+*+*+**+*+*+*+\n++**++****++**++++**++****++**++\n+**++**+*++**++*+**++**+*++**++*\n++++********++++++++********++++\n+*+**+*+*+*++*+*+*+**+*+*+*++*+*\n++****++**++++**++****++**++++**\n+..." }, { "input": "6", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**+\n++++****++++****++++****++++****++++****++++****++++****++++****\n+*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*+\n++****++++****++++****++++****++++****++++****++++****++++****++\n+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+**+*++*+..." }, { "input": "7", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*\n++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**\n+**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++**++..." }, { "input": "8", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+..." }, { "input": "9", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..." } ]
30
0
0
7,404
883
Field of Wonders
[ "implementation", "strings" ]
null
null
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1). Polycarpus knows *m* words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these *m* words. At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed. It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed. Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
The first line contains one integer *n* (1<=≀<=*n*<=≀<=50) β€” the length of the hidden word. The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed. The third line contains an integer *m* (1<=≀<=*m*<=≀<=1000) β€” the number of words of length *n*, which Polycarpus knows. The following *m* lines contain the words themselves β€” *n*-letter strings of lowercase Latin letters. All words are distinct. It is guaranteed that the hidden word appears as one of the given *m* words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output the single integer β€” the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
[ "4\na**d\n2\nabcd\nacbd\n", "5\nlo*er\n2\nlover\nloser\n", "3\na*a\n2\naaa\naba\n" ]
[ "2\n", "0\n", "1\n" ]
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
[ { "input": "4\na**d\n2\nabcd\nacbd", "output": "2" }, { "input": "5\nlo*er\n2\nlover\nloser", "output": "0" }, { "input": "3\na*a\n2\naaa\naba", "output": "1" }, { "input": "1\n*\n1\na", "output": "1" }, { "input": "1\n*\n1\nz", "output": "1" }, { "input": "1\n*\n2\na\nz", "output": "0" }, { "input": "2\n**\n1\naa", "output": "1" }, { "input": "2\n**\n1\nfx", "output": "2" }, { "input": "2\n**\n2\nfx\nab", "output": "0" }, { "input": "2\n**\n2\nfx\naf", "output": "1" }, { "input": "2\na*\n2\naa\nab", "output": "1" }, { "input": "4\na*b*\n2\nabbc\nadbd", "output": "1" }, { "input": "4\na*b*\n3\nabbc\nadbd\nacbe", "output": "0" }, { "input": "4\na*b*\n3\nabbc\nadbd\nacbd", "output": "1" }, { "input": "3\n***\n2\naaa\nbbb", "output": "0" }, { "input": "3\n***\n2\naab\nabb", "output": "2" }, { "input": "3\n*a*\n4\naaa\ncac\naab\nbaa", "output": "1" }, { "input": "42\n*****o*******t********************oo******\n10\nvcrccobltkeidtxhsxhccaslkjhfyeqsetoowaemso\nuimjsoxifamvctkgqmrwhyjrgmlydczzqjoobnnwch\nuvmjsoqizfavctkxemrpaycngmlyemzzqjoobszwbh\nusmjsoviskzvctkljmrlmylugmlydfzzqvoobzawgh\nfeqweodinkhiatqmfokaxwcmlmbmvskssyookgcrax\ntackfosjhxeqftkgjynbbedrczegtimuvooosypczy\nxanuvoeismzmctruyplxgmfcpyrpqopyctoozlquvg\nurmjsouirdrvctkepmrwjyaxgmlyzvzzqcoobjgwih\nuymjsogivzivctkydmrgwyavgmlyphzzquoobclwhh\nkodyeoyihylgrtrdwudrsyonmuhtxaqklcoolsaclu", "output": "18" }, { "input": "50\n***********************************o**************\n5\nwrubnrgpqmduhgxtlxymsmcaiimivvypkkeouspglhzkfbpzcu\nfrubkrgplrduhgjuuxdmsgeaiimavvypkkeousulbhnkebpzcu\nwrubkrgpdrduhgfanxdmsufaiimgvvypkkeouwvsshikhbpzcu\nvhyfvnnobcguishyvuswkaxhkesgatuvbkyodxdrvlwwifiimd\nwrubwrgpvaduhgfnqxtmsjqaiimcvvypkkeouiqpyhckkbpzcu", "output": "20" }, { "input": "10\n**********\n10\nmvsthotcmi\nhmivtctsmo\nmmcostthiv\ntmomihtsvc\nmottsivmch\nhtomvcsmit\nsvhmotmcti\nmitotmvhcs\nvomcttmish\ncmostitvmh", "output": "8" }, { "input": "20\n********************\n1\nlaizpfbafxrugjcytfbs", "output": "16" }, { "input": "50\n**************************************************\n1\nqgaeytghzvvtgeitpovqozyclectzcohivbggudhiylaecbdzq", "output": "17" }, { "input": "50\n**************************************************\n2\nhvjbrfkhdaobruoptrrachzuvkxvvsckycfiroipqicoqvcqpr\nuirvabciccxdvpryroisvpoqvthrpurkzhoovcfqcjbhkarkqf", "output": "20" }, { "input": "26\n**************************\n10\nevfsnczuiodgbhqmlypkjatxrw\nuapqfdtoxkzynlbrehgwismvjc\nwjuyacngtzmvhqelikxoprdfbs\nyjgstlkvrhoqadxwfbiucpznem\nvebnxtrlocgkajqmwfuiszhypd\nroaqchwlpvtzxymnbkjigfedsu\noxmwaqpcendihzkutsybrjgfvl\nbnfzlwcsagxojdiyktqvruemhp\npdjahwnvmouxgqlciktzrfeysb\nbznurcyefxiapgktmqwjvsdloh", "output": "26" }, { "input": "26\n**************************\n1\nayvguplhjsoiencbkxdrfwmqtz", "output": "26" }, { "input": "26\n*lmnotuvwxyzjkabcdehiqfgrs\n2\nblmnotuvwxyzjkabcdehiqfgrs\nplmnotuvwxyzjkabcdehiqfgrs", "output": "1" }, { "input": "16\nx*d**s******xd*u\n22\nxfdeoshogyqjxdmu\nxvdvdsnwfwakxdyu\nxfdjoshftykjxdmu\nxfdcoshfwyajxdmu\nxfdfoshkmyajxdmu\nxfdyoshpoycjxdmu\nxmdhcswqnhxjxdtu\nxxdxwsoogqzwxdcu\nxxdhhsxqzciuxdfu\nxddcmswqzksqxdhu\nxfdtoshioyvjxdmu\nxsdxmsfmgjbyxdgu\nxadfssplfnlbxdru\nxndcasykmqmbxdru\nxrdxgszaisicxdlu\nxfdfoshhmypjxdmu\nxfdioshfiyhjxdmu\nxvdzysydlmyuxdnu\nxjdbqszgkuwhxdmu\nxfdfoshjyymjxdmu\nxgdjksubrmrfxdpu\nxkdshsfszixmxdcu", "output": "2" }, { "input": "3\n*vt\n2\ncvt\nqvb", "output": "1" }, { "input": "3\ntv*\n2\ntvc\nbvq", "output": "1" }, { "input": "41\n*z*hjcxxdgkny*tc*rmaov***fra**efs*lbi*puw\n1\nqzqhjcxxdgknyqtcqrmaovqqqfraqqefsqlbiqpuw", "output": "1" }, { "input": "48\n*h*i**ag**um**fuxvmxlj*dsyt*gb*dxkzp*brnelctkq*w\n1\nohoiooagooumoofuxvmxljodsytogbodxkzpobrnelctkqow", "output": "1" } ]
15
0
0
7,406
234
Practice
[ "constructive algorithms", "divide and conquer", "implementation" ]
null
null
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number β€” a unique integer from 1 to *n*. To prepare for the championship, the coach Mr. Floppe decided to spend some number of practices. Mr. Floppe spent some long nights of his holiday planning how to conduct the practices. He came to a very complex practice system. Each practice consists of one game, all *n* players of the team take part in the game. The players are sorted into two teams in some way. In this case, the teams may have different numbers of players, but each team must have at least one player. The coach wants to be sure that after the series of the practice sessions each pair of players had at least one practice, when they played in different teams. As the players' energy is limited, the coach wants to achieve the goal in the least number of practices. Help him to schedule the practices.
A single input line contains integer *n* (2<=≀<=*n*<=≀<=1000).
In the first line print *m* β€” the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in *m* lines. In the *i*-th of those lines print *f**i* β€” the number of players in the first team during the *i*-th practice (1<=≀<=*f**i*<=&lt;<=*n*), and *f**i* numbers from 1 to *n* β€” the numbers of players in the first team. The rest of the players will play in the second team during this practice. Separate numbers on a line with spaces. Print the numbers of the players in any order. If there are multiple optimal solutions, print any of them.
[ "2\n", "3\n" ]
[ "1\n1 1\n", "2\n2 1 2\n1 1\n" ]
none
[ { "input": "2", "output": "1\n1 1" }, { "input": "3", "output": "2\n2 1 2\n1 1" }, { "input": "4", "output": "2\n2 1 2\n2 1 3" }, { "input": "5", "output": "3\n3 1 2 3\n3 1 2 4\n1 1" }, { "input": "6", "output": "3\n3 1 2 3\n4 1 2 4 5\n2 1 4" }, { "input": "7", "output": "3\n4 1 2 3 4\n4 1 2 5 6\n3 1 3 5" }, { "input": "8", "output": "3\n4 1 2 3 4\n4 1 2 5 6\n4 1 3 5 7" }, { "input": "9", "output": "4\n5 1 2 3 4 5\n5 1 2 3 6 7\n5 1 2 4 6 8\n1 1" }, { "input": "10", "output": "4\n5 1 2 3 4 5\n6 1 2 3 6 7 8\n6 1 2 4 6 7 9\n2 1 6" }, { "input": "11", "output": "4\n6 1 2 3 4 5 6\n6 1 2 3 7 8 9\n7 1 2 4 5 7 8 10\n3 1 4 7" }, { "input": "13", "output": "4\n7 1 2 3 4 5 6 7\n7 1 2 3 4 8 9 10\n8 1 2 5 6 8 9 11 12\n5 1 3 5 8 11" }, { "input": "15", "output": "4\n8 1 2 3 4 5 6 7 8\n8 1 2 3 4 9 10 11 12\n8 1 2 5 6 9 10 13 14\n7 1 3 5 7 9 11 13" }, { "input": "16", "output": "4\n8 1 2 3 4 5 6 7 8\n8 1 2 3 4 9 10 11 12\n8 1 2 5 6 9 10 13 14\n8 1 3 5 7 9 11 13 15" }, { "input": "18", "output": "5\n9 1 2 3 4 5 6 7 8 9\n10 1 2 3 4 5 10 11 12 13 14\n10 1 2 3 6 7 10 11 12 15 16\n10 1 2 4 6 8 10 11 13 15 17\n2 1 10" }, { "input": "20", "output": "5\n10 1 2 3 4 5 6 7 8 9 10\n10 1 2 3 4 5 11 12 13 14 15\n12 1 2 3 6 7 8 11 12 13 16 17 18\n12 1 2 4 6 7 9 11 12 14 16 17 19\n4 1 6 11 16" }, { "input": "100", "output": "7\n50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\n50 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75\n52 1 2 3 4 5 6 7 8 9 10 11 12 13 26 27 28 29 30 31 32 33 34 35 36 37 38 51 52 53 54 55 56 57 58 59 60 61 62 63 76 77 78 79 80 81 82 83 84 85 86 87 88\n52 1 2 3 4 5 6 7 14 15 16 17 18 19 26 27 28 29 30 31 32 39 40 41 42..." }, { "input": "110", "output": "7\n55 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55\n56 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83\n56 1 2 3 4 5 6 7 8 9 10 11 12 13 14 29 30 31 32 33 34 35 36 37 38 39 40 41 42 56 57 58 59 60 61 62 63 64 65 66 67 68 69 84 85 86 87 88 89 90 91 92 93 94 95 96 97\n56 1 2 3 4 5 6 7 15 16..." }, { "input": "120", "output": "7\n60 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60\n60 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90\n60 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 91 92 93 94 95 96 97 98 99 10..." }, { "input": "140", "output": "8\n70 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70\n70 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105\n72 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50..." }, { "input": "157", "output": "8\n79 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79\n79 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118\n80 1 2 3 4 5 6 7 8 9 10 1..." }, { "input": "171", "output": "8\n86 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86\n86 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 1..." }, { "input": "199", "output": "8\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 11..." }, { "input": "200", "output": "8\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 11..." }, { "input": "213", "output": "8\n107 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107\n107 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 108 109 110 111 112 113 11..." }, { "input": "231", "output": "8\n116 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116\n116 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51..." }, { "input": "240", "output": "8\n120 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120\n120 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 4..." }, { "input": "250", "output": "8\n125 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125\n126 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..." }, { "input": "253", "output": "8\n127 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127\n127 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 ..." }, { "input": "260", "output": "9\n130 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130\n130 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 ..." }, { "input": "270", "output": "9\n135 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135\n136 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 2..." }, { "input": "271", "output": "9\n136 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136\n136 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ..." }, { "input": "277", "output": "9\n139 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139\n139 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ..." }, { "input": "280", "output": "9\n140 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140\n140 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19..." }, { "input": "290", "output": "9\n145 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145\n146 1 2 3 4 5 6 7 8 9 10 11 12 ..." }, { "input": "300", "output": "9\n150 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150\n150 1 2 3 4..." }, { "input": "700", "output": "10\n350 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "730", "output": "10\n365 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "766", "output": "10\n383 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "777", "output": "10\n389 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "800", "output": "10\n400 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "832", "output": "10\n416 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "855", "output": "10\n428 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "869", "output": "10\n435 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "888", "output": "10\n444 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "900", "output": "10\n450 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "914", "output": "10\n457 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "930", "output": "10\n465 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "950", "output": "10\n475 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "990", "output": "10\n495 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "1000", "output": "10\n500 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." } ]
248
3,276,800
3
7,447
0
none
[ "none" ]
null
null
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≀<=*a**i*<=≀<=109), the number of answer variants to question *i*.
Print a single number β€” the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "2999999999" }, { "input": "10\n5 7 8 1 10 3 6 4 10 6", "output": "294" }, { "input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8", "output": "24212" }, { "input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62", "output": "261115" }, { "input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644", "output": "2519223" }, { "input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950", "output": "24496504" }, { "input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899", "output": "685659563557" }, { "input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460", "output": "27409624352" }, { "input": "1\n84355694", "output": "84355694" }, { "input": "2\n885992042 510468669", "output": "1906929379" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1", "output": "2686" }, { "input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1", "output": "4667" } ]
124
4,710,400
3
7,450
895
Square Subsets
[ "bitmasks", "combinatorics", "dp", "math" ]
null
null
Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 109<=+<=7.
First line contains one integer *n* (1<=≀<=*n*<=≀<=105)Β β€” the number of elements in the array. Second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=70)Β β€” the elements of the array.
Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109<=+<=7.
[ "4\n1 1 1 1\n", "4\n2 2 2 2\n", "5\n1 2 4 5 8\n" ]
[ "15\n", "7\n", "7\n" ]
In first sample product of elements chosen by any way is 1 and 1 = 1<sup class="upper-index">2</sup>. So the answer is 2<sup class="upper-index">4</sup> - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
[ { "input": "4\n1 1 1 1", "output": "15" }, { "input": "4\n2 2 2 2", "output": "7" }, { "input": "5\n1 2 4 5 8", "output": "7" }, { "input": "1\n64", "output": "1" }, { "input": "5\n2 2 2 2 2", "output": "15" }, { "input": "6\n1 2 3 4 5 6", "output": "7" }, { "input": "2\n70 70", "output": "1" }, { "input": "7\n4 9 16 25 36 49 64", "output": "127" }, { "input": "13\n64 65 40 26 36 46 53 31 63 11 2 46 59", "output": "15" }, { "input": "15\n66 34 43 45 61 14 12 67 38 25 55 9 30 41 16", "output": "15" }, { "input": "17\n44 57 54 57 54 65 40 57 59 16 39 51 32 51 20 9 8", "output": "511" }, { "input": "18\n22 41 40 8 36 48 23 5 58 12 26 44 53 49 3 56 58 57", "output": "127" }, { "input": "20\n20 34 51 40 70 64 14 30 24 20 6 1 70 28 38 43 9 60 31 69", "output": "2047" }, { "input": "5\n19 51 55 29 13", "output": "0" }, { "input": "6\n19 60 48 64 56 27", "output": "3" }, { "input": "7\n67 52 58 62 38 26 2", "output": "1" }, { "input": "7\n5 28 46 57 39 26 45", "output": "1" }, { "input": "7\n53 59 56 9 13 1 28", "output": "3" }, { "input": "10\n38 58 51 41 61 12 17 47 18 24", "output": "3" }, { "input": "10\n27 44 40 3 33 38 56 37 43 36", "output": "7" }, { "input": "10\n51 4 25 46 15 21 32 9 43 8", "output": "15" }, { "input": "10\n5 66 19 60 34 27 15 27 42 51", "output": "7" }, { "input": "5\n2 3 5 7 11", "output": "0" }, { "input": "10\n2 3 5 7 11 13 17 19 23 29", "output": "0" }, { "input": "2\n15 45", "output": "0" } ]
4,000
41,472,000
0
7,451
424
Magic Formulas
[ "math" ]
null
null
People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas: Here, "mod" means the operation of taking the residue after dividing. The expression means applying the bitwise *xor* (excluding "OR") operation to integers *x* and *y*. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in Pascal β€” by "xor". People in the Tomskaya region like magic formulas very much, but they don't like to calculate them! Therefore you are given the sequence *p*, calculate the value of *Q*.
The first line of the input contains the only integer *n* (1<=≀<=*n*<=≀<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≀<=*p**i*<=≀<=2Β·109).
The only line of output should contain a single integer β€” the value of *Q*.
[ "3\n1 2 3\n" ]
[ "3\n" ]
none
[ { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n0", "output": "0" }, { "input": "2\n65535 0", "output": "65534" }, { "input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015", "output": "948506286" }, { "input": "20\n1999581813 313463235 1733614990 662007911 1789348031 1120800519 196972430 1579897311 191001928 241720485 1426288783 1103088596 839698523 1974815116 77040208 904949865 840522850 1488919296 1027394709 857931762", "output": "1536068328" }, { "input": "25\n39226529 640445129 936289624 364461191 1096077769 573427707 1919403410 950067229 1217479531 455229458 1574949468 397268319 1267289585 995220637 1920919164 501015483 1815262670 1197059269 86947741 1137410885 667368575 733666398 1536581408 611239452 947487746", "output": "259654661" } ]
46
0
0
7,459
163
e-Government
[ "data structures", "dfs and similar", "dp", "strings", "trees" ]
null
null
The best programmers of Embezzland compete to develop a part of the project called "e-Government" β€” the system of automated statistic collecting and press analysis. We know that any of the *k* citizens can become a member of the Embezzland government. The citizens' surnames are *a*1,<=*a*2,<=...,<=*a**k*. All surnames are different. Initially all *k* citizens from this list are members of the government. The system should support the following options: - Include citizen *a**i* to the government. - Exclude citizen *a**i* from the government. - Given a newspaper article text, calculate how politicized it is. To do this, for every active government member the system counts the number of times his surname occurs in the text as a substring. All occurrences are taken into consideration, including the intersecting ones. The degree of politicization of a text is defined as the sum of these values for all active government members. Implement this system.
The first line contains space-separated integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=105) β€” the number of queries to the system and the number of potential government members. Next *k* lines contain the surnames *a*1,<=*a*2,<=...,<=*a**k*, one per line. All surnames are pairwise different. Next *n* lines contain queries to the system, one per line. Each query consists of a character that determines an operation and the operation argument, written consecutively without a space. Operation "include in the government" corresponds to the character "+", operation "exclude" corresponds to "-". An argument of those operations is an integer between 1 and *k* β€” the index of the citizen involved in the operation. Any citizen can be included and excluded from the government an arbitrary number of times in any order. Including in the government a citizen who is already there or excluding the citizen who isn't there changes nothing. The operation "calculate politicization" corresponds to character "?". Its argument is a text. All strings β€” surnames and texts β€” are non-empty sequences of lowercase Latin letters. The total length of all surnames doesn't exceed 106, the total length of all texts doesn't exceed 106.
For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations.
[ "7 3\na\naa\nab\n?aaab\n-2\n?aaab\n-3\n?aaab\n+2\n?aabbaa\n" ]
[ "6\n4\n3\n6\n" ]
none
[]
1,000
11,673,600
0
7,461
190
Surrounded
[ "geometry" ]
null
null
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal β€” their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city β€” that's the strategy the flatlanders usually follow when they besiege cities. The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most *r* from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most *r*). Then the radar can immediately inform about the enemy's attack. Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (*r*) is, the more the radar costs. That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius *r* (*r*<=β‰₯<=0) such, that a radar with radius *r* can be installed at some point and it can register the start of the movements of both flatland rings from that point. In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range β€” as a disk (including the border) with the center at the point where the radar is placed.
The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≀<=104;Β 1<=≀<=*r**i*<=≀<=104) β€” the city's coordinates and the distance from the city to the flatlanders, correspondingly. It is guaranteed that the cities are located at different points.
Print a single real number β€” the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6.
[ "0 0 1\n6 0 3\n", "-10 10 3\n10 -10 3\n" ]
[ "1.000000000000000", "11.142135623730951" ]
The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0). The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).
[ { "input": "0 0 1\n6 0 3", "output": "1.000000000000000" }, { "input": "-10 10 3\n10 -10 3", "output": "11.142135623730951" }, { "input": "2 1 3\n8 9 5", "output": "1.000000000000000" }, { "input": "0 0 1\n-10 -10 9", "output": "2.071067811865475" }, { "input": "10000 -9268 1\n-9898 9000 10", "output": "13500.519287710202000" }, { "input": "10000 10000 1\n-10000 -10000 1", "output": "14141.135623730950000" }, { "input": "123 21 50\n10 100 1000", "output": "406.061621719103360" }, { "input": "0 3278 2382\n2312 1 1111", "output": "258.747677968983450" }, { "input": "3 4 5\n5 12 13", "output": "0.000000000000000" }, { "input": "-2 7 5\n4 0 6", "output": "0.000000000000000" }, { "input": "4 0 2\n6 -1 10", "output": "2.881966011250105" }, { "input": "41 17 3\n71 -86 10", "output": "47.140003728560643" }, { "input": "761 641 6\n506 -293 5", "output": "478.592191632957450" }, { "input": "-5051 -7339 9\n-9030 755 8", "output": "4501.080828635849700" }, { "input": "0 5 2\n8 -4 94", "output": "39.979202710603850" }, { "input": "83 -64 85\n27 80 89", "output": "0.000000000000000" }, { "input": "-655 -750 68\n905 -161 68", "output": "765.744715125679250" }, { "input": "1055 -5271 60\n-2992 8832 38", "output": "7287.089182936641900" }, { "input": "4 0 201\n-6 4 279", "output": "33.614835192865499" }, { "input": "-34 -5 836\n52 -39 706", "output": "18.761487913212431" }, { "input": "659 -674 277\n-345 -556 127", "output": "303.455240352694320" }, { "input": "4763 2945 956\n3591 9812 180", "output": "2915.147750239716500" }, { "input": "3 -7 5749\n1 -6 9750", "output": "1999.381966011250100" }, { "input": "28 -63 2382\n43 -83 1364", "output": "496.500000000000000" }, { "input": "315 -532 7813\n407 -157 2121", "output": "2652.939776235497000" }, { "input": "-9577 9051 5276\n-4315 -1295 8453", "output": "0.000000000000000" }, { "input": "-7 -10 1\n-4 3 1", "output": "5.670832032063167" }, { "input": "-74 27 535\n18 84 1", "output": "212.886692948961240" }, { "input": "-454 -721 72\n-33 279 911", "output": "51.003686623418254" }, { "input": "-171 762 304\n-428 -85 523", "output": "29.065814314662131" }, { "input": "192 -295 1386\n-54 -78 1", "output": "528.483994683445640" }, { "input": "-5134 -9860 5513\n6291 -855 9034", "output": "0.093506651303098" }, { "input": "6651 8200 610\n-9228 9387 10000", "output": "2656.651995660197400" }, { "input": "6370 7728 933\n4595 3736 2748", "output": "343.915768575204200" }, { "input": "-6 3 8\n7 2 1", "output": "2.019202405202649" }, { "input": "0 -1 1\n1 -1 1", "output": "0.000000000000000" }, { "input": "0 1 3\n1 -1 1", "output": "0.000000000000000" }, { "input": "-2 0 1\n3 -2 1", "output": "1.692582403567252" }, { "input": "-10000 42 10000\n10000 43 10000", "output": "0.000012499999992" }, { "input": "103 104 5\n97 96 5", "output": "0.000000000000000" }, { "input": "2587 4850 3327\n3278 -204 1774", "output": "0.009605941526345" }, { "input": "826 4417 2901\n833 -2286 3802", "output": "0.001827539409235" }, { "input": "1003 -5005 3399\n-6036 -1729 4365", "output": "0.000032199896827" } ]
109
6,963,200
3
7,502
165
Compatible Numbers
[ "bitmasks", "brute force", "dfs and similar", "dp" ]
null
null
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* &amp; *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 &amp; 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 &amp; 1102<==<=102. You are given an array of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=106) β€” the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=4Β·106) β€” the elements of the given array. The numbers in the array can coincide.
Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* &amp; *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*.
[ "2\n90 36\n", "4\n3 6 3 6\n", "5\n10 6 9 8 2\n" ]
[ "36 90", "-1 -1 -1 -1", "-1 8 2 2 8" ]
none
[ { "input": "2\n90 36", "output": "36 90" }, { "input": "4\n3 6 3 6", "output": "-1 -1 -1 -1" }, { "input": "5\n10 6 9 8 2", "output": "-1 8 2 2 8" }, { "input": "10\n4 9 8 3 2 6 8 2 9 7", "output": "8 4 4 8 8 8 4 8 4 8" }, { "input": "10\n3 5 18 12 4 20 11 19 15 6", "output": "4 18 4 18 18 3 4 4 -1 -1" }, { "input": "15\n8 4 9 3 6 6 6 6 1 6 7 1 8 9 2", "output": "4 8 4 8 8 8 8 8 8 8 8 8 4 4 8" }, { "input": "20\n280 983 126 941 167 215 868 748 383 554 917 285 43 445 331 800 527 998 503 164", "output": "164 -1 -1 -1 280 800 -1 -1 -1 -1 -1 -1 -1 -1 164 215 -1 -1 -1 280" }, { "input": "5\n1 4 2 3 5", "output": "4 2 4 4 2" }, { "input": "1\n1", "output": "-1" }, { "input": "1\n4000000", "output": "-1" }, { "input": "1\n2097152", "output": "-1" } ]
1,776
268,390,400
0
7,505
482
Diverse Permutation
[ "constructive algorithms", "greedy" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*. Your task is to find such permutation *p* of length *n*, that the group of numbers |*p*1<=-<=*p*2|,<=|*p*2<=-<=*p*3|,<=...,<=|*p**n*<=-<=1<=-<=*p**n*| has exactly *k* distinct elements.
The single line of the input contains two space-separated positive integers *n*, *k* (1<=≀<=*k*<=&lt;<=*n*<=≀<=105).
Print *n* integers forming the permutation. If there are multiple answers, print any of them.
[ "3 2\n", "3 1\n", "5 2\n" ]
[ "1 3 2\n", "1 2 3\n", "1 3 2 4 5\n" ]
By |*x*| we denote the absolute value of number *x*.
[ { "input": "3 2", "output": "1 3 2" }, { "input": "3 1", "output": "1 2 3" }, { "input": "5 2", "output": "1 3 2 4 5" }, { "input": "5 4", "output": "1 5 2 4 3" }, { "input": "10 4", "output": "1 10 2 9 8 7 6 5 4 3" }, { "input": "10 3", "output": "1 10 2 3 4 5 6 7 8 9" }, { "input": "10 9", "output": "1 10 2 9 3 8 4 7 5 6" }, { "input": "100000 99999", "output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..." }, { "input": "99999 99998", "output": "1 99999 2 99998 3 99997 4 99996 5 99995 6 99994 7 99993 8 99992 9 99991 10 99990 11 99989 12 99988 13 99987 14 99986 15 99985 16 99984 17 99983 18 99982 19 99981 20 99980 21 99979 22 99978 23 99977 24 99976 25 99975 26 99974 27 99973 28 99972 29 99971 30 99970 31 99969 32 99968 33 99967 34 99966 35 99965 36 99964 37 99963 38 99962 39 99961 40 99960 41 99959 42 99958 43 99957 44 99956 45 99955 46 99954 47 99953 48 99952 49 99951 50 99950 51 99949 52 99948 53 99947 54 99946 55 99945 56 99944 57 99943 58 9994..." }, { "input": "42273 29958", "output": "1 42273 2 42272 3 42271 4 42270 5 42269 6 42268 7 42267 8 42266 9 42265 10 42264 11 42263 12 42262 13 42261 14 42260 15 42259 16 42258 17 42257 18 42256 19 42255 20 42254 21 42253 22 42252 23 42251 24 42250 25 42249 26 42248 27 42247 28 42246 29 42245 30 42244 31 42243 32 42242 33 42241 34 42240 35 42239 36 42238 37 42237 38 42236 39 42235 40 42234 41 42233 42 42232 43 42231 44 42230 45 42229 46 42228 47 42227 48 42226 49 42225 50 42224 51 42223 52 42222 53 42221 54 42220 55 42219 56 42218 57 42217 58 4221..." }, { "input": "29857 9843", "output": "1 29857 2 29856 3 29855 4 29854 5 29853 6 29852 7 29851 8 29850 9 29849 10 29848 11 29847 12 29846 13 29845 14 29844 15 29843 16 29842 17 29841 18 29840 19 29839 20 29838 21 29837 22 29836 23 29835 24 29834 25 29833 26 29832 27 29831 28 29830 29 29829 30 29828 31 29827 32 29826 33 29825 34 29824 35 29823 36 29822 37 29821 38 29820 39 29819 40 29818 41 29817 42 29816 43 29815 44 29814 45 29813 46 29812 47 29811 48 29810 49 29809 50 29808 51 29807 52 29806 53 29805 54 29804 55 29803 56 29802 57 29801 58 2980..." }, { "input": "27687 4031", "output": "1 27687 2 27686 3 27685 4 27684 5 27683 6 27682 7 27681 8 27680 9 27679 10 27678 11 27677 12 27676 13 27675 14 27674 15 27673 16 27672 17 27671 18 27670 19 27669 20 27668 21 27667 22 27666 23 27665 24 27664 25 27663 26 27662 27 27661 28 27660 29 27659 30 27658 31 27657 32 27656 33 27655 34 27654 35 27653 36 27652 37 27651 38 27650 39 27649 40 27648 41 27647 42 27646 43 27645 44 27644 45 27643 46 27642 47 27641 48 27640 49 27639 50 27638 51 27637 52 27636 53 27635 54 27634 55 27633 56 27632 57 27631 58 2763..." }, { "input": "25517 1767", "output": "1 25517 2 25516 3 25515 4 25514 5 25513 6 25512 7 25511 8 25510 9 25509 10 25508 11 25507 12 25506 13 25505 14 25504 15 25503 16 25502 17 25501 18 25500 19 25499 20 25498 21 25497 22 25496 23 25495 24 25494 25 25493 26 25492 27 25491 28 25490 29 25489 30 25488 31 25487 32 25486 33 25485 34 25484 35 25483 36 25482 37 25481 38 25480 39 25479 40 25478 41 25477 42 25476 43 25475 44 25474 45 25473 46 25472 47 25471 48 25470 49 25469 50 25468 51 25467 52 25466 53 25465 54 25464 55 25463 56 25462 57 25461 58 2546..." }, { "input": "23347 20494", "output": "1 23347 2 23346 3 23345 4 23344 5 23343 6 23342 7 23341 8 23340 9 23339 10 23338 11 23337 12 23336 13 23335 14 23334 15 23333 16 23332 17 23331 18 23330 19 23329 20 23328 21 23327 22 23326 23 23325 24 23324 25 23323 26 23322 27 23321 28 23320 29 23319 30 23318 31 23317 32 23316 33 23315 34 23314 35 23313 36 23312 37 23311 38 23310 39 23309 40 23308 41 23307 42 23306 43 23305 44 23304 45 23303 46 23302 47 23301 48 23300 49 23299 50 23298 51 23297 52 23296 53 23295 54 23294 55 23293 56 23292 57 23291 58 2329..." }, { "input": "10931 8824", "output": "1 10931 2 10930 3 10929 4 10928 5 10927 6 10926 7 10925 8 10924 9 10923 10 10922 11 10921 12 10920 13 10919 14 10918 15 10917 16 10916 17 10915 18 10914 19 10913 20 10912 21 10911 22 10910 23 10909 24 10908 25 10907 26 10906 27 10905 28 10904 29 10903 30 10902 31 10901 32 10900 33 10899 34 10898 35 10897 36 10896 37 10895 38 10894 39 10893 40 10892 41 10891 42 10890 43 10889 44 10888 45 10887 46 10886 47 10885 48 10884 49 10883 50 10882 51 10881 52 10880 53 10879 54 10878 55 10877 56 10876 57 10875 58 1087..." }, { "input": "98514 26178", "output": "1 98514 2 98513 3 98512 4 98511 5 98510 6 98509 7 98508 8 98507 9 98506 10 98505 11 98504 12 98503 13 98502 14 98501 15 98500 16 98499 17 98498 18 98497 19 98496 20 98495 21 98494 22 98493 23 98492 24 98491 25 98490 26 98489 27 98488 28 98487 29 98486 30 98485 31 98484 32 98483 33 98482 34 98481 35 98480 36 98479 37 98478 38 98477 39 98476 40 98475 41 98474 42 98473 43 98472 44 98471 45 98470 46 98469 47 98468 48 98467 49 98466 50 98465 51 98464 52 98463 53 98462 54 98461 55 98460 56 98459 57 98458 58 9845..." }, { "input": "6591 407", "output": "1 6591 2 6590 3 6589 4 6588 5 6587 6 6586 7 6585 8 6584 9 6583 10 6582 11 6581 12 6580 13 6579 14 6578 15 6577 16 6576 17 6575 18 6574 19 6573 20 6572 21 6571 22 6570 23 6569 24 6568 25 6567 26 6566 27 6565 28 6564 29 6563 30 6562 31 6561 32 6560 33 6559 34 6558 35 6557 36 6556 37 6555 38 6554 39 6553 40 6552 41 6551 42 6550 43 6549 44 6548 45 6547 46 6546 47 6545 48 6544 49 6543 50 6542 51 6541 52 6540 53 6539 54 6538 55 6537 56 6536 57 6535 58 6534 59 6533 60 6532 61 6531 62 6530 63 6529 64 6528 65 6527 ..." }, { "input": "94174 30132", "output": "1 94174 2 94173 3 94172 4 94171 5 94170 6 94169 7 94168 8 94167 9 94166 10 94165 11 94164 12 94163 13 94162 14 94161 15 94160 16 94159 17 94158 18 94157 19 94156 20 94155 21 94154 22 94153 23 94152 24 94151 25 94150 26 94149 27 94148 28 94147 29 94146 30 94145 31 94144 32 94143 33 94142 34 94141 35 94140 36 94139 37 94138 38 94137 39 94136 40 94135 41 94134 42 94133 43 94132 44 94131 45 94130 46 94129 47 94128 48 94127 49 94126 50 94125 51 94124 52 94123 53 94122 54 94121 55 94120 56 94119 57 94118 58 9411..." }, { "input": "92004 85348", "output": "1 92004 2 92003 3 92002 4 92001 5 92000 6 91999 7 91998 8 91997 9 91996 10 91995 11 91994 12 91993 13 91992 14 91991 15 91990 16 91989 17 91988 18 91987 19 91986 20 91985 21 91984 22 91983 23 91982 24 91981 25 91980 26 91979 27 91978 28 91977 29 91976 30 91975 31 91974 32 91973 33 91972 34 91971 35 91970 36 91969 37 91968 38 91967 39 91966 40 91965 41 91964 42 91963 43 91962 44 91961 45 91960 46 91959 47 91958 48 91957 49 91956 50 91955 51 91954 52 91953 53 91952 54 91951 55 91950 56 91949 57 91948 58 9194..." }, { "input": "59221 29504", "output": "1 59221 2 59220 3 59219 4 59218 5 59217 6 59216 7 59215 8 59214 9 59213 10 59212 11 59211 12 59210 13 59209 14 59208 15 59207 16 59206 17 59205 18 59204 19 59203 20 59202 21 59201 22 59200 23 59199 24 59198 25 59197 26 59196 27 59195 28 59194 29 59193 30 59192 31 59191 32 59190 33 59189 34 59188 35 59187 36 59186 37 59185 38 59184 39 59183 40 59182 41 59181 42 59180 43 59179 44 59178 45 59177 46 59176 47 59175 48 59174 49 59173 50 59172 51 59171 52 59170 53 59169 54 59168 55 59167 56 59166 57 59165 58 5916..." }, { "input": "2 1", "output": "1 2" }, { "input": "4 1", "output": "1 2 3 4" }, { "input": "4 2", "output": "1 4 3 2" }, { "input": "100000 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "99999 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "99998 2", "output": "1 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 99915 99914..." }, { "input": "99999 5000", "output": "1 99999 2 99998 3 99997 4 99996 5 99995 6 99994 7 99993 8 99992 9 99991 10 99990 11 99989 12 99988 13 99987 14 99986 15 99985 16 99984 17 99983 18 99982 19 99981 20 99980 21 99979 22 99978 23 99977 24 99976 25 99975 26 99974 27 99973 28 99972 29 99971 30 99970 31 99969 32 99968 33 99967 34 99966 35 99965 36 99964 37 99963 38 99962 39 99961 40 99960 41 99959 42 99958 43 99957 44 99956 45 99955 46 99954 47 99953 48 99952 49 99951 50 99950 51 99949 52 99948 53 99947 54 99946 55 99945 56 99944 57 99943 58 9994..." }, { "input": "100000 99998", "output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..." }, { "input": "3222 311", "output": "1 3222 2 3221 3 3220 4 3219 5 3218 6 3217 7 3216 8 3215 9 3214 10 3213 11 3212 12 3211 13 3210 14 3209 15 3208 16 3207 17 3206 18 3205 19 3204 20 3203 21 3202 22 3201 23 3200 24 3199 25 3198 26 3197 27 3196 28 3195 29 3194 30 3193 31 3192 32 3191 33 3190 34 3189 35 3188 36 3187 37 3186 38 3185 39 3184 40 3183 41 3182 42 3181 43 3180 44 3179 45 3178 46 3177 47 3176 48 3175 49 3174 50 3173 51 3172 52 3171 53 3170 54 3169 55 3168 56 3167 57 3166 58 3165 59 3164 60 3163 61 3162 62 3161 63 3160 64 3159 65 3158 ..." }, { "input": "32244 222", "output": "1 32244 2 32243 3 32242 4 32241 5 32240 6 32239 7 32238 8 32237 9 32236 10 32235 11 32234 12 32233 13 32232 14 32231 15 32230 16 32229 17 32228 18 32227 19 32226 20 32225 21 32224 22 32223 23 32222 24 32221 25 32220 26 32219 27 32218 28 32217 29 32216 30 32215 31 32214 32 32213 33 32212 34 32211 35 32210 36 32209 37 32208 38 32207 39 32206 40 32205 41 32204 42 32203 43 32202 44 32201 45 32200 46 32199 47 32198 48 32197 49 32196 50 32195 51 32194 52 32193 53 32192 54 32191 55 32190 56 32189 57 32188 58 3218..." }, { "input": "1111 122", "output": "1 1111 2 1110 3 1109 4 1108 5 1107 6 1106 7 1105 8 1104 9 1103 10 1102 11 1101 12 1100 13 1099 14 1098 15 1097 16 1096 17 1095 18 1094 19 1093 20 1092 21 1091 22 1090 23 1089 24 1088 25 1087 26 1086 27 1085 28 1084 29 1083 30 1082 31 1081 32 1080 33 1079 34 1078 35 1077 36 1076 37 1075 38 1074 39 1073 40 1072 41 1071 42 1070 43 1069 44 1068 45 1067 46 1066 47 1065 48 1064 49 1063 50 1062 51 1061 52 1060 53 1059 54 1058 55 1057 56 1056 57 1055 58 1054 59 1053 60 1052 61 1051 1050 1049 1048 1047 1046 1045 10..." }, { "input": "32342 1221", "output": "1 32342 2 32341 3 32340 4 32339 5 32338 6 32337 7 32336 8 32335 9 32334 10 32333 11 32332 12 32331 13 32330 14 32329 15 32328 16 32327 17 32326 18 32325 19 32324 20 32323 21 32322 22 32321 23 32320 24 32319 25 32318 26 32317 27 32316 28 32315 29 32314 30 32313 31 32312 32 32311 33 32310 34 32309 35 32308 36 32307 37 32306 38 32305 39 32304 40 32303 41 32302 42 32301 43 32300 44 32299 45 32298 46 32297 47 32296 48 32295 49 32294 50 32293 51 32292 52 32291 53 32290 54 32289 55 32288 56 32287 57 32286 58 3228..." }, { "input": "100000 50000", "output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 99968 34 99967 35 99966 36 99965 37 99964 38 99963 39 99962 40 99961 41 99960 42 99959 43 99958 44 99957 45 99956 46 99955 47 99954 48 99953 49 99952 50 99951 51 99950 52 99949 53 99948 54 99947 55 99946 56 99945 57 99944 58 999..." }, { "input": "100000 45", "output": "1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 12..." }, { "input": "99999 2", "output": "1 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 99915..." }, { "input": "9 8", "output": "1 9 2 8 3 7 4 6 5" }, { "input": "7 5", "output": "1 7 2 6 3 4 5" } ]
514
614,400
3
7,509
135
Rectangle and Square
[ "brute force", "geometry", "math" ]
null
null
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
You are given 8 pairs of integers, a pair per line β€” the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β€” point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
[ "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2\n", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1\n" ]
[ "YES\n5 6 7 8\n1 2 3 4\n", "NO\n", "YES\n1 2 3 4\n5 6 7 8\n" ]
Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
[ { "input": "0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "output": "YES\n5 6 7 8\n1 2 3 4" }, { "input": "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "output": "NO" }, { "input": "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1", "output": "YES\n1 2 3 4\n5 6 7 8" }, { "input": "-160 336\n-76 672\n8 168\n-580 588\n-1000 504\n-496 840\n-496 84\n-664 0", "output": "YES\n2 3 4 7\n1 5 6 8" }, { "input": "8 -328\n-440 568\n-104 8\n-1000 -664\n8 456\n-328 8\n-552 120\n-664 -1000", "output": "YES\n2 3 5 7\n1 4 6 8" }, { "input": "65 852\n-645 284\n-361 710\n-1000 71\n-219 284\n207 426\n-716 0\n-929 355", "output": "YES\n1 3 5 6\n2 4 7 8" }, { "input": "980 518\n584 -670\n-208 914\n-736 -340\n-604 -274\n-1000 -736\n-604 -1000\n-340 -604", "output": "YES\n1 2 3 5\n4 6 7 8" }, { "input": "48 264\n144 240\n24 0\n168 48\n120 144\n0 72\n144 120\n24 168", "output": "YES\n1 2 5 8\n3 4 6 7" }, { "input": "576 -616\n192 -424\n384 152\n768 248\n384 -1000\n0 -808\n480 -232\n864 -136", "output": "YES\n1 2 5 6\n3 4 7 8" }, { "input": "547 -167\n-1000 -762\n190 904\n-762 -1000\n-167 71\n904 547\n71 -167\n-167 190", "output": "YES\n1 3 6 8\n2 4 5 7" }, { "input": "-1000 -736\n1200 408\n1728 12\n188 -1000\n1332 -516\n-736 -208\n452 -472\n804 -120", "output": "NO" }, { "input": "210 140\n140 0\n210 210\n455 140\n70 210\n525 385\n0 70\n280 455", "output": "YES\n1 2 5 7\n3 4 6 8" }, { "input": "-1000 -829\n-715 -601\n311 197\n197 -715\n-829 -1000\n-601 311\n-658 -487\n-487 -658", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "329 -859\n282 -765\n376 81\n0 -906\n47 -1000\n846 -577\n940 -13\n282 -483", "output": "YES\n3 6 7 8\n1 2 4 5" }, { "input": "40 100\n210 20\n100 60\n120 230\n0 40\n60 0\n60 80\n270 170", "output": "YES\n1 3 5 6\n2 4 7 8" }, { "input": "-252 -1000\n-1000 -932\n-864 20\n-796 -864\n768 -388\n-932 -796\n-864 -1000\n156 632", "output": "YES\n2 4 6 7\n1 3 5 8" }, { "input": "351 234\n234 741\n234 351\n702 819\n117 0\n0 117\n312 273\n780 351", "output": "YES\n2 4 7 8\n1 3 5 6" }, { "input": "434 372\n0 62\n496 868\n868 620\n620 248\n248 496\n62 434\n372 0", "output": "YES\n3 4 5 6\n1 2 7 8" }, { "input": "-40 -1000\n-440 120\n2200 -200\n1800 920\n-200 -680\n-840 120\n-40 -360\n-1000 -200", "output": "NO" }, { "input": "-850 -1000\n-475 -325\n1025 800\n-325 575\n-325 -850\n-1000 -475\n-100 -775\n1250 -550", "output": "YES\n1 2 5 6\n3 4 7 8" }, { "input": "70 64\n32 0\n58 48\n48 80\n72 50\n0 48\n56 62\n80 32", "output": "YES\n1 3 5 7\n2 4 6 8" }, { "input": "937 937\n-851 43\n-404 1086\n43 -106\n788 -404\n-553 -255\n-1000 -851\n-106 -1000", "output": "YES\n1 3 5 6\n2 4 7 8" }, { "input": "-1 -223\n554 110\n-778 -1000\n-667 -445\n-1000 -667\n-445 -778\n443 -334\n110 221", "output": "YES\n3 4 5 6\n1 2 7 8" }, { "input": "1610 0\n1700 270\n-1000 -900\n2105 315\n800 0\n-190 -900\n1925 90\n1880 495", "output": "NO" }, { "input": "-360 120\n600 440\n-680 -40\n440 600\n-520 -360\n-200 -200\n-840 -1000\n-1000 -840", "output": "YES\n1 3 5 6\n2 4 7 8" }, { "input": "-11 220\n-11 22\n176 -66\n-198 -22\n-198 176\n220 -198\n0 88\n44 -44", "output": "NO" }, { "input": "378 504\n504 504\n126 0\n504 126\n0 378\n252 546\n294 798\n546 756", "output": "YES\n1 3 4 5\n2 6 7 8" }, { "input": "312 468\n312 0\n728 728\n468 676\n520 416\n0 0\n780 468\n0 468", "output": "YES\n3 4 5 7\n1 2 6 8" }, { "input": "180 100\n180 220\n80 0\n240 760\n0 80\n100 180\n720 160\n780 700", "output": "YES\n2 4 7 8\n1 3 5 6" }, { "input": "-1000 -742\n1064 290\n32 634\n720 -742\n-742 -226\n-312 -398\n-484 -1000\n-226 -484", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "-153 -238\n-204 34\n102 119\n34 0\n-663 -306\n0 68\n-612 -578\n136 51", "output": "NO" }, { "input": "-620 -1000\n-1000 -620\n976 672\n-240 140\n596 140\n140 -240\n1052 216\n520 596", "output": "YES\n3 5 7 8\n1 2 4 6" }, { "input": "203 232\n232 348\n58 0\n0 58\n319 203\n290 232\n348 319\n232 290", "output": "YES\n1 2 5 7\n3 4 6 8" }, { "input": "-328 260\n-664 -1000\n-1000 -496\n92 -496\n-1000 -1000\n-664 -496\n-496 -328\n260 92", "output": "YES\n1 4 7 8\n2 3 5 6" }, { "input": "-586 414\n-931 0\n-103 276\n-448 897\n-655 414\n35 759\n-586 345\n-1000 69", "output": "YES\n1 3 4 6\n2 5 7 8" }, { "input": "-424 920\n-1000 152\n344 -232\n-232 536\n-424 -1000\n-616 -40\n344 -616\n536 728", "output": "YES\n1 3 6 8\n2 4 5 7" }, { "input": "427 -451\n549 -573\n122 -1000\n0 -85\n183 -512\n427 98\n610 -329\n0 -878", "output": "YES\n4 5 6 7\n1 2 3 8" }, { "input": "89 -307\n-109 -505\n-10 89\n-1000 -604\n-505 -1000\n-406 -10\n-307 -406\n-604 -109", "output": "YES\n1 3 6 7\n2 4 5 8" }, { "input": "5 0\n16 -54\n9 5\n0 4\n0 -6\n4 9\n40 -24\n-24 -36", "output": "NO" }, { "input": "-845 860\n-535 -225\n-380 85\n395 550\n-225 -535\n-1000 -690\n-690 -1000\n-70 1325", "output": "YES\n1 3 4 8\n2 5 6 7" }, { "input": "702 628\n-334 -408\n-482 -852\n850 -704\n-408 -334\n-926 -1000\n-1000 -926\n-630 480", "output": "YES\n1 3 4 8\n2 5 6 7" }, { "input": "-465 -37\n-465 -1000\n177 -37\n-144 177\n-1000 -37\n-1000 -1000\n-358 -144\n-37 -358", "output": "YES\n3 4 7 8\n1 2 5 6" }, { "input": "-1000 176\n408 88\n-384 528\n-648 704\n-472 792\n-736 0\n-384 0\n320 880", "output": "YES\n2 5 7 8\n1 3 4 6" }, { "input": "-1000 786\n-906 1256\n-671 1021\n-812 974\n598 316\n-765 1303\n598 -1000\n-1000 -530", "output": "NO" }, { "input": "550 -70\n-8 -597\n-70 -628\n-39 -690\n-1000 -380\n23 -659\n-70 550\n-380 -1000", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "184 230\n46 0\n0 184\n23 184\n115 552\n483 460\n391 92\n230 46", "output": "YES\n4 5 6 7\n1 2 3 8" }, { "input": "692 -60\n-812 316\n128 880\n-248 -624\n-812 692\n-1000 -1000\n-1000 692\n-812 -1000", "output": "YES\n1 2 3 4\n5 6 7 8" }, { "input": "-1000 -852\n-852 -1000\n332 480\n36 1812\n184 2996\n480 332\n-408 776\n-556 -408", "output": "NO" }, { "input": "68 0\n374 221\n306 204\n323 136\n272 340\n391 153\n0 272\n340 68", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "296 -163\n350 -190\n-190 -1000\n701 -730\n782 -244\n215 -649\n-1000 -460\n-460 350", "output": "YES\n1 4 5 6\n2 3 7 8" }, { "input": "280 0\n504 420\n0 0\n0 168\n644 504\n280 168\n532 532\n616 392", "output": "YES\n2 5 7 8\n1 3 4 6" }, { "input": "728 656\n584 152\n1160 152\n-1000 -1000\n1016 944\n-568 -424\n1448 440\n1016 728", "output": "NO" }, { "input": "0 25\n725 325\n250 225\n575 675\n375 175\n225 525\n25 0\n225 250", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "116 488\n-628 -1000\n-70 -70\n116 1604\n-814 860\n488 -628\n860 674\n-1000 116", "output": "YES\n3 4 5 7\n1 2 6 8" }, { "input": "-208 -703\n-109 -604\n-406 -10\n287 188\n-208 -406\n-1000 -802\n-901 -1000\n485 -505", "output": "YES\n1 3 4 8\n2 5 6 7" }, { "input": "1136 602\n1403 -21\n-21 -911\n-1000 424\n-733 513\n-288 -1000\n780 -288\n513 335", "output": "NO" }, { "input": "760 980\n1420 -120\n320 -780\n-1000 -560\n100 -340\n-340 320\n-560 -1000\n-340 100", "output": "YES\n1 2 3 6\n4 5 7 8" }, { "input": "2843 260\n3347 890\n2780 827\n1520 134\n-1000 -874\n2276 8\n-244 -1000\n3410 323", "output": "NO" }, { "input": "0 336\n112 476\n196 448\n336 0\n560 896\n140 560\n224 532\n896 560", "output": "YES\n2 3 6 7\n1 4 5 8" }, { "input": "0 39\n169 117\n182 182\n104 130\n117 195\n65 0\n39 104\n104 65", "output": "YES\n2 3 4 5\n1 6 7 8" }, { "input": "-610 40\n-1000 -220\n-870 -1000\n-220 352\n-298 -350\n-220 -90\n92 -38\n-90 -870", "output": "YES\n1 4 5 7\n2 3 6 8" }, { "input": "560 140\n0 140\n280 280\n560 700\n420 560\n700 560\n140 0\n700 420", "output": "YES\n1 3 5 8\n2 4 6 7" }, { "input": "400 -580\n-580 -895\n-475 -720\n-580 -1000\n-405 -1000\n-20 400\n-300 -825\n-1000 -20", "output": "YES\n2 3 5 7\n1 4 6 8" }, { "input": "-736 -560\n56 -560\n-208 320\n-736 -472\n56 760\n-648 320\n-1000 -1000\n144 232", "output": "NO" }, { "input": "688 516\n387 258\n0 129\n387 430\n43 0\n430 129\n774 215\n473 129", "output": "YES\n1 4 7 8\n2 3 5 6" }, { "input": "-856 -1000\n224 872\n-136 8\n584 656\n8 512\n368 296\n8 -136\n-1000 -856", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "-880 0\n400 -240\n-640 480\n-160 240\n-240 480\n-520 360\n320 0\n-1000 120", "output": "NO" }, { "input": "58 0\n0 58\n377 145\n261 203\n203 261\n406 29\n290 0\n261 116", "output": "YES\n3 6 7 8\n1 2 4 5" }, { "input": "420 280\n308 196\n336 392\n224 308\n0 224\n224 280\n56 0\n280 56", "output": "YES\n1 2 3 4\n5 6 7 8" }, { "input": "136 -1000\n544 -864\n408 -456\n816 156\n340 88\n884 -320\n0 -592\n408 -388", "output": "YES\n1 2 3 7\n4 5 6 8" }, { "input": "920 -360\n2088 200\n-1000 600\n2024 -56\n1576 -184\n1240 -1000\n-680 -40\n1512 -440", "output": "NO" }, { "input": "528 660\n792 660\n660 528\n528 0\n0 132\n330 462\n132 0\n990 198", "output": "YES\n2 4 6 8\n1 3 5 7" }, { "input": "248 404\n872 794\n950 846\n560 -1000\n-1000 716\n924 716\n1002 768\n-688 -688", "output": "NO" }, { "input": "-656 0\n-140 344\n-140 516\n-484 860\n-1000 344\n-54 946\n204 602\n-398 688", "output": "YES\n2 6 7 8\n1 3 4 5" }, { "input": "744 -19\n-1000 -782\n-237 90\n-128 -346\n-346 -891\n-891 -1000\n635 -1000\n-19 -564", "output": "YES\n1 3 5 7\n2 4 6 8" }, { "input": "420 -664\n0 -160\n420 260\n-840 -412\n420 -580\n-840 92\n420 -160\n0 -1000", "output": "NO" }, { "input": "558 930\n0 837\n930 558\n310 775\n372 0\n0 372\n124 651\n186 961", "output": "YES\n2 4 7 8\n1 3 5 6" }, { "input": "-1000 448\n120 448\n876 224\n1212 -84\n36 588\n372 280\n-776 0\n-104 896", "output": "NO" }, { "input": "-320 904\n3896 -184\n224 224\n3624 -48\n-1000 360\n-456 -320\n-864 -864\n-592 -1000", "output": "NO" }, { "input": "302 488\n-814 860\n-70 984\n-690 116\n-814 -1000\n488 302\n54 240\n-1000 -814", "output": "YES\n2 3 4 7\n1 5 6 8" }, { "input": "0 0\n4 -16\n24 36\n-60 60\n-56 44\n36 43\n40 12\n52 19", "output": "NO" }, { "input": "-1000 282\n-154 705\n-859 0\n974 846\n833 141\n128 282\n-13 423\n269 987", "output": "YES\n4 5 6 8\n1 2 3 7" }, { "input": "20 -40\n-40 60\n-20 -15\n100 -90\n40 45\n0 0\n60 60\n40 10", "output": "NO" }, { "input": "-192 -192\n-495 616\n-1000 -596\n414 -91\n313 717\n-394 -192\n-798 -1000\n10 -596", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "-1000 -637\n-516 -274\n-274 -153\n-32 -516\n452 210\n210 -516\n-758 -1000\n-274 452", "output": "YES\n2 5 6 8\n1 3 4 7" }, { "input": "-799 407\n-665 -531\n-531 -866\n-866 -1000\n-263 -933\n809 407\n1345 -933\n-1000 -665", "output": "NO" }, { "input": "-1000 640\n-16 640\n312 -1000\n968 -16\n640 968\n-672 -344\n-672 -1000\n968 -672", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "-1000 -676\n-136 -460\n-460 188\n188 80\n-568 -460\n-460 -136\n-676 -1000\n80 -568", "output": "YES\n3 4 5 8\n1 2 6 7" }, { "input": "748 68\n663 -34\n0 680\n425 0\n663 -68\n425 680\n0 0\n578 -170", "output": "NO" }, { "input": "248 92\n-1000 -792\n-584 -376\n-168 40\n-116 -376\n-792 -1000\n-376 -584\n300 -324", "output": "YES\n1 4 5 8\n2 3 6 7" }, { "input": "140 42\n126 84\n-154 238\n-420 406\n14 0\n0 42\n-518 532\n-56 112", "output": "NO" }, { "input": "477 0\n636 371\n106 689\n212 265\n0 53\n530 795\n53 530\n530 477", "output": "YES\n2 3 4 6\n1 5 7 8" }, { "input": "0 -814\n93 -256\n372 -349\n186 23\n837 -628\n744 -442\n93 -1000\n465 -70", "output": "YES\n2 3 4 8\n1 5 6 7" }, { "input": "-832 -286\n-748 -664\n-916 -1000\n302 -160\n-328 344\n-202 -790\n-1000 -748\n-664 -916", "output": "YES\n1 4 5 6\n2 3 7 8" }, { "input": "25 10\n0 10\n41 34\n5 0\n39 30\n37 36\n35 32\n20 20", "output": "YES\n3 5 6 7\n1 2 4 8" }, { "input": "-522 -1000\n912 1629\n912 434\n-283 1629\n-1000 -283\n195 -522\n-283 195\n-283 2824", "output": "NO" }, { "input": "-586 -310\n-310 104\n104 -586\n-172 -1000\n-1000 -310\n-724 -862\n-34 -448\n-586 -1000", "output": "YES\n1 4 6 7\n2 3 5 8" }, { "input": "-445 -1\n-556 -1000\n554 443\n-1000 -445\n-445 -334\n443 -445\n-1 -556\n-334 554", "output": "YES\n1 2 4 7\n3 5 6 8" }, { "input": "-288 -822\n-733 -110\n-733 -1000\n1047 -555\n-1000 -911\n780 780\n-466 -199\n-555 513", "output": "YES\n1 4 6 8\n2 3 5 7" }, { "input": "2024 8\n1352 -1000\n1016 -244\n512 344\n1856 344\n2360 -748\n-1000 -664\n344 -664", "output": "NO" }, { "input": "-1000 -400\n1190 450\n1460 420\n800 50\n1250 -550\n1100 360\n1370 330\n-550 -1000", "output": "NO" }, { "input": "1175 450\n-130 -1000\n160 160\n-1000 -1000\n-1000 450\n-130 450\n1465 -565\n450 -855", "output": "YES\n1 3 7 8\n2 4 5 6" }, { "input": "424 -288\n-1000 -466\n68 246\n246 1492\n-644 -1000\n-644 -110\n-1000 1136\n602 246", "output": "YES\n4 6 7 8\n1 2 3 5" }, { "input": "-471 -80\n-1000 35\n-402 127\n150 -885\n-885 -1000\n35 150\n-333 -11\n-540 58", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "-400 -1000\n-400 1000\n600 400\n400 1000\n400 1200\n-1000 -400\n-200 200\n1000 400", "output": "YES\n2 3 5 7\n1 4 6 8" }, { "input": "292 1414\n802 1312\n-1000 -1000\n462 2400\n-184 -235\n-847 326\n-31 1091\n972 2298", "output": "NO" }, { "input": "0 0\n8 12\n14 4\n0 10\n7 5\n5 10\n15 11\n5 0", "output": "YES\n2 3 5 7\n1 4 6 8" }, { "input": "60 260\n280 0\n100 240\n80 200\n0 0\n0 400\n280 400\n40 220", "output": "YES\n1 3 4 8\n2 5 6 7" }, { "input": "-850 -1000\n-1000 -850\n-800 -250\n250 -700\n-50 50\n-500 -1000\n-650 -800\n-800 -650", "output": "YES\n3 4 5 6\n1 2 7 8" }, { "input": "-125 -825\n1100 -475\n400 -300\n-1000 -475\n-475 400\n-650 -1000\n50 225\n750 750", "output": "YES\n1 2 5 8\n3 4 6 7" }, { "input": "-725 1596\n155 -1000\n-758 1530\n-571 1376\n-1000 320\n-692 1497\n-659 1563\n584 56", "output": "NO" }, { "input": "-638 3887\n-1000 1896\n448 1353\n-95 4430\n-457 -1000\n-276 4611\n-95 4249\n-819 4068", "output": "NO" }, { "input": "216 0\n828 504\n648 612\n504 432\n756 792\n288 576\n0 144\n936 684", "output": "YES\n2 3 5 8\n1 4 6 7" }, { "input": "72 32\n4 40\n44 32\n32 0\n40 72\n20 16\n28 56\n0 40", "output": "YES\n2 3 6 7\n1 4 5 8" }, { "input": "457 -329\n-530 611\n-624 0\n-953 658\n-577 188\n-859 -141\n692 -188\n-1000 235", "output": "NO" }, { "input": "-841 -205\n590 -205\n-1000 -1000\n-364 1385\n-682 113\n-841 -1000\n-1000 -205\n908 1067", "output": "YES\n2 4 5 8\n1 3 6 7" }, { "input": "-1000 -604\n-604 1112\n-340 -736\n452 1376\n-604 -340\n-736 -1000\n716 320\n-340 56", "output": "YES\n1 3 5 6\n2 4 7 8" }, { "input": "-260 332\n-112 776\n776 184\n-1000 -1000\n-112 1368\n-852 36\n628 924\n36 36", "output": "NO" }, { "input": "600 0\n460 600\n500 960\n0 200\n660 760\n300 800\n100 500\n700 300", "output": "YES\n2 3 5 6\n1 4 7 8" }, { "input": "15 160\n-101 334\n-855 -1000\n-275 -101\n-1000 -855\n160 15\n160 -275\n334 160", "output": "YES\n2 4 7 8\n1 3 5 6" }, { "input": "0 108\n216 144\n480 360\n0 0\n60 108\n240 192\n60 0\n-24 -24", "output": "NO" }, { "input": "344 -200\n-200 -520\n-680 -1000\n280 -8\n-1000 -680\n536 -136\n-520 -200\n472 56", "output": "YES\n1 4 6 8\n2 3 5 7" }, { "input": "270 2024\n-486 -1000\n-162 2672\n162 2888\n540 728\n918 1862\n-864 1160\n486 2510", "output": "NO" }, { "input": "0 336\n128 80\n240 272\n0 0\n368 -112\n128 -256\n144 96\n464 64", "output": "NO" }, { "input": "-526 -447\n-1000 -526\n-526 -1000\n-131 -131\n-368 106\n185 -526\n-210 -842\n106 -368", "output": "YES\n1 4 6 7\n2 3 5 8" }, { "input": "648 440\n720 -1000\n0 -280\n-120 1520\n-840 2240\n720 488\n672 560\n600 512", "output": "NO" }, { "input": "-1000 568\n-432 639\n278 710\n-929 0\n-361 355\n-361 71\n-219 852\n136 213", "output": "YES\n1 2 4 6\n3 5 7 8" }, { "input": "-520 480\n-40 240\n-1000 240\n240 360\n-400 240\n-160 520\n-880 0\n120 640", "output": "YES\n2 4 6 8\n1 3 5 7" }, { "input": "270 225\n297 387\n315 135\n387 315\n45 0\n0 90\n225 297\n315 225", "output": "YES\n2 4 7 8\n1 3 5 6" }, { "input": "60 30\n0 18\n24 6\n81 36\n75 57\n18 24\n54 51\n6 0", "output": "YES\n1 4 5 7\n2 3 6 8" }, { "input": "134 -496\n-496 -118\n-748 8\n-1000 -748\n8 -244\n-370 134\n-622 260\n-874 -1000", "output": "YES\n2 3 6 7\n1 4 5 8" }, { "input": "1538 -718\n-1000 -718\n3277 -13\n3089 645\n3747 833\n-718 -1000\n3935 175\n1820 -1000", "output": "NO" }, { "input": "116 232\n87 0\n319 116\n203 174\n58 145\n174 0\n203 261\n0 58", "output": "YES\n3 5 6 7\n1 2 4 8" }, { "input": "-912 -296\n672 -560\n-472 -296\n-648 -208\n-648 1288\n-824 -1000\n-1000 -912\n936 1024", "output": "YES\n1 2 5 8\n3 4 6 7" }, { "input": "428 -796\n-592 -1000\n666 3318\n-1000 1856\n190 2842\n462 3454\n394 2706\n20 2060", "output": "NO" }, { "input": "684 399\n0 228\n570 342\n228 285\n342 0\n228 570\n570 855\n114 741", "output": "YES\n2 3 5 6\n1 4 7 8" }, { "input": "-1000 -373\n254 1090\n-791 672\n463 -164\n-373 -373\n-373 -1000\n-164 463\n672 45", "output": "YES\n2 3 5 8\n1 4 6 7" }, { "input": "-536 -304\n-536 508\n-768 -188\n-768 -1000\n-1000 -768\n160 276\n-72 -420\n-304 -536", "output": "YES\n2 3 6 7\n1 4 5 8" }, { "input": "120 30\n200 160\n130 0\n150 40\n40 200\n0 40\n160 10\n160 0", "output": "YES\n1 3 4 7\n2 5 6 8" }, { "input": "595 -159\n421 -565\n-275 -1000\n-275 -420\n189 15\n-1000 -1000\n-1000 -420\n15 -391", "output": "YES\n1 2 5 8\n3 4 6 7" }, { "input": "6 40\n0 35\n4 50\n5 0\n35 40\n40 5\n10 46\n0 44", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "360 300\n210 240\n240 90\n180 210\n150 390\n300 450\n0 120\n60 0", "output": "YES\n1 2 5 6\n3 4 7 8" }, { "input": "434 116\n434 426\n-186 -1000\n-186 -256\n0 116\n434 -628\n62 54\n372 488", "output": "NO" }, { "input": "520 -325\n260 0\n650 -455\n0 195\n130 390\n195 455\n455 260\n260 260", "output": "NO" }, { "input": "189 135\n261 153\n0 54\n81 0\n234 108\n216 180\n135 81\n54 135", "output": "YES\n1 2 5 6\n3 4 7 8" }, { "input": "864 -540\n972 -162\n342 216\n0 -324\n108 54\n468 378\n486 234\n324 360", "output": "NO" }, { "input": "265 220\n30 -60\n330 -420\n140 110\n15 0\n140 200\n15 90\n345 -480", "output": "NO" }, { "input": "94 112\n-190 360\n-280 0\n0 0\n94 84\n74 76\n114 120\n90 360", "output": "NO" }, { "input": "234 104\n0 52\n286 104\n598 624\n208 156\n182 520\n26 0\n702 208", "output": "YES\n3 4 6 8\n1 2 5 7" }, { "input": "0 304\n456 532\n532 304\n456 76\n304 380\n152 0\n608 228\n228 152", "output": "YES\n3 4 5 8\n1 2 6 7" }, { "input": "517 551\n940 786\n376 -13\n799 -1000\n-94 -154\n329 -906\n329 81\n-94 81", "output": "NO" }, { "input": "117 0\n195 312\n312 195\n0 117\n312 663\n195 390\n468 273\n585 546", "output": "YES\n5 6 7 8\n1 2 3 4" }, { "input": "646 102\n238 136\n102 510\n136 0\n578 578\n102 238\n0 102\n170 34", "output": "YES\n2 4 6 7\n1 3 5 8" }, { "input": "-856 -1000\n440 728\n728 296\n-1000 -856\n296 8\n-424 -280\n-280 -424\n8 440", "output": "YES\n2 3 5 8\n1 4 6 7" }, { "input": "160 120\n180 120\n340 140\n20 0\n320 300\n180 40\n160 280\n0 80", "output": "YES\n2 3 5 7\n1 4 6 8" }, { "input": "195 260\n533 390\n455 546\n0 65\n260 195\n65 0\n689 468\n611 624", "output": "YES\n2 3 7 8\n1 4 5 6" }, { "input": "123 0\n-410 123\n902 -123\n-82 369\n123 492\n0 492\n574 -369\n0 0", "output": "NO" }, { "input": "42 -168\n966 252\n462 126\n840 756\n336 630\n0 -588\n-252 -168\n-294 -588", "output": "NO" }, { "input": "280 480\n360 -80\n-1000 -640\n-200 -160\n-760 -1000\n-280 -160\n-280 400\n-40 -520", "output": "YES\n1 2 4 7\n3 5 6 8" }, { "input": "-622 315\n-1000 126\n-937 0\n-55 315\n-559 189\n-433 441\n-307 819\n71 693", "output": "YES\n4 6 7 8\n1 2 3 5" }, { "input": "410 533\n287 41\n615 164\n328 246\n697 451\n246 287\n0 246\n41 0", "output": "YES\n1 3 4 5\n2 6 7 8" }, { "input": "-919 0\n53 648\n-514 405\n-433 729\n-1000 162\n-28 162\n-433 243\n-514 243", "output": "YES\n2 4 6 8\n1 3 5 7" }, { "input": "-1000 276\n-586 828\n-34 414\n104 414\n-862 690\n-448 276\n-34 966\n-172 0", "output": "YES\n2 4 6 7\n1 3 5 8" }, { "input": "-544 -316\n140 368\n-1000 -772\n-316 -544\n-316 596\n-544 140\n-88 -88\n-772 -1000", "output": "YES\n2 5 6 7\n1 3 4 8" }, { "input": "980 -520\n860 -430\n620 -250\n500 -160\n20 1220\n-1000 980\n380 -760\n-640 -1000", "output": "NO" }, { "input": "432 -1000\n0 -1000\n0 -520\n432 -520\n864 104\n192 8\n960 -568\n288 -664", "output": "YES\n5 6 7 8\n1 2 3 4" }, { "input": "872 872\n-766 -1000\n170 -64\n1808 989\n1925 53\n989 -64\n-64 170\n-1000 -766", "output": "YES\n1 4 5 6\n2 3 7 8" }, { "input": "-620 -1000\n-430 -240\n45 -240\n-810 -145\n-145 520\n-715 -430\n-905 330\n-1000 -905", "output": "YES\n3 5 6 7\n1 2 4 8" }, { "input": "-316 684\n-1000 -228\n444 76\n520 152\n1204 380\n-316 0\n-240 0\n368 760", "output": "NO" }, { "input": "364 -688\n-260 248\n-312 40\n0 -532\n0 -792\n104 -792\n260 -428\n-52 -1000", "output": "NO" }, { "input": "96 180\n-204 108\n-144 36\n84 102\n-12 0\n0 6\n-72 72\n12 84", "output": "NO" }, { "input": "357 -1000\n119 190\n714 -48\n0 -643\n833 -524\n952 547\n476 -167\n357 785", "output": "YES\n2 3 6 8\n1 4 5 7" }, { "input": "598 368\n414 92\n0 0\n138 46\n368 322\n644 138\n138 0\n0 46", "output": "YES\n1 2 5 6\n3 4 7 8" }, { "input": "-480 -350\n-1000 -870\n-870 -1000\n-155 495\n-740 -285\n40 -870\n625 -90\n-350 -480", "output": "YES\n4 5 6 7\n1 2 3 8" }, { "input": "-340 1640\n-1000 650\n320 375\n705 485\n815 100\n430 -10\n-340 -10\n-1000 -1000", "output": "NO" }, { "input": "120 120\n105 30\n30 0\n0 75\n75 90\n90 165\n75 105\n45 135", "output": "YES\n2 3 4 7\n1 5 6 8" }, { "input": "840 980\n140 532\n980 840\n588 420\n700 868\n252 980\n140 0\n0 140", "output": "YES\n2 4 5 6\n1 3 7 8" }, { "input": "-244 -730\n512 998\n-460 -946\n728 1214\n-1000 -568\n728 -892\n80 -1000\n-352 -460", "output": "NO" }, { "input": "62 60\n54 50\n6 42\n64 42\n0 6\n36 0\n72 52\n42 36", "output": "YES\n1 2 4 7\n3 5 6 8" }, { "input": "-941 -1000\n-764 -410\n-823 -882\n-882 -823\n-1000 -941\n1006 298\n475 -941\n-233 829", "output": "YES\n2 6 7 8\n1 3 4 5" }, { "input": "360 648\n504 360\n0 360\n648 288\n288 504\n648 576\n288 0\n432 720", "output": "YES\n1 3 4 7\n2 5 6 8" }, { "input": "792 -648\n-352 -142\n704 -1000\n88 -472\n0 -824\n-682 1046\n572 -208\n242 980", "output": "NO" }, { "input": "-1000 176\n100 616\n-824 0\n-780 396\n-252 88\n-780 440\n-428 968\n-604 220", "output": "YES\n2 5 6 7\n1 3 4 8" }, { "input": "-1000 -580\n-1000 -1000\n330 960\n610 260\n-860 -580\n120 470\n-860 -1000\n820 750", "output": "YES\n3 4 6 8\n1 2 5 7" }, { "input": "0 -970\n90 -580\n585 500\n150 -880\n270 -400\n30 -1000\n405 320\n120 -850", "output": "NO" }, { "input": "600 500\n700 200\n600 180\n620 100\n700 120\n100 0\n680 200\n0 300", "output": "YES\n3 4 5 7\n1 2 6 8" }, { "input": "256 496\n304 512\n576 0\n320 464\n272 448\n0 64\n64 640\n640 576", "output": "YES\n1 2 4 5\n3 6 7 8" }, { "input": "128 112\n40 72\n64 96\n72 40\n80 32\n32 0\n0 32\n144 48", "output": "YES\n1 3 5 8\n2 4 6 7" }, { "input": "-1000 1052\n140 -392\n292 -1000\n900 -848\n-12 368\n672 -544\n748 -240\n-316 140", "output": "NO" }, { "input": "-208 -10\n188 -208\n386 188\n-505 -1000\n-505 -703\n-10 386\n-1000 -1000\n-1000 -703", "output": "YES\n1 2 3 6\n4 5 7 8" }, { "input": "153 102\n187 170\n102 153\n153 68\n0 51\n221 102\n51 0\n119 136", "output": "YES\n2 4 6 8\n1 3 5 7" }, { "input": "-1000 -60\n-342 -1000\n1444 -248\n1162 -718\n1538 -624\n1914 -530\n786 692\n2290 -436", "output": "NO" }, { "input": "3368 858\n-1000 -546\n1886 0\n3914 702\n3602 429\n3056 585\n-298 -780\n2588 -234", "output": "NO" }, { "input": "780 68\n424 -466\n68 -110\n246 424\n246 -466\n-110 -110\n-822 -1000\n-1000 -644", "output": "YES\n1 2 4 6\n3 5 7 8" }, { "input": "-372 93\n-403 31\n31 -31\n558 186\n248 434\n279 155\n0 -93\n527 465", "output": "NO" }, { "input": "-859 329\n-1000 141\n81 705\n-906 0\n-577 987\n-718 329\n-624 188\n-201 47", "output": "YES\n1 3 5 8\n2 4 6 7" }, { "input": "-97 -140\n290 -97\n290 935\n935 290\n-1000 -355\n-140 247\n247 290\n-355 -1000", "output": "YES\n1 2 6 7\n3 4 5 8" }, { "input": "426 518\n-609 449\n633 -1000\n-586 2220\n-954 2174\n-632 2588\n-1000 2542\n-816 1967", "output": "NO" }, { "input": "410 -754\n574 312\n82 66\n820 -180\n410 -1000\n0 -1000\n328 -426\n0 -754", "output": "YES\n2 3 4 7\n1 5 6 8" }, { "input": "-700 120\n-370 -90\n-40 510\n-490 150\n-1000 -60\n-670 -270\n-850 600\n-400 960", "output": "NO" }, { "input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n0 -10", "output": "NO" }, { "input": "100 100\n100 101\n101 100\n101 101\n0 0\n0 5\n10 5\n6 2", "output": "NO" }, { "input": "100 100\n100 101\n101 100\n101 101\n0 0\n1 5\n11 5\n10 0", "output": "NO" }, { "input": "0 0\n1 0\n0 1\n1 1\n100 100\n100 101\n101 100\n101 101", "output": "YES\n1 2 3 4\n5 6 7 8" }, { "input": "0 8\n-2 0\n-3 0\n0 -8\n2 0\n3 0\n0 2\n0 -2", "output": "NO" }, { "input": "-8 0\n0 -3\n8 0\n10000 10000\n9999 9999\n9999 10000\n0 3\n10000 9999", "output": "NO" }, { "input": "-8 0\n0 -3\n8 0\n10000 10000\n9998 9999\n9998 10000\n0 3\n10000 9999", "output": "NO" }, { "input": "10 10\n15 11\n15 9\n20 10\n100 100\n100 102\n107 102\n107 100", "output": "NO" }, { "input": "0 0\n5 0\n8 4\n3 4\n-2 -2\n-2 -1\n-1 -1\n-1 -2", "output": "NO" }, { "input": "0 0\n1 1\n2 2\n3 3\n4 4\n4 5\n5 4\n5 5", "output": "NO" }, { "input": "0 0\n0 1\n1 0\n1 1\n10 10\n14 10\n12 16\n12 20", "output": "NO" }, { "input": "0 0\n0 1\n1 0\n1 1\n2 0\n2 1\n3 1\n4 0", "output": "NO" }, { "input": "1 1\n1 2\n2 1\n2 2\n100 100\n101 100\n101 102\n102 102", "output": "NO" }, { "input": "0 0\n2 0\n2 2\n0 2\n1 1\n5 0\n5 2\n9 1", "output": "NO" }, { "input": "0 0\n0 1\n1 0\n1 1\n2 2\n3 2\n3 3\n4 3", "output": "NO" }, { "input": "4 1\n7 3\n9 4\n4 5\n1 3\n9 6\n12 4\n12 6", "output": "NO" }, { "input": "0 0\n3 0\n3 4\n6 4\n100 100\n101 100\n100 101\n101 101", "output": "NO" }, { "input": "1 0\n0 4\n2 4\n1 8\n15 15\n15 16\n18 15\n18 16", "output": "NO" }, { "input": "0 0\n0 1\n1 1\n1 0\n1000 1000\n1001 1003\n1004 1004\n1003 1001", "output": "NO" }, { "input": "1 0\n2 2\n0 2\n1 4\n7 0\n9 0\n7 1\n9 1", "output": "NO" }, { "input": "0 0\n1 0\n1 1\n0 1\n5 6\n100 190\n6 7\n10 196", "output": "NO" }, { "input": "0 0\n1 0\n2 0\n1 2\n50 50\n50 51\n51 51\n51 50", "output": "NO" } ]
186
204,800
-1
7,523
464
No to Palindromes!
[ "greedy", "strings" ]
null
null
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.
The first line contains two space-separated integers: *n* and *p* (1<=≀<=*n*<=≀<=1000; 1<=≀<=*p*<=≀<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
[ "3 3\ncba\n", "3 4\ncba\n", "4 4\nabcd\n" ]
[ "NO\n", "cbd\n", "abda\n" ]
String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i* + 1</sub> &gt; *t*<sub class="lower-index">*i* + 1</sub>. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string that reads the same forward or reversed.
[ { "input": "3 3\ncba", "output": "NO" }, { "input": "3 4\ncba", "output": "cbd" }, { "input": "4 4\nabcd", "output": "abda" }, { "input": "2 2\nab", "output": "ba" }, { "input": "2 2\nba", "output": "NO" }, { "input": "1 2\na", "output": "b" }, { "input": "1 2\nb", "output": "NO" }, { "input": "1 1\na", "output": "NO" }, { "input": "3 4\ncdb", "output": "dab" }, { "input": "7 26\nzyxzyxz", "output": "NO" }, { "input": "10 5\nabcabcabca", "output": "abcabcabcd" }, { "input": "10 10\nfajegfaicb", "output": "fajegfaicd" }, { "input": "1 26\no", "output": "p" }, { "input": "1 2\nb", "output": "NO" }, { "input": "1 26\nz", "output": "NO" }, { "input": "3 3\ncab", "output": "cba" }, { "input": "3 26\nyzx", "output": "zab" }, { "input": "5 5\naceba", "output": "acebc" }, { "input": "10 3\ncbacbacbac", "output": "NO" }, { "input": "11 3\nabcabcabcab", "output": "acbacbacbac" }, { "input": "12 10\nabcabcabcabc", "output": "abcabcabcabd" }, { "input": "13 7\ngfegfegfegfeg", "output": "NO" }, { "input": "15 11\ncgjkbadjfbdaikj", "output": "cgjkbadjfbdajba" }, { "input": "17 4\ndabcadcbdcadbcdbc", "output": "dabcadcbdcadcabca" }, { "input": "26 26\nahnxdnbfcriersyzdihuecojdi", "output": "ahnxdnbfcriersyzdihuecojdk" }, { "input": "30 7\ncedcfedcfgcfgcbadcadgfaegfacgf", "output": "cedcfedcfgcfgcbadcadgfaegfadba" }, { "input": "70 4\ndcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbd", "output": "NO" }, { "input": "77 7\ncadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacegfegfegf", "output": "cadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacfabcabcab" }, { "input": "100 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcd" }, { "input": "333 5\nedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedc", "output": "NO" }, { "input": "3 3\nacb", "output": "bac" }, { "input": "17 26\nbazyxzyxzyxzyxzyx", "output": "bcabcabcabcabcabc" }, { "input": "6 3\nacbacb", "output": "bacbac" }, { "input": "6 3\nabcabc", "output": "acbacb" }, { "input": "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcb", "output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac" }, { "input": "30 26\nabcabcabczyxzyxzyxzyxzyxzyxzyx", "output": "abcabcabdabcabcabcabcabcabcabc" }, { "input": "300 3\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc", "output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacb" }, { "input": "2 4\ncd", "output": "da" } ]
78
0
0
7,553
276
Little Girl and Maximum XOR
[ "bitmasks", "dp", "greedy", "implementation", "math" ]
null
null
A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≀<=*a*<=≀<=*b*<=≀<=*r*). Your task is to find the maximum value among all considered ones. Expression means applying bitwise excluding or operation to integers *x* and *y*. The given operation exists in all modern programming languages, for example, in languages *C*++ and *Java* it is represented as "^", in *Pascal* β€” as "xor".
The single line contains space-separated integers *l* and *r* (1<=≀<=*l*<=≀<=*r*<=≀<=1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
In a single line print a single integer β€” the maximum value of for all pairs of integers *a*, *b* (*l*<=≀<=*a*<=≀<=*b*<=≀<=*r*).
[ "1 2\n", "8 16\n", "1 1\n" ]
[ "3\n", "31\n", "0\n" ]
none
[ { "input": "1 2", "output": "3" }, { "input": "8 16", "output": "31" }, { "input": "1 1", "output": "0" }, { "input": "506 677", "output": "1023" }, { "input": "33 910", "output": "1023" }, { "input": "36 94", "output": "127" }, { "input": "10000000000 20000000000", "output": "34359738367" }, { "input": "79242383109441603 533369389165030783", "output": "576460752303423487" }, { "input": "797162752288318119 908416915938410706", "output": "576460752303423487" }, { "input": "230148668013473494 573330407369354716", "output": "576460752303423487" }, { "input": "668869743157683834 805679503731305624", "output": "288230376151711743" }, { "input": "32473107276976561 588384394540535099", "output": "1152921504606846975" }, { "input": "632668612680440378 864824360766754908", "output": "576460752303423487" }, { "input": "658472316271074503 728242833853270665", "output": "288230376151711743" }, { "input": "289218059048863941 314351197831808685", "output": "36028797018963967" }, { "input": "54248140375568203 718189790306910368", "output": "1152921504606846975" }, { "input": "330134158459714054 457118108955760856", "output": "288230376151711743" }, { "input": "190442232278841373 980738846929096255", "output": "1152921504606846975" }, { "input": "203359308073091683 455893840817516371", "output": "576460752303423487" }, { "input": "200851182089362664 449305852839820160", "output": "576460752303423487" }, { "input": "731792654005832175 789527173439457653", "output": "72057594037927935" }, { "input": "231465750142682282 276038074124518614", "output": "72057594037927935" }, { "input": "462451489958473150 957447393463701191", "output": "1152921504606846975" }, { "input": "68666076639301243 247574109010873331", "output": "288230376151711743" }, { "input": "491113582000560303 858928223424873439", "output": "1152921504606846975" }, { "input": "454452550141901489 843034681327343036", "output": "1152921504606846975" }, { "input": "43543567767276698 769776048133345296", "output": "1152921504606846975" }, { "input": "214985598536531449 956713939905291713", "output": "1152921504606846975" }, { "input": "56445001476501414 706930175458589379", "output": "1152921504606846975" }, { "input": "666033930784103123 883523065811761270", "output": "576460752303423487" }, { "input": "501827377176522663 590153819613032662", "output": "1152921504606846975" }, { "input": "140216419613864821 362678730465999561", "output": "576460752303423487" }, { "input": "23811264031960242 520940113721281721", "output": "576460752303423487" }, { "input": "43249439481689805 431488136320817289", "output": "576460752303423487" }, { "input": "198909890748296613 528950282310167050", "output": "576460752303423487" }, { "input": "190620774979376809 899159649449168622", "output": "1152921504606846975" }, { "input": "18565852953382418 697862904569985066", "output": "1152921504606846975" }, { "input": "277046860122752192 828379515775613732", "output": "1152921504606846975" }, { "input": "25785331761502790 119852560236585580", "output": "144115188075855871" }, { "input": "363313173638414449 500957528623228245", "output": "288230376151711743" }, { "input": "549330032897152846 715374717344043295", "output": "1152921504606846975" }, { "input": "47456305370335136 388462406071482688", "output": "576460752303423487" }, { "input": "125051194948742221 235911208585118006", "output": "288230376151711743" }, { "input": "780993382943360354 889872865454335075", "output": "576460752303423487" }, { "input": "815449097320007662 942453891178865528", "output": "576460752303423487" }, { "input": "765369978472937483 796958953973862258", "output": "144115188075855871" }, { "input": "259703440079833303 857510033561081530", "output": "1152921504606846975" }, { "input": "181513087965617551 301910258955864271", "output": "576460752303423487" }, { "input": "28591024119784617 732203343197854927", "output": "1152921504606846975" }, { "input": "215365547805299155 861595308221385098", "output": "1152921504606846975" }, { "input": "1 1000000000000000000", "output": "1152921504606846975" }, { "input": "1000000000000 999999999999999999", "output": "1152921504606846975" }, { "input": "1 1", "output": "0" }, { "input": "9999999999998 9999999999999", "output": "1" }, { "input": "9999999999900 9999999999901", "output": "1" }, { "input": "9999999999900 9999999999902", "output": "3" }, { "input": "9999999999900 9999999999903", "output": "3" }, { "input": "1 3", "output": "3" }, { "input": "5000000 5900000", "output": "2097151" }, { "input": "8589934592 8989934592", "output": "536870911" }, { "input": "1 288230376151711743", "output": "288230376151711743" } ]
30
0
0
7,558
765
Artsem and Saunders
[ "constructive algorithms", "dsu", "math" ]
null
null
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=β†’<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*. Now then, you are given a function *f*:<=[*n*]<=β†’<=[*n*]. Your task is to find a positive integer *m*, and two functions *g*:<=[*n*]<=β†’<=[*m*], *h*:<=[*m*]<=β†’<=[*n*], such that *g*(*h*(*x*))<==<=*x* for all , and *h*(*g*(*x*))<==<=*f*(*x*) for all , or determine that finding these is impossible.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integersΒ β€” values *f*(1),<=...,<=*f*(*n*) (1<=≀<=*f*(*i*)<=≀<=*n*).
If there is no answer, print one integer -1. Otherwise, on the first line print the number *m* (1<=≀<=*m*<=≀<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
[ "3\n1 2 3\n", "3\n2 2 2\n", "2\n2 1\n" ]
[ "3\n1 2 3\n1 2 3\n", "1\n1 1 1\n2\n", "-1\n" ]
none
[ { "input": "3\n1 2 3", "output": "3\n1 2 3\n1 2 3" }, { "input": "3\n2 2 2", "output": "1\n1 1 1\n2" }, { "input": "2\n2 1", "output": "-1" }, { "input": "1\n1", "output": "1\n1\n1" }, { "input": "2\n2 1", "output": "-1" }, { "input": "2\n2 2", "output": "1\n1 1\n2" }, { "input": "5\n5 5 5 3 5", "output": "-1" }, { "input": "10\n4 4 4 4 4 4 4 4 4 4", "output": "1\n1 1 1 1 1 1 1 1 1 1\n4" }, { "input": "2\n1 2", "output": "2\n1 2\n1 2" }, { "input": "3\n3 2 3", "output": "2\n2 1 2\n2 3" }, { "input": "3\n1 2 1", "output": "2\n1 2 1\n1 2" }, { "input": "4\n4 2 4 4", "output": "2\n2 1 2 2\n2 4" }, { "input": "5\n1 4 5 4 5", "output": "3\n1 2 3 2 3\n1 4 5" }, { "input": "4\n1 2 1 2", "output": "2\n1 2 1 2\n1 2" }, { "input": "5\n1 3 3 4 4", "output": "3\n1 2 2 3 3\n1 3 4" }, { "input": "4\n4 2 2 4", "output": "2\n2 1 1 2\n2 4" }, { "input": "7\n7 3 3 5 5 7 7", "output": "3\n3 1 1 2 2 3 3\n3 5 7" }, { "input": "6\n1 1 1 3 3 3", "output": "-1" }, { "input": "4\n2 2 3 2", "output": "2\n1 1 2 1\n2 3" }, { "input": "6\n1 2 3 4 5 5", "output": "5\n1 2 3 4 5 5\n1 2 3 4 5" }, { "input": "3\n1 1 2", "output": "-1" }, { "input": "4\n3 4 3 4", "output": "2\n1 2 1 2\n3 4" }, { "input": "6\n1 1 1 4 4 4", "output": "2\n1 1 1 2 2 2\n1 4" }, { "input": "4\n1 2 1 1", "output": "2\n1 2 1 1\n1 2" }, { "input": "5\n1 2 3 4 3", "output": "4\n1 2 3 4 3\n1 2 3 4" }, { "input": "4\n2 2 4 4", "output": "2\n1 1 2 2\n2 4" }, { "input": "4\n1 1 3 3", "output": "2\n1 1 2 2\n1 3" }, { "input": "3\n2 2 3", "output": "2\n1 1 2\n2 3" }, { "input": "5\n5 3 3 3 5", "output": "2\n2 1 1 1 2\n3 5" } ]
2,000
11,980,800
0
7,572
74
Room Leader
[ "implementation" ]
A. Room Leader
2
256
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document. In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five problems, *A*, *B*, *C*, *D* and *E*. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks. You are suggested to determine the leader for some room; the leader is a participant who has maximum points.
The first line contains an integer *n*, which is the number of contestants in the room (1<=≀<=*n*<=≀<=50). The next *n* lines contain the participants of a given room. The *i*-th line has the format of "*handle**i* *plus**i* *minus**i* *a**i* *b**i* *c**i* *d**i* *e**i*" β€” it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems *A*, *B*, *C*, *D*, *E* correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: - 0<=≀<=*plus**i*,<=*minus**i*<=≀<=50; - 150<=≀<=*a**i*<=≀<=500 or *a**i*<==<=0, if problem *A* is not solved; - 300<=≀<=*b**i*<=≀<=1000 or *b**i*<==<=0, if problem *B* is not solved; - 450<=≀<=*c**i*<=≀<=1500 or *c**i*<==<=0, if problem *C* is not solved; - 600<=≀<=*d**i*<=≀<=2000 or *d**i*<==<=0, if problem *D* is not solved; - 750<=≀<=*e**i*<=≀<=2500 or *e**i*<==<=0, if problem *E* is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).
Print on the single line the handle of the room leader.
[ "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n" ]
[ "tourist" ]
The number of points that each participant from the example earns, are as follows: - Petr β€” 3860 - tourist β€” 4140 - Egor β€” 4030 - c00lH4x0R β€”  - 350 - some_participant β€” 2220 Thus, the leader of the room is tourist.
[ { "input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "output": "tourist" }, { "input": "1\nA 0 0 200 0 0 0 0", "output": "A" }, { "input": "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0", "output": "_" }, { "input": "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600 2000\nEf 0 0 480 900 1200 1600 2000\ngH 0 0 480 900 1200 1599 2000\nij 0 0 480 900 1199 1600 2001", "output": "Ab" }, { "input": "4\nF1 0 0 150 0 0 0 0\nF2 0 1 0 0 0 0 0\nF3 0 2 0 0 0 0 0\nF4 0 3 0 0 0 0 0", "output": "F1" }, { "input": "2\nA87h 5 0 199 0 0 0 0\nBcfg 7 0 0 0 0 0 0", "output": "Bcfg" }, { "input": "10\nKh 40 26 0 0 0 0 1243\nn 46 50 500 0 910 1912 0\nU 18 1 182 0 457 0 0\nFth6A0uT6i 38 30 0 787 0 1121 0\nC5l 24 38 0 689 1082 0 0\nN 47 25 0 0 1065 0 1538\nznyL 9 24 0 315 0 0 0\nJ0kU 27 47 445 0 0 0 0\nlT0rwiD2pg 46 13 0 818 0 0 0\nuJzr 29 14 0 0 0 0 2387", "output": "N" }, { "input": "2\nminus_one 0 4 199 0 0 0 0\nminus_two 0 4 198 0 0 0 0", "output": "minus_one" }, { "input": "10\nW22kb1L1 0 39 0 465 0 1961 865\n1MCXiVYmu5ys0afl 0 38 0 0 0 1982 1241\nCxg706kUJtQ 0 23 211 0 0 1785 1056\nmzEY 0 16 0 0 0 1988 1404\nv8JUjmam5SFP 0 48 0 788 1199 1426 0\n7giq 0 21 0 780 1437 1363 1930\nsXsUGbAulj6Lbiq 0 32 205 0 0 603 0\nRepIrY1Er4PgK 0 13 381 872 927 1488 0\nleKBdKHLnLFz 0 29 220 0 0 1006 889\nD 0 26 497 0 0 0 1815", "output": "7giq" }, { "input": "1\nZ 0 0 0 0 0 0 0", "output": "Z" }, { "input": "3\nAbcd 0 4 189 0 0 0 0\nDefg 0 5 248 0 0 0 0\nGhh 1 3 0 0 0 0 0", "output": "Defg" }, { "input": "3\ndf 0 6 0 0 0 0 0\njnm 1 8 300 0 0 0 0\n_ub_ 3 20 300 310 0 0 0", "output": "jnm" }, { "input": "1\njhgcyt 0 50 0 0 0 0 0", "output": "jhgcyt" }, { "input": "2\njhv 0 50 500 1000 1500 2000 2500\nPetr 2 1 489 910 1100 1300 1000", "output": "jhv" }, { "input": "3\nufu 0 50 0 0 0 0 0\nhzEr65f 1 50 0 0 0 0 0\nytdttjfhfd 0 50 150 0 0 0 0", "output": "ytdttjfhfd" }, { "input": "5\nufuf 0 50 0 0 0 0 0\nyfycy 50 0 500 1000 1500 2000 2500\n__u77 6 7 490 999 1456 1976 1356\n0 1 2 0 0 0 0 2452\ngu7fF 50 0 500 1000 1500 2000 2499", "output": "yfycy" }, { "input": "2\nhfy 0 50 0 0 0 0 2500\nugug 0 50 0 0 0 0 2499", "output": "hfy" }, { "input": "8\nA 0 0 0 0 0 0 0\nb 0 0 0 0 0 0 0\nc 0 0 0 0 0 0 0\nD 0 0 0 0 0 0 0\nE 1 0 0 0 0 0 0\nF 0 0 0 0 0 0 0\ng 0 0 0 0 0 0 0\nH 0 0 0 0 0 0 0", "output": "E" }, { "input": "2\nyyyc 50 50 0 0 0 0 0\nydd 0 0 0 0 0 0 2499", "output": "yyyc" }, { "input": "2\ntom 0 2 0 0 0 0 0\nmac 0 1 0 0 0 0 0", "output": "mac" }, { "input": "1\ncool 0 10 0 0 0 0 0", "output": "cool" } ]
124
0
0
7,595
121
Lucky Transformation
[ "strings" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it *d*. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation *k* times: find the minimum *x* (1<=≀<=*x*<=&lt;<=*n*) such that *d**x*<==<=4 and *d**x*<=+<=1<==<=7, if *x* is odd, then to assign *d**x*<==<=*d**x*<=+<=1<==<=4, otherwise to assign *d**x*<==<=*d**x*<=+<=1<==<=7. Note that if no *x* was found, then the operation counts as completed and the array doesn't change at all. You are given the initial number as an array of digits and the number *k*. Help Petya find the result of completing *k* operations.
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105,<=0<=≀<=*k*<=≀<=109) β€” the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the number does not equal zero.
In the single line print the result without spaces β€” the number after the *k* operations are fulfilled.
[ "7 4\n4727447\n", "4 2\n4478\n" ]
[ "4427477\n", "4478\n" ]
In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477. In the second sample: 4478 → 4778 → 4478.
[ { "input": "7 4\n4727447", "output": "4427477" }, { "input": "4 2\n4478", "output": "4478" }, { "input": "7 7\n4211147", "output": "4211177" }, { "input": "7 6\n4747477", "output": "4444477" }, { "input": "10 2\n9474444474", "output": "9774444774" }, { "input": "10 47\n4214777477", "output": "4217777777" }, { "input": "3 99\n447", "output": "477" }, { "input": "4 1000000000\n7747", "output": "7744" }, { "input": "3 1000000000\n447", "output": "447" }, { "input": "3 100\n447", "output": "447" }, { "input": "7 74\n4777774", "output": "4777774" }, { "input": "10 200\n6860544593", "output": "6860544593" }, { "input": "10 477\n5837934237", "output": "5837934237" }, { "input": "47 7477\n83492039276961836565341994102530448486552156001", "output": "83492039276961836565341994102530448486552156001" }, { "input": "100 0\n9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827", "output": "9179665522184092255095619209953008761499858159751083177424923082479016015954927554823400601862864827" }, { "input": "485 9554485\n77591213686327368525391827531734680282181149581181587323024775516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722", "output": "77591213686327368525391827531734680282181149581181587323024475516707756080151536104831756264659461447807315739541829004122483827102803764919259852061561098901393332937462039404423475012940096002301663119780442182470831027122573263011092200024968051233448164275142862251531399243063800892848783227559284462449919786387761960941614255036371684927500361571685732032325070607701306810264624073744998990612133986362972207072576588540217974702060321406370425911824802563123926135054749895722" }, { "input": "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773", "output": "44437850490316923506619313449771062875964157742919669484484624083960118773" }, { "input": "47 7\n77774477747474477477477774747747447447774777474", "output": "77774777747474477477477774747747447447774777474" }, { "input": "100 2\n7477774774777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444", "output": "7777774474777474774777777474474474744477777477774444477444774474477774777474774744477474744474777444" }, { "input": "99 1\n474747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477", "output": "444747444774447474444477474747774774447444477744774744477747777474777774777474477744447447447447477" }, { "input": "74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444", "output": "77444444774774747474777447474777777477474444477747444777447444474744744444" }, { "input": "74 999999999\n47474777744447477747777774774777447474747747447744474777477474777774774447", "output": "44444477744447477747777774774777447474747747447744474777477474777774774447" }, { "input": "100 47\n4346440647444704624490777777537777677744747437443404484777536674477779371445774947477174444474400267", "output": "4346440644444404624490777777537777677747747437443404484777536674477779371445774947477174444474400267" }, { "input": "100 1000000000\n5849347454478644774747479437170493249634474874684784475734456487776740780444477442497447771444047377", "output": "5849377454448644774747479437170493249634474874684784475734456487776740780444477442497447771444047377" }, { "input": "154 96\n7967779274474413067517474773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487", "output": "7967779274444413067517444773015431177704444740654941743448963746454006444442746745494233876247994374947948475494434494479684421447774484909784471488747487" }, { "input": "2 0\n47", "output": "47" }, { "input": "5 0\n12473", "output": "12473" } ]
62
0
0
7,599
45
Director
[ "constructive algorithms", "greedy" ]
E. Director
2
256
Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a list of *n* names and *n* surnames that he wants to use. Vasya haven't decided yet how to call characters, so he is free to match any name to any surname. Now he has to make the list of all the main characters in the following format: "*Name*1 *Surname*1, *Name*2 *Surname*2, ..., *Name**n* *Surname**n*", i.e. all the name-surname pairs should be separated by exactly one comma and exactly one space, and the name should be separated from the surname by exactly one space. First of all Vasya wants to maximize the number of the pairs, in which the name and the surname start from one letter. If there are several such variants, Vasya wants to get the lexicographically minimal one. Help him. An answer will be verified a line in the format as is shown above, including the needed commas and spaces. It's the lexicographical minimality of such a line that needs to be ensured. The output line shouldn't end with a space or with a comma.
The first input line contains number *n* (1<=≀<=*n*<=≀<=100) β€” the number of names and surnames. Then follow *n* lines β€” the list of names. Then follow *n* lines β€” the list of surnames. No two from those 2*n* strings match. Every name and surname is a non-empty string consisting of no more than 10 Latin letters. It is guaranteed that the first letter is uppercase and the rest are lowercase.
The output data consist of a single line β€” the needed list. Note that one should follow closely the output data format!
[ "4\nAnn\nAnna\nSabrina\nJohn\nPetrov\nIvanova\nStoltz\nAbacaba\n", "4\nAa\nAb\nAc\nBa\nAd\nAe\nBb\nBc\n" ]
[ "Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz", "Aa Ad, Ab Ae, Ac Bb, Ba Bc" ]
none
[ { "input": "4\nAnn\nAnna\nSabrina\nJohn\nPetrov\nIvanova\nStoltz\nAbacaba", "output": "Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz" }, { "input": "4\nAa\nAb\nAc\nBa\nAd\nAe\nBb\nBc", "output": "Aa Ad, Ab Ae, Ac Bb, Ba Bc" }, { "input": "5\nDa\nEcccdbbdc\nD\nEabbd\nFaafbfdffa\nFdfdd\nEabececb\nFaacca\nFdbfa\nEb", "output": "D Faacca, Da Fdbfa, Eabbd Eabececb, Ecccdbbdc Eb, Faafbfdffa Fdfdd" }, { "input": "5\nCcbcbaba\nAb\nCbcbcc\nCac\nCba\nCacabbabbb\nAacacbcac\nAacbc\nBbccc\nBbbb", "output": "Ab Aacacbcac, Cac Aacbc, Cba Bbbb, Cbcbcc Bbccc, Ccbcbaba Cacabbabbb" }, { "input": "6\nEjcohjns\nUl\nBaedlgrca\nGorslqhfum\nLqdujfs\nIlmrum\nRoimgd\nJg\nEnsgdl\nJ\nPrsraiotmm\nDougis", "output": "Baedlgrca Dougis, Ejcohjns Ensgdl, Gorslqhfum J, Ilmrum Jg, Lqdujfs Prsraiotmm, Ul Roimgd" }, { "input": "4\nIdaig\nCe\nDdgage\nGggej\nHbagbcgi\nEdgag\nJibgdcegia\nGjbjhji", "output": "Ce Edgag, Ddgage Hbagbcgi, Gggej Gjbjhji, Idaig Jibgdcegia" }, { "input": "2\nHpmftejsc\nPisqmdpgtj\nStfooeeqct\nLicklrsed", "output": "Hpmftejsc Licklrsed, Pisqmdpgtj Stfooeeqct" }, { "input": "6\nEjihbjb\nGlaefbebla\nAbl\nAickhgcjh\nFbggidc\nCbjamddcj\nMjejakadle\nE\nDbbic\nHkeb\nKiblfdlhh\nAgbljbif", "output": "Abl Agbljbif, Aickhgcjh Dbbic, Cbjamddcj Hkeb, Ejihbjb E, Fbggidc Kiblfdlhh, Glaefbebla Mjejakadle" }, { "input": "3\nB\nBabcac\nCbbbbbcbb\nCcbbca\nAabbb\nBbbaaacac", "output": "B Aabbb, Babcac Bbbaaacac, Cbbbbbcbb Ccbbca" }, { "input": "5\nBwoxkhem\nDbxx\nOjnwf\nWlbppd\nLdj\nGjvgshfuwf\nMfvk\nEcnmumgdl\nKdwkdl\nVogl", "output": "Bwoxkhem Ecnmumgdl, Dbxx Gjvgshfuwf, Ldj Kdwkdl, Ojnwf Mfvk, Wlbppd Vogl" }, { "input": "1\nC\nAccccabcaa", "output": "C Accccabcaa" }, { "input": "3\nBoojbn\nDhhfjq\nLjgjigqh\nP\nKjaqjqh\nIc", "output": "Boojbn Ic, Dhhfjq Kjaqjqh, Ljgjigqh P" }, { "input": "5\nIqrelephj\nOeigtjab\nG\nEqifrkd\nMif\nTcaoagse\nOgho\nIqd\nMqm\nDis", "output": "Eqifrkd Dis, G Tcaoagse, Iqrelephj Iqd, Mif Mqm, Oeigtjab Ogho" }, { "input": "3\nGefdaeg\nCedfadf\nAgae\nBbcgabbfb\nF\nFefffggg", "output": "Agae Bbcgabbfb, Cedfadf F, Gefdaeg Fefffggg" }, { "input": "2\nEfgiiibfe\nFiegcbdb\nDdhcehah\nChccffg", "output": "Efgiiibfe Chccffg, Fiegcbdb Ddhcehah" }, { "input": "2\nPqlkixrw\nSw\nSegmd\nPqexkldse", "output": "Pqlkixrw Pqexkldse, Sw Segmd" }, { "input": "6\nAaccaca\nCc\nCac\nBc\nCaabccaa\nAbcbcabaac\nBaa\nCacacc\nCbcc\nAaca\nBbcaaca\nBbabcaabb", "output": "Aaccaca Aaca, Abcbcabaac Baa, Bc Bbabcaabb, Caabccaa Bbcaaca, Cac Cacacc, Cc Cbcc" }, { "input": "4\nSpg\nPvdpe\nKralfi\nTmlbhakxm\nR\nGskc\nPpowufk\nNpacfrtofl", "output": "Kralfi Gskc, Pvdpe Ppowufk, Spg Npacfrtofl, Tmlbhakxm R" }, { "input": "6\nOjli\nPpfoa\nJhlnelagb\nDng\nDfrofipdh\nKjhpfopf\nI\nG\nObr\nJlllilo\nMjhbqmjbn\nMqecfqgnfl", "output": "Dfrofipdh G, Dng I, Jhlnelagb Jlllilo, Kjhpfopf Mjhbqmjbn, Ojli Obr, Ppfoa Mqecfqgnfl" }, { "input": "5\nFdhfae\nDdfci\nBaahh\nA\nCfghicabbg\nFa\nHcha\nAgfcghdbhc\nCidece\nCaieed", "output": "A Agfcghdbhc, Baahh Caieed, Cfghicabbg Cidece, Ddfci Hcha, Fdhfae Fa" }, { "input": "6\nImlichb\nAc\nHibm\nB\nJddle\nI\nEjaa\nIemfcgdi\nBbgh\nBik\nHb\nCkedal", "output": "Ac Bbgh, B Bik, Hibm Hb, I Ckedal, Imlichb Iemfcgdi, Jddle Ejaa" }, { "input": "2\nAfmu\nJalbdpdrpe\nCrifng\nQhhlrm", "output": "Afmu Crifng, Jalbdpdrpe Qhhlrm" }, { "input": "3\nKierslt\nK\nMebfcbg\nRar\nOddrlc\nFhbojgofe", "output": "K Fhbojgofe, Kierslt Oddrlc, Mebfcbg Rar" }, { "input": "5\nAbbaab\nBaabbbaaab\nAbabbbbaa\nBab\nAbabbb\nBbab\nAabaababaa\nBbbbaaab\nA\nBaa", "output": "Ababbb A, Ababbbbaa Aabaababaa, Abbaab Baa, Baabbbaaab Bbab, Bab Bbbbaaab" }, { "input": "4\nDgjlfdie\nDdi\nLhgdmndo\nKh\nFob\nJikoafoe\nNkldlh\nGhcnolfe", "output": "Ddi Fob, Dgjlfdie Ghcnolfe, Kh Jikoafoe, Lhgdmndo Nkldlh" }, { "input": "3\nBf\nDegagfdc\nGcbbcfcfg\nE\nFbfgdaefga\nEeaccga", "output": "Bf E, Degagfdc Eeaccga, Gcbbcfcfg Fbfgdaefga" }, { "input": "5\nEdgkkkij\nKefhijgdbd\nGakfh\nJaiccfkeg\nCgaikgj\nHccigee\nKibjhea\nJjdibe\nIfbja\nDfdkda", "output": "Cgaikgj Dfdkda, Edgkkkij Hccigee, Gakfh Ifbja, Jaiccfkeg Jjdibe, Kefhijgdbd Kibjhea" }, { "input": "4\nXvlusvjxn\nUb\nWgraue\nFuu\nVx\nKglmq\nNlnb\nVctx", "output": "Fuu Kglmq, Ub Nlnb, Wgraue Vctx, Xvlusvjxn Vx" }, { "input": "4\nM\nHbhqeqoq\nEfhomepaj\nApjqkep\nGdmba\nGqgkn\nInock\nCpknlkn", "output": "Apjqkep Cpknlkn, Efhomepaj Gdmba, Hbhqeqoq Gqgkn, M Inock" }, { "input": "3\nMslgbylj\nIrhlscuce\nYkgty\nEsvtwml\nRw\nXhnnbck", "output": "Irhlscuce Esvtwml, Mslgbylj Rw, Ykgty Xhnnbck" }, { "input": "4\nIjmgnm\nBmj\nNg\nEci\nNfkfammhaf\nJf\nBgbekid\nHfg", "output": "Bmj Bgbekid, Eci Hfg, Ijmgnm Jf, Ng Nfkfammhaf" }, { "input": "6\nEoic\nHqrdefsgos\nAoqkqn\nKkfigffj\nCbebkk\nHq\nCqqooafpmi\nEdjsgedhbk\nD\nF\nMc\nEqlrqadms", "output": "Aoqkqn D, Cbebkk Cqqooafpmi, Eoic Edjsgedhbk, Hq Eqlrqadms, Hqrdefsgos F, Kkfigffj Mc" }, { "input": "1\nOhhjpmpbn\nCwbungcfb", "output": "Ohhjpmpbn Cwbungcfb" }, { "input": "5\nEdbbdfaedb\nBfcd\nCaabfbda\nB\nCdefcae\nAdf\nCda\nCaabafcdda\nCfbbdcc\nEeafc", "output": "B Adf, Bfcd Caabafcdda, Caabfbda Cda, Cdefcae Cfbbdcc, Edbbdfaedb Eeafc" }, { "input": "1\nRf\nBkppbiog", "output": "Rf Bkppbiog" }, { "input": "6\nJcv\nRhpqmxtlf\nXrgwns\nGvkkdcgtif\nWgkegia\nNsknu\nAahxuoqsb\nWbfgaujsu\nOd\nPbcll\nKctij\nI", "output": "Gvkkdcgtif Aahxuoqsb, Jcv I, Nsknu Kctij, Rhpqmxtlf Od, Wgkegia Wbfgaujsu, Xrgwns Pbcll" }, { "input": "1\nA\nPlttvbsja", "output": "A Plttvbsja" }, { "input": "6\nInddf\nBode\nAdmjl\nConnfj\nPioermlko\nIdjb\nPjkqhifk\nBrpoddj\nEdce\nQn\nMlpqpjrca\nPlmjbm", "output": "Admjl Edce, Bode Brpoddj, Connfj Mlpqpjrca, Idjb Pjkqhifk, Inddf Qn, Pioermlko Plmjbm" }, { "input": "4\nFcdadef\nCdiggdjbff\nCjih\nEc\nFedicjef\nDea\nF\nHhhcb", "output": "Cdiggdjbff Dea, Cjih F, Ec Hhhcb, Fcdadef Fedicjef" }, { "input": "4\nIhleenbko\nL\nFghncegei\nCd\nOggiiijm\nOecfbjb\nEmjbl\nDfl", "output": "Cd Dfl, Fghncegei Emjbl, Ihleenbko Oecfbjb, L Oggiiijm" }, { "input": "6\nTbhssirfl\nL\nS\nTmorp\nIqnqdcdj\nTcq\nJf\nLenc\nPp\nEdiphdpit\nJeo\nHenqjik", "output": "Iqnqdcdj Ediphdpit, L Lenc, S Henqjik, Tbhssirfl Jeo, Tcq Jf, Tmorp Pp" }, { "input": "5\nAbacbba\nBccaa\nBbabcaac\nA\nB\nBccc\nAcaa\nCbbaababa\nBcab\nCaa", "output": "A Acaa, Abacbba Caa, B Bcab, Bbabcaac Bccc, Bccaa Cbbaababa" }, { "input": "6\nIwmuivuiaj\nW\nKjp\nSankublv\nTkvmaci\nWblqalbflu\nEvtce\nFsd\nD\nWkrpnrirmj\nJodiiwh\nWbrh", "output": "Iwmuivuiaj D, Kjp Evtce, Sankublv Fsd, Tkvmaci Jodiiwh, W Wbrh, Wblqalbflu Wkrpnrirmj" }, { "input": "1\nEbac\nEddddaccef", "output": "Ebac Eddddaccef" }, { "input": "5\nCi\nHih\nDcg\nIib\nGcjk\nDaahii\nEajega\nAd\nIifdcbd\nJdgghe", "output": "Ci Ad, Dcg Daahii, Gcjk Eajega, Hih Jdgghe, Iib Iifdcbd" }, { "input": "5\nEf\nFfbihdj\nDjj\nAigcgdh\nFdbf\nJcihgfbda\nHaacdfi\nBaicd\nAdbeich\nAdd", "output": "Aigcgdh Adbeich, Djj Add, Ef Baicd, Fdbf Haacdfi, Ffbihdj Jcihgfbda" }, { "input": "5\nGdbb\nFgfa\nBafdfdaa\nCbac\nGc\nCeeefadc\nF\nAeefebcgg\nBcgcgcd\nFceagggf", "output": "Bafdfdaa Bcgcgcd, Cbac Ceeefadc, Fgfa F, Gc Aeefebcgg, Gdbb Fceagggf" }, { "input": "6\nBelandfa\nFnacibcm\nFkknhml\nFa\nJdkcghgnlj\nGgainlk\nHlehcg\nAbeb\nFffbgmndb\nMmacnfmma\nBbcfilh\nBdbe", "output": "Belandfa Bbcfilh, Fa Abeb, Fkknhml Bdbe, Fnacibcm Fffbgmndb, Ggainlk Hlehcg, Jdkcghgnlj Mmacnfmma" }, { "input": "1\nLukbme\nOviewxi", "output": "Lukbme Oviewxi" }, { "input": "4\nQ\nHkbnq\nQmocp\nLramnhhe\nNoag\nQnd\nBmrhoio\nLrkgag", "output": "Hkbnq Bmrhoio, Lramnhhe Lrkgag, Q Noag, Qmocp Qnd" }, { "input": "3\nHjii\nCdh\nEahejg\nAcbjhb\nDebe\nJahibe", "output": "Cdh Acbjhb, Eahejg Debe, Hjii Jahibe" }, { "input": "3\nBnoajel\nRpoannipj\nQbqlm\nGcjdornkri\nNloimkdkki\nAcb", "output": "Bnoajel Acb, Qbqlm Gcjdornkri, Rpoannipj Nloimkdkki" }, { "input": "4\nPpw\nHbw\nVqvcitemnh\nJkmwcaa\nWd\nEoxyhbhb\nPl\nE", "output": "Hbw E, Jkmwcaa Eoxyhbhb, Ppw Pl, Vqvcitemnh Wd" }, { "input": "6\nEu\nKzdawsv\nQh\nE\nGtsphxqhdu\nHylhnikwvi\nMcbstghhx\nKcjznnkj\nJgsdy\nXedwpmsmxm\nWrlxctnebt\nKsvg", "output": "E Jgsdy, Eu Kcjznnkj, Gtsphxqhdu Mcbstghhx, Hylhnikwvi Wrlxctnebt, Kzdawsv Ksvg, Qh Xedwpmsmxm" }, { "input": "10\nVince\nH\nEpcenhj\nBvjvgbsnfi\nTtrrj\nHj\nPmdmxijz\nDxbrldlq\nCimweepkgg\nYsrwelodpn\nOtep\nBpvkrdh\nKjftlvnxib\nHxquwm\nSfvnmwpapd\nYioxis\nYh\nLyiaq\nMecpx\nIno", "output": "Bvjvgbsnfi Bpvkrdh, Cimweepkgg Ino, Dxbrldlq Kjftlvnxib, Epcenhj Lyiaq, H Hxquwm, Hj Mecpx, Pmdmxijz Otep, Ttrrj Sfvnmwpapd, Vince Yh, Ysrwelodpn Yioxis" }, { "input": "14\nCfmtbejyil\nEcg\nZs\nBfdq\nFvn\nIbsyysduj\nFmyz\nNttfwibmrl\nCcewi\nD\nFclpflh\nEdatolifm\nOv\nLtvbit\nJvyejz\nVrfcdcrczk\nJqagz\nJmwonbdcc\nRpjbc\nV\nBaslqgpi\nF\nAhfzuqlbir\nUn\nXcjiakbv\nUlkd\nPlrcdqe\nOjn", "output": "Bfdq Baslqgpi, Ccewi Ahfzuqlbir, Cfmtbejyil Jmwonbdcc, D Jqagz, Ecg Jvyejz, Edatolifm Plrcdqe, Fclpflh F, Fmyz Rpjbc, Fvn Ulkd, Ibsyysduj Un, Ltvbit V, Nttfwibmrl Vrfcdcrczk, Ov Ojn, Zs Xcjiakbv" }, { "input": "18\nPbojywwn\nYsiaz\nOfre\nAiamkh\nGamwmfr\nAceuyny\nLtwdwqkm\nFfqb\nBa\nFzoiug\nWxzhg\nWabuxabbcq\nV\nRjw\nGl\nBtt\nLhr\nKcollntp\nQdofbu\nVxnotvwp\nVaehi\nJusoeed\nF\nNonfp\nB\nJfca\nRyfv\nR\nH\nRyqqz\nIulhooucxa\nBbojrvmb\nNbwhugpj\nLhuqkkxabp\nIjwbdoqi\nUopmvlbmn", "output": "Aceuyny H, Aiamkh Ijwbdoqi, Ba B, Btt Bbojrvmb, Ffqb F, Fzoiug Iulhooucxa, Gamwmfr Jfca, Gl Jusoeed, Kcollntp Nbwhugpj, Lhr Lhuqkkxabp, Ltwdwqkm Nonfp, Ofre Qdofbu, Pbojywwn R, Rjw Ryfv, V Vaehi, Wabuxabbcq Ryqqz, Wxzhg Uopmvlbmn, Ysiaz Vxnotvwp" }, { "input": "25\nQoencmxtab\nMcvr\nBqddqxfah\nWjkqwzvwyh\nCckohnzqf\nZnj\nWxfgfjy\nGh\nQcjt\nN\nTglhmv\nVictke\nNckac\nOun\nLlfmyajvg\nIteljso\nWcgs\nRhfy\nNgyuogj\nTgt\nBxvqp\nRjfowcdrdt\nRah\nNaok\nH\nFtagofc\nXwvkdup\nJlulb\nKpdptl\nLjt\nOrj\nRzpn\nKbmk\nMchws\nIwryj\nNmwae\nAigclj\nMuypjgnakb\nFsls\nPght\nHbhxt\nZkaymuiz\nDgcxsa\nHrplllthbi\nOjdh\nPc\nPqqwi\nA\nVtvwkrj\nFyrg", "output": "Bqddqxfah A, Bxvqp Aigclj, Cckohnzqf Dgcxsa, Gh Fsls, H Hbhxt, Iteljso Iwryj, Llfmyajvg Ljt, Mcvr Mchws, N Ftagofc, Naok Fyrg, Nckac Hrplllthbi, Ngyuogj Nmwae, Oun Ojdh, Qcjt Jlulb, Qoencmxtab Kbmk, Rah Kpdptl, Rhfy Muypjgnakb, Rjfowcdrdt Rzpn, Tglhmv Orj, Tgt Pc, Victke Vtvwkrj, Wcgs Pght, Wjkqwzvwyh Pqqwi, Wxfgfjy Xwvkdup, Znj Zkaymuiz" }, { "input": "30\nLkrvu\nOjzefo\nBbncywtbeh\nGm\nQfgyxlwl\nJich\nFafqqx\nPbvx\nKqpydmiudv\nZeudtwvz\nBywnnrcabi\nMnpicakfk\nB\nQfe\nXwnwyri\nRniaxikzx\nIhyinmj\nMx\nXniayl\nLvpst\nQticaoi\nPtzr\nYqmoq\nQgbgilbsu\nVkiwq\nEuzrovcmh\nXctnh\nYekughfot\nEmpastx\nXuwxqax\nRysjtsnvh\nDgthyxds\nIu\nMabdjdt\nNesvooryoa\nIr\nH\nTuoja\nEiblvkho\nScnirn\nKpmwnlet\nX\nUqmpa\nExxrtlk\nBiyvlaahvk\nSagfftl\nIjay\nCyrz\nErfkjemdna\nNqii\nQvsafpwxe\nXxmlrb\nBwfbcqw\nEhvizbxix\nEnnctyw\nBnnlwit\nHmmkbvol\nErgujvfsq\nOkurybmipc\nDryzynlu", "output": "B Biyvlaahvk, Bbncywtbeh Bnnlwit, Bywnnrcabi Bwfbcqw, Empastx Ehvizbxix, Euzrovcmh Eiblvkho, Fafqqx Cyrz, Gm Dgthyxds, Ihyinmj Ijay, Jich Dryzynlu, Kqpydmiudv Kpmwnlet, Lkrvu Ennctyw, Lvpst Erfkjemdna, Mnpicakfk Ergujvfsq, Mx Mabdjdt, Ojzefo Okurybmipc, Pbvx Exxrtlk, Ptzr H, Qfe Hmmkbvol, Qfgyxlwl Ir, Qgbgilbsu Iu, Qticaoi Qvsafpwxe, Rniaxikzx Rysjtsnvh, Vkiwq Nesvooryoa, Xctnh Nqii, Xniayl Sagfftl, Xuwxqax X, Xwnwyri Xxmlrb, Yekughfot Scnirn, Yqmoq Tuoja, Zeudtwvz Uqmpa" }, { "input": "4\nU\nOjrbfile\nWfzntvwg\nEjmsrokmfp\nEhlzpo\nZj\nThhjz\nKqbaidjmu", "output": "Ejmsrokmfp Ehlzpo, Ojrbfile Kqbaidjmu, U Thhjz, Wfzntvwg Zj" }, { "input": "6\nDmdqeyhvbm\nTbhmfsimms\nDmssv\nVufczejycy\nIbqholfugr\nAvshkju\nVxfnonsgba\nGcj\nWtwqf\nKuome\nWilcuo\nOjqfaahanx", "output": "Avshkju Gcj, Dmdqeyhvbm Kuome, Dmssv Ojqfaahanx, Ibqholfugr Wilcuo, Tbhmfsimms Wtwqf, Vufczejycy Vxfnonsgba" }, { "input": "10\nNewkwj\nPwlt\nCsmgdpf\nSkyqtmtbxc\nQzsioma\nAqc\nNgphmzu\nClx\nN\nYcjbmdb\nXzggfs\nJngvohpd\nTnn\nTtkry\nBqytgxrfzv\nOkwfhrdkal\nOakii\nF\nYubzwo\nUrb", "output": "Aqc Bqytgxrfzv, Clx F, Csmgdpf Jngvohpd, N Oakii, Newkwj Okwfhrdkal, Ngphmzu Tnn, Pwlt Ttkry, Qzsioma Urb, Skyqtmtbxc Xzggfs, Ycjbmdb Yubzwo" }, { "input": "14\nHv\nUgwe\nGgihdhhfv\nLchhinoa\nWvdztopak\nOgocupw\nJiebvzwox\nPkgkdv\nNeoaf\nDupbbgww\nFj\nZslqnclo\nInrmh\nNtdxo\nUteopjiw\nParlyfv\nJbzzf\nF\nNhlet\nWvpdt\nYzutknye\nVseglkc\nFi\nNvzhq\nPweehpwfgj\nEa\nJoa\nVaqp", "output": "Dupbbgww Ea, Fj F, Ggihdhhfv Fi, Hv Jbzzf, Inrmh Parlyfv, Jiebvzwox Joa, Lchhinoa Vaqp, Neoaf Nhlet, Ntdxo Nvzhq, Ogocupw Vseglkc, Pkgkdv Pweehpwfgj, Ugwe Uteopjiw, Wvdztopak Wvpdt, Zslqnclo Yzutknye" }, { "input": "18\nCjr\nTxixsjahh\nUu\nEtaeywar\nIzyppd\nSrwlojju\nNuuh\nOwrbbjbu\nS\nSic\nCw\nTdquovp\nZjq\nSdkrmyc\nHxwvbm\nXd\nAafk\nGhbeztyi\nTqpcctoila\nHopqjdgn\nP\nPlrtsrslgh\nXfqjqpolh\nUjqolvsfhq\nThujdq\nPwjur\nZmmzpgkqc\nJczat\nVqrufwfixf\nZbrdx\nUrg\nThogqt\nIaaqixivfl\nVovde\nWpaxlbwfr\nVcy", "output": "Aafk Jczat, Cjr P, Cw Plrtsrslgh, Etaeywar Pwjur, Ghbeztyi Thogqt, Hxwvbm Hopqjdgn, Izyppd Iaaqixivfl, Nuuh Ujqolvsfhq, Owrbbjbu Vcy, S Vovde, Sdkrmyc Vqrufwfixf, Sic Wpaxlbwfr, Srwlojju Zbrdx, Tdquovp Thujdq, Txixsjahh Tqpcctoila, Uu Urg, Xd Xfqjqpolh, Zjq Zmmzpgkqc" }, { "input": "25\nWctcwhou\nOboa\nYgcy\nNcla\nEyds\nFunlnpas\nGscxstbdgz\nDwxxjywit\nFnns\nKsdkdto\nXvvrcxx\nVeewcog\nZ\nFjgpvgtvwq\nWop\nOz\nGzhzas\nKxra\nAncdrxb\nGdwfm\nCpzcso\nOsjbcmyxz\nNtpmkyjde\nKmhqusz\nOcx\nOeeq\nK\nSyjsfkjju\nQiwbitvcrd\nY\nGxair\nA\nEst\nDqmnoqdzbw\nZrmyoq\nAvosvzytow\nCjcrmi\nGozpkircw\nFswloprnu\nTnnwv\nCdjyan\nDqbrxq\nIyfyphzqaq\nTo\nNtuphe\nU\nJg\nT\nJpniuqb\nLsjeclfm", "output": "Ancdrxb A, Cpzcso Cdjyan, Dwxxjywit Dqbrxq, Eyds Est, Fjgpvgtvwq Avosvzytow, Fnns Cjcrmi, Funlnpas Fswloprnu, Gdwfm Dqmnoqdzbw, Gscxstbdgz Gozpkircw, Gzhzas Gxair, Kmhqusz Iyfyphzqaq, Ksdkdto Jg, Kxra K, Ncla Jpniuqb, Ntpmkyjde Ntuphe, Oboa Lsjeclfm, Ocx Oeeq, Osjbcmyxz Qiwbitvcrd, Oz Syjsfkjju, Veewcog T, Wctcwhou Tnnwv, Wop To, Xvvrcxx U, Ygcy Y, Z Zrmyoq" }, { "input": "30\nSfmuqd\nLjsmcw\nCzgfz\nFjcrjda\nHbn\nXpqn\nKxjqcqnq\nJqu\nIom\nE\nNnvzvfr\nOdkgzrkq\nYgorzyck\nRpk\nTmdc\nPhkkilqlgp\nI\nNl\nLtahfgmoo\nIawoa\nGlao\nGktz\nWb\nO\nQfe\nCctwmhr\nR\nUg\nQfktr\nM\nPrsvvfwiov\nWmycckk\nYuxshzs\nPkf\nOr\nUnyxnk\nGsnsecide\nS\nZxqt\nFfkvbgs\nFvnismv\nUwtqoglgo\nLug\nFcfcbxik\nWycvm\nRlvmzreke\nL\nVgd\nQtoflj\nVe\nJnvcm\nCrfgefw\nD\nBfqh\nBf\nZchjkgxfiu\nDkcdte\nFmmjx\nLsshf\nVfqwyoxki", "output": "Cctwmhr Bf, Czgfz Crfgefw, E Bfqh, Fjcrjda Fcfcbxik, Gktz D, Glao Gsnsecide, Hbn Dkcdte, I Ffkvbgs, Iawoa Fmmjx, Iom Fvnismv, Jqu Jnvcm, Kxjqcqnq L, Ljsmcw Lsshf, Ltahfgmoo Lug, M Pkf, Nl Unyxnk, Nnvzvfr Ve, O Or, Odkgzrkq Vfqwyoxki, Phkkilqlgp Prsvvfwiov, Qfe Qtoflj, Qfktr Vgd, R Rlvmzreke, Rpk Wmycckk, Sfmuqd S, Tmdc Zchjkgxfiu, Ug Uwtqoglgo, Wb Wycvm, Xpqn Zxqt, Ygorzyck Yuxshzs" }, { "input": "4\nToywf\nLvbhixy\nErnwsstqxz\nEfjol\nYtxgimclx\nEq\nWv\nLmbq", "output": "Efjol Eq, Ernwsstqxz Wv, Lvbhixy Lmbq, Toywf Ytxgimclx" }, { "input": "6\nSkvknneci\nYqtxdtrnzl\nRls\nLz\nX\nTop\nBvae\nQjbgcyl\nMgqx\nE\nYr\nAmogkatq", "output": "Lz Amogkatq, Rls Bvae, Skvknneci E, Top Mgqx, X Qjbgcyl, Yqtxdtrnzl Yr" }, { "input": "10\nToxkb\nQltc\nZrhvwb\nVccfmdxbzw\nMgcejyragz\nD\nGkfp\nOgyyt\nBtb\nIzyiekx\nQeyqyfmz\nY\nHwka\nXmwtmci\nTgqcdz\nCp\nXnd\nAc\nLuds\nVc", "output": "Btb Ac, D Cp, Gkfp Hwka, Izyiekx Luds, Mgcejyragz Xmwtmci, Ogyyt Xnd, Qltc Qeyqyfmz, Toxkb Tgqcdz, Vccfmdxbzw Vc, Zrhvwb Y" }, { "input": "14\nZ\nUjextoqryl\nTyolkeuto\nOntpojghj\nNq\nKeq\nTetdkxdo\nShsxwvqotk\nCvhbwqcaz\nSfue\nTxq\nQzznk\nAejnvuc\nT\nWjgnuelt\nYjuhi\nGmxkgj\nKltxoildze\nSybzfm\nHhdbvdpt\nPeedniub\nOlskewova\nDzhjdzqsj\nLtbxltpug\nVdtyqse\nJ\nYl\nK", "output": "Aejnvuc Dzhjdzqsj, Cvhbwqcaz Gmxkgj, Keq K, Nq Hhdbvdpt, Ontpojghj Olskewova, Qzznk J, Sfue Kltxoildze, Shsxwvqotk Sybzfm, T Ltbxltpug, Tetdkxdo Peedniub, Txq Vdtyqse, Tyolkeuto Wjgnuelt, Ujextoqryl Yjuhi, Z Yl" }, { "input": "18\nGtbmox\nDl\nBaxubgvgip\nLdn\nWgjsblxvg\nPwlartghr\nU\nIfmprj\nGawujn\nGrth\nIzqoddgwtp\nIrpwqvt\nLwpthqz\nWeo\nPlhibwks\nFop\nAgfjasurvq\nJxbr\nXmyn\nOgfx\nQvh\nOgcocvgerd\nJwcbq\nI\nG\nSooticdnj\nIuaylf\nWhfrxwwv\nWyanbbbcuy\nIsh\nJssvbx\nHgooryd\nM\nJk\nAu\nDohfynvuj", "output": "Agfjasurvq Au, Baxubgvgip Hgooryd, Dl Dohfynvuj, Fop Jk, Gawujn G, Grth Jssvbx, Gtbmox M, Ifmprj I, Irpwqvt Ish, Izqoddgwtp Iuaylf, Jxbr Jwcbq, Ldn Ogcocvgerd, Lwpthqz Ogfx, Plhibwks Qvh, Pwlartghr Sooticdnj, U Xmyn, Weo Whfrxwwv, Wgjsblxvg Wyanbbbcuy" }, { "input": "25\nFwhxbm\nF\nHoe\nR\nKyfxzz\nTun\nCfmgskyudr\nKwppr\nDxydvyn\nFhzxwrx\nXxs\nVrz\nV\nAeluhklihx\nMcyxl\nPtnezjp\nYmakurwz\nIvzfugi\nK\nDe\nQuc\nIwqz\nHavbcqgs\nP\nWsmoslxl\nHpgvuvxbbt\nBn\nWbutic\nLfathrt\nIb\nLqlsq\nQymy\nWqdbqzyl\nHecvzecwle\nWktkp\nAmbsjal\nLn\nWmskelvtsa\nIlf\nMc\nNjbnvskubj\nXb\nAwkdp\nWv\nXqostegk\nZr\nSqihtxfi\nRcncgvogf\nMtjsjbbbq\nYenngpvbwu", "output": "Aeluhklihx Ambsjal, Cfmgskyudr Awkdp, De Bn, Dxydvyn Lfathrt, F Ln, Fhzxwrx Lqlsq, Fwhxbm Mc, Havbcqgs Hecvzecwle, Hoe Hpgvuvxbbt, Ivzfugi Ib, Iwqz Ilf, K Njbnvskubj, Kwppr Sqihtxfi, Kyfxzz Wbutic, Mcyxl Mtjsjbbbq, P Wktkp, Ptnezjp Wmskelvtsa, Quc Qymy, R Rcncgvogf, Tun Wqdbqzyl, V Xb, Vrz Zr, Wsmoslxl Wv, Xxs Xqostegk, Ymakurwz Yenngpvbwu" }, { "input": "30\nB\nCjja\nK\nUnknsyohcw\nTz\nZcrkmjv\nNxnsuiwq\nKpt\nIg\nXhtvgur\nRxsr\nXjzv\nPhyx\nP\nGgq\nSs\nJdtfnnmq\nDpciytlrzc\nYcus\nY\nPepusf\nPkkv\nMgqs\nGc\nU\nR\nSx\nYg\nNbelti\nAzux\nJjqylaprgi\nErpx\nDusqgbm\nPdo\nGiehna\nOlyp\nKzoqwdoy\nGdrswibix\nZlguvcunbi\nH\nWuv\nVfyxjrpul\nWilepwe\nFhs\nBmyfsojua\nTvcvrvb\nSqn\nAwucqdvuup\nDoezapfb\nLqkr\nUqnjqqrs\nWwtyn\nDplsjenfg\nQffilp\nAno\nDle\nCzfk\nVgz\nDhzsbsqqbf\nMvdlonnngw", "output": "Azux Ano, B Bmyfsojua, Cjja Czfk, Dpciytlrzc Dhzsbsqqbf, Gc Gdrswibix, Ggq Giehna, Ig Awucqdvuup, Jdtfnnmq Jjqylaprgi, K Dle, Kpt Kzoqwdoy, Mgqs Mvdlonnngw, Nbelti Doezapfb, Nxnsuiwq Dplsjenfg, P Dusqgbm, Pepusf Erpx, Phyx Fhs, Pkkv Pdo, R H, Rxsr Lqkr, Ss Olyp, Sx Sqn, Tz Tvcvrvb, U Qffilp, Unknsyohcw Uqnjqqrs, Xhtvgur Vfyxjrpul, Xjzv Vgz, Y Wilepwe, Ycus Wuv, Yg Wwtyn, Zcrkmjv Zlguvcunbi" } ]
62
0
0
7,616
38
Blinds
[ "brute force" ]
C. Blinds
2
256
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths) Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe) After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way. Thus, if the blinds consist of *k* pieces each *d* in length, then they are of form of a rectangle of *k*<=Γ—<=*d* bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than *l* bourlemeter. The window is of form of a rectangle with side lengths as positive integers.
The first output line contains two space-separated integers *n* and *l* (1<=≀<=*n*,<=*l*<=≀<=100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated *n* integers *a**i*. They are the lengths of initial stripes in bourlemeters (1<=≀<=*a**i*<=≀<=100).
Print the single number β€” the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.
[ "4 2\n1 2 3 4\n", "5 3\n5 5 7 3 1\n", "2 3\n1 2\n" ]
[ "8\n", "15\n", "0\n" ]
In the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.
[ { "input": "4 2\n1 2 3 4", "output": "8" }, { "input": "5 3\n5 5 7 3 1", "output": "15" }, { "input": "2 3\n1 2", "output": "0" }, { "input": "2 2\n3 3", "output": "6" }, { "input": "5 2\n2 4 1 1 3", "output": "8" }, { "input": "7 4\n3 2 1 1 1 3 2", "output": "0" }, { "input": "10 1\n1 2 2 6 6 1 2 5 5 6", "output": "36" }, { "input": "10 2\n6 3 1 1 6 4 6 1 6 3", "output": "33" }, { "input": "15 6\n1 6 6 5 2 10 4 4 7 8 7 3 5 1 2", "output": "36" }, { "input": "20 2\n13 3 6 11 6 11 9 1 1 2 5 2 9 15 14 10 3 12 3 13", "output": "136" }, { "input": "25 20\n10 8 4 6 12 14 19 18 19 9 21 16 16 15 10 15 12 12 18 18 9 22 12 14 14", "output": "42" }, { "input": "30 15\n93 99 77 69 43 86 56 15 9 9 75 84 56 1 42 45 10 23 83 87 86 99 46 48 40 69 95 10 61 47", "output": "1455" }, { "input": "35 3\n13 12 38 45 71 61 42 75 58 40 50 70 27 38 16 37 21 12 36 7 39 4 65 12 32 26 1 21 66 63 29 56 32 29 26", "output": "1236" }, { "input": "40 33\n33 52 83 32 59 90 25 90 38 31 60 30 76 77 9 13 48 1 55 39 84 28 58 83 12 3 77 34 33 73 15 35 29 8 3 21 63 4 21 75", "output": "1089" }, { "input": "45 1\n1 1 2 3 1 2 3 1 1 1 1 2 2 2 2 3 1 1 2 2 3 3 2 3 3 1 3 3 3 1 2 3 2 1 2 1 1 2 1 2 1 1 2 2 2", "output": "84" }, { "input": "50 70\n60 21 1 35 20 10 35 59 27 12 57 67 76 49 27 72 39 47 56 36 36 13 62 16 6 16 39 46 35 9 67 59 61 52 1 44 70 40 60 3 5 2 14 29 56 32 4 28 35 73", "output": "280" }, { "input": "55 12\n15 5 11 16 17 3 5 28 19 15 1 9 5 26 25 3 14 14 33 12 3 21 16 30 22 18 7 16 24 28 2 17 24 25 16 16 31 9 11 9 6 13 25 23 32 18 4 21 10 32 11 5 4 32 14", "output": "588" }, { "input": "60 10\n42 89 35 19 51 41 31 77 10 8 73 27 47 26 66 91 43 33 74 62 77 23 5 44 18 23 74 6 51 21 30 17 31 39 74 4 55 39 3 34 21 3 18 41 61 37 31 91 69 55 75 67 77 30 11 16 35 68 62 19", "output": "2240" }, { "input": "65 7\n1 5 4 1 4 11 9 1 11 7 6 11 9 4 2 6 10 11 10 12 4 6 1 12 12 5 1 11 7 9 11 6 10 10 7 8 4 1 3 5 2 3 2 10 11 10 5 8 7 10 12 5 11 6 8 6 2 9 9 7 2 4 12 7 7", "output": "245" }, { "input": "70 12\n6 8 11 13 11 30 4 26 16 24 8 12 14 25 7 26 1 24 1 9 7 19 25 11 18 23 27 26 27 19 8 10 9 20 23 2 14 27 24 24 14 21 31 5 1 14 24 20 2 1 11 17 12 7 17 20 8 21 16 17 31 25 9 25 5 18 6 19 22 27", "output": "756" }, { "input": "75 19\n3 35 38 25 5 17 12 37 26 34 20 3 30 33 16 26 16 31 17 5 13 40 4 40 16 4 24 31 39 13 12 3 25 40 21 2 27 26 21 2 18 24 24 25 18 3 15 20 5 6 23 10 16 37 20 13 39 4 6 28 9 25 14 7 6 15 34 9 4 16 36 19 17 30 33", "output": "817" }, { "input": "80 1\n7 13 38 24 17 20 11 3 25 23 36 16 41 36 18 9 33 10 37 20 8 7 42 8 17 1 39 30 39 24 36 17 8 11 3 33 23 42 36 16 36 3 30 20 29 35 43 17 32 26 33 4 41 34 9 37 14 26 6 40 16 24 8 26 16 31 11 12 18 24 42 34 24 37 5 23 32 13 8 14", "output": "1810" }, { "input": "85 2\n26 5 48 55 22 22 43 29 55 29 6 53 48 35 58 22 44 7 14 26 48 17 66 44 2 10 50 4 19 35 29 61 55 57 25 5 54 64 18 17 43 16 14 63 46 22 55 23 8 52 65 30 10 13 24 18 7 44 65 7 42 63 29 54 32 23 55 17 3 11 67 14 45 31 33 22 36 28 27 54 46 45 15 40 55", "output": "2796" }, { "input": "90 3\n44 16 62 40 33 17 53 32 66 18 68 33 18 76 14 66 41 8 18 57 39 63 9 41 30 39 30 35 46 12 27 33 6 4 21 26 32 24 18 25 35 39 14 49 65 32 54 38 55 64 75 2 53 21 72 11 46 47 63 60 33 62 13 35 40 21 26 15 66 74 55 48 24 26 76 69 65 68 62 12 74 58 21 13 53 5 40 56 66 67", "output": "3492" }, { "input": "91 6\n4 2 4 2 6 2 4 1 2 6 5 3 3 3 3 2 5 4 2 5 3 2 1 3 5 2 4 5 1 3 3 3 6 6 5 3 4 1 5 6 2 5 2 2 5 4 1 5 4 1 2 6 1 2 3 4 3 3 3 3 2 1 4 5 1 6 5 1 6 5 3 5 6 3 3 5 4 4 5 4 5 2 5 2 3 1 5 6 6 4 2", "output": "66" }, { "input": "92 8\n3 4 6 9 7 9 12 12 7 4 9 1 3 9 2 12 4 5 12 2 6 5 9 9 5 2 7 5 12 2 1 7 7 11 11 1 4 10 11 7 5 6 3 5 12 2 9 1 11 1 9 11 1 9 7 9 7 8 1 5 8 8 1 8 6 6 4 5 6 10 7 9 7 1 6 2 12 11 7 6 12 11 5 11 6 10 1 9 3 9 11 9", "output": "306" }, { "input": "93 10\n6 47 6 89 21 91 51 72 32 48 54 89 36 12 25 38 58 62 54 16 5 52 52 85 67 33 81 72 6 42 91 16 29 78 56 62 75 48 69 12 89 34 27 15 7 80 14 57 29 6 80 46 64 94 83 96 1 42 11 41 15 26 17 36 44 11 68 73 93 45 73 35 91 14 84 48 7 8 63 84 59 68 87 26 91 10 54 41 74 71 74 62 24", "output": "4110" }, { "input": "94 12\n40 66 66 35 43 23 77 6 55 44 68 90 20 59 11 95 78 13 75 98 30 22 40 29 2 23 82 26 53 48 16 100 97 100 74 96 73 30 35 72 23 38 25 86 7 45 53 20 18 77 68 95 41 45 1 94 42 94 54 9 33 84 53 71 6 68 98 94 35 78 58 34 84 78 28 65 58 11 2 78 96 5 8 36 34 26 76 10 69 49 25 9 77 30", "output": "4173" }, { "input": "95 17\n1 24 17 9 41 5 39 30 6 32 17 30 27 11 13 25 22 23 12 31 19 31 35 43 8 23 39 23 39 41 10 17 25 17 38 39 37 23 37 11 6 15 43 4 15 44 44 42 29 2 14 6 1 6 31 45 26 21 14 18 15 17 23 11 39 12 16 6 11 19 15 31 18 10 33 10 2 8 21 4 26 3 42 45 16 1 11 28 43 24 18 45 25 39 9", "output": "1360" }, { "input": "96 9\n4 5 1 10 2 6 1 9 2 6 3 2 9 4 1 1 3 10 10 4 6 8 6 4 4 6 4 6 2 9 1 9 3 6 9 10 4 3 7 2 7 4 4 4 6 4 1 7 9 4 9 2 1 7 7 3 4 10 10 5 1 3 10 5 1 9 8 4 10 4 7 2 9 6 9 4 2 3 6 9 8 1 1 2 9 4 10 4 9 7 7 5 1 10 9 10", "output": "225" }, { "input": "97 28\n13 12 30 2 17 29 28 28 26 10 27 27 20 14 8 28 10 5 33 19 17 31 15 4 8 13 21 23 32 3 20 9 33 17 11 13 11 9 19 30 19 25 1 18 1 13 1 20 19 9 17 31 32 26 1 34 7 34 6 22 7 13 29 6 29 3 13 28 3 6 7 29 17 34 28 32 14 33 23 25 23 11 19 19 27 27 3 20 17 13 24 2 8 25 10 31 34", "output": "672" }, { "input": "98 14\n23 3 39 39 6 35 2 35 38 9 11 24 42 35 35 46 23 46 20 36 25 46 23 9 21 24 21 38 43 9 9 38 38 46 3 28 17 31 30 14 29 12 37 15 5 45 46 32 35 39 39 27 25 15 42 40 19 19 11 6 32 16 25 29 46 2 45 44 5 36 21 11 14 18 39 1 39 26 18 14 1 23 38 24 10 38 14 42 15 3 8 8 23 46 40 19 14 29", "output": "1876" }, { "input": "99 57\n69 27 70 70 16 66 64 35 44 1 51 38 69 17 19 35 83 7 47 4 10 22 60 64 64 56 80 54 83 34 51 42 46 51 41 75 54 10 13 44 66 46 27 79 55 13 13 40 18 12 2 33 20 13 75 45 70 75 51 39 80 25 22 27 77 52 41 83 40 33 23 76 81 21 23 59 27 74 45 68 42 20 83 50 66 58 5 8 55 62 76 81 27 52 55 67 28 65 71", "output": "2030" }, { "input": "100 2\n2 2 1 1 1 1 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 2 2 2 1 2 1 2 1 2 1 2 2 2 1 1 2 2 1 2 1 1 1 1 2 1 2 2 2 1 2 1 1 1 2 2 1", "output": "92" }, { "input": "100 2\n79 84 2 24 18 95 57 79 67 60 78 85 75 23 68 68 76 30 39 31 32 81 42 90 50 33 49 9 63 18 74 46 34 55 48 41 7 75 74 90 14 90 2 49 20 29 33 65 43 7 11 12 58 45 17 100 1 28 3 12 26 94 45 5 45 19 3 28 95 11 71 68 89 47 59 5 74 92 43 100 15 63 78 85 70 38 62 100 78 76 29 69 64 2 32 68 48 61 82 100", "output": "4978" }, { "input": "100 17\n20 61 7 74 87 84 87 35 64 7 36 5 72 20 62 29 29 58 67 51 50 45 82 20 76 79 39 21 5 39 94 13 65 11 3 21 26 2 15 56 20 75 49 27 64 48 51 96 32 80 57 10 57 48 36 83 51 25 45 65 24 22 3 92 45 52 52 58 15 90 23 43 56 88 46 50 72 70 60 47 91 68 40 24 16 44 82 90 17 17 51 71 25 94 13 42 26 25 53 95", "output": "3961" } ]
92
0
0
7,652
42
Baldman and the military
[ "dfs and similar", "graphs", "trees" ]
E. Baldman and the military
4
256
Baldman is a warp master. He possesses a unique ability β€” creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both directions. Unfortunately, such operation isn't free for Baldman: each created wormhole makes him lose plenty of hair from his head. Because of such extraordinary abilities, Baldman has caught the military's attention. He has been charged with a special task. But first things first. The military base consists of several underground objects, some of which are connected with bidirectional tunnels. There necessarily exists a path through the tunnel system between each pair of objects. Additionally, exactly two objects are connected with surface. For the purposes of security, a patrol inspects the tunnel system every day: he enters one of the objects which are connected with surface, walks the base passing each tunnel at least once and leaves through one of the objects connected with surface. He can enter and leave either through the same object, or through different objects. The military management noticed that the patrol visits some of the tunnels multiple times and decided to optimize the process. Now they are faced with a problem: a system of wormholes needs to be made to allow of a patrolling which passes each tunnel exactly once. At the same time a patrol is allowed to pass each wormhole any number of times. This is where Baldman comes to operation: he is the one to plan and build the system of the wormholes. Unfortunately for him, because of strict confidentiality the military can't tell him the arrangement of tunnels. Instead, they insist that his system of portals solves the problem for any arrangement of tunnels which satisfies the given condition. Nevertheless, Baldman has some information: he knows which pairs of objects he can potentially connect and how much it would cost him (in hair). Moreover, tomorrow he will be told which objects (exactly two) are connected with surface. Of course, our hero decided not to waste any time and calculate the minimal cost of getting the job done for some pairs of objects (which he finds likely to be the ones connected with surface). Help Baldman!
First line of the input contains a single natural number *n* (2<=≀<=*n*<=≀<=100000) β€” the number of objects on the military base. The second line β€” one number *m* (1<=≀<=*m*<=≀<=200000) β€” the number of the wormholes Baldman can make. The following *m* lines describe the wormholes: each line contains three integer numbers *a*,<=*b*,<=*c* (1<=≀<=*a*,<=*b*<=≀<=*n*,<=1<=≀<=*c*<=≀<=100000) β€” the numbers of objects which can be connected and the number of hair Baldman has to spend to make this wormhole. The next line contains one natural number *q* (1<=≀<=*q*<=≀<=100000) β€” the number of queries. Finally, the last *q* lines contain a description of one query each β€” a pair of numbers of different objects *a**i*,<=*b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*, *a**i*<=β‰ <=*b**i*). There could be more than one wormhole between a pair of objects.
Your program should output *q* lines, one for each query. The *i*-th line should contain a single integer number β€” the answer for *i*-th query: the minimum cost (in hair) of a system of wormholes allowing the optimal patrol for any system of tunnels (satisfying the given conditions) if *a**i* and *b**i* are the two objects connected with surface, or "-1" if such system of wormholes cannot be made.
[ "2\n1\n1 2 3\n1\n1 2\n", "3\n1\n1 2 3\n2\n1 2\n1 3\n" ]
[ "0\n", "-1\n3\n" ]
none
[ { "input": "2\n1\n1 2 3\n1\n1 2", "output": "0" }, { "input": "3\n1\n1 2 3\n2\n1 2\n1 3", "output": "-1\n3" }, { "input": "4\n4\n1 2 1\n1 3 2\n3 4 3\n1 3 4\n6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "5\n4\n3\n4\n3\n3" }, { "input": "4\n5\n1 2 10\n2 3 3\n3 4 4\n1 4 5\n2 4 6\n6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "7\n7\n7\n9\n8\n8" }, { "input": "5\n4\n1 2 3\n1 3 4\n2 3 5\n4 5 2\n6\n1 2\n1 3\n1 4\n4 5\n2 4\n3 5", "output": "-1\n-1\n9\n-1\n9\n9" }, { "input": "6\n4\n1 2 3\n2 3 4\n1 3 5\n4 5 6\n10\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 5\n3 4\n4 5\n3 5", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "10\n18\n3 4 5085\n8 4 20846\n5 8 46276\n7 6 24632\n6 9 94302\n9 6 35901\n6 4 88184\n10 4 45058\n6 3 81851\n2 3 21935\n1 2 45770\n7 4 59403\n4 2 50360\n2 6 78088\n3 8 87938\n10 9 23726\n9 10 66377\n8 6 36029\n30\n10 2\n4 10\n10 9\n1 6\n10 3\n3 8\n7 6\n6 3\n2 5\n1 9\n8 10\n1 9\n6 1\n5 8\n1 4\n2 3\n10 5\n2 5\n2 4\n6 4\n10 5\n7 9\n5 4\n10 2\n9 7\n9 7\n9 4\n10 1\n1 9\n7 1", "output": "224171\n224171\n236474\n214430\n224171\n239354\n235568\n224171\n213924\n214430\n224171\n214430\n214430\n213924\n214430\n238265\n213924\n213924\n238265\n224171\n213924\n224299\n213924\n224171\n224299\n224299\n224171\n214430\n214430\n214430" }, { "input": "10\n18\n3 7 23726\n5 9 81851\n3 4 45058\n6 5 24632\n5 7 94302\n9 2 87938\n7 3 66377\n5 4 88184\n7 5 35901\n1 8 45770\n9 4 5085\n2 5 36029\n4 8 50360\n6 4 59403\n8 5 78088\n2 4 20846\n10 2 46276\n8 9 21935\n40\n6 7\n3 10\n8 4\n1 7\n5 1\n10 6\n7 6\n7 4\n6 5\n10 2\n1 7\n8 9\n3 8\n3 1\n5 9\n5 4\n5 3\n8 9\n1 4\n3 10\n1 5\n3 2\n4 3\n8 9\n7 6\n4 3\n9 1\n5 7\n6 1\n3 9\n3 7\n1 7\n3 8\n3 8\n8 10\n2 3\n9 2\n7 4\n8 10\n10 4", "output": "224299\n213924\n238265\n214430\n214430\n213924\n224299\n224171\n235568\n213924\n214430\n238265\n224171\n214430\n224171\n224171\n224299\n238265\n214430\n213924\n214430\n224171\n224171\n238265\n224299\n224171\n214430\n224299\n214430\n224171\n236474\n214430\n224171\n224171\n213924\n224171\n239354\n224171\n213924\n213924" }, { "input": "10\n18\n5 1 51020\n8 4 81851\n4 8 36029\n3 2 20846\n10 9 66760\n5 3 23726\n5 8 5085\n2 8 22144\n10 9 1240\n7 3 45770\n6 1 46576\n9 10 78605\n7 5 88184\n10 9 40660\n9 10 39552\n7 1 24985\n3 6 50360\n1 5 82636\n50\n8 4\n8 10\n10 8\n7 1\n2 3\n7 4\n4 6\n3 9\n4 2\n4 7\n6 5\n1 9\n8 4\n4 6\n9 3\n6 5\n10 2\n3 10\n9 10\n9 5\n2 9\n4 6\n9 4\n4 3\n6 1\n4 3\n4 10\n6 1\n10 2\n1 3\n3 8\n4 5\n9 2\n5 7\n7 2\n1 7\n6 9\n9 7\n5 3\n2 3\n10 8\n1 8\n6 8\n6 5\n4 5\n1 2\n2 5\n4 1\n6 5\n4 1", "output": "-1\n202675\n202675\n-1\n-1\n-1\n-1\n202675\n-1\n-1\n-1\n202675\n-1\n-1\n202675\n-1\n202675\n202675\n-1\n202675\n202675\n-1\n202675\n-1\n-1\n-1\n202675\n-1\n202675\n-1\n-1\n-1\n202675\n-1\n-1\n-1\n202675\n202675\n-1\n-1\n202675\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" } ]
60
0
0
7,660
429
Points and Segments
[ "graphs" ]
null
null
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw *n* distinct segments [*l**i*,<=*r**i*] on the *OX* axis. He can draw each segment with either red or blue. The drawing is good if and only if the following requirement is met: for each point *x* of the *OX* axis consider all the segments that contains point *x*; suppose, that *r**x* red segments and *b**x* blue segments contain point *x*; for each point *x* inequality |*r**x*<=-<=*b**x*|<=≀<=1 must be satisfied. A segment [*l*,<=*r*] contains a point *x* if and only if *l*<=≀<=*x*<=≀<=*r*. Iahub gives you the starting and ending points of all the segments. You have to find any good drawing for him.
The first line of input contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of segments. The *i*-th of the next *n* lines contains two integers *l**i* and *r**i* (0<=≀<=*l**i*<=≀<=*r**i*<=≀<=109) β€” the borders of the *i*-th segment. It's guaranteed that all the segments are distinct.
If there is no good drawing for a given test, output a single integer -1. Otherwise output *n* integers; each integer must be 0 or 1. The *i*-th number denotes the color of the *i*-th segment (0 is red and 1 is blue). If there are multiple good drawings you can output any of them.
[ "2\n0 2\n2 3\n", "6\n1 5\n1 3\n3 5\n2 10\n11 11\n12 12\n" ]
[ "0 1\n", "0 1 0 1 0 0\n" ]
none
[]
108
921,600
-1
7,661
58
Coins
[ "greedy" ]
B. Coins
2
256
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.
The first and only line contains an integer *n* (1<=≀<=*n*<=≀<=106) which represents the denomination of the most expensive coin.
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.
[ "10\n", "4\n", "3\n" ]
[ "10 5 1\n", "4 2 1\n", "3 1\n" ]
none
[ { "input": "10", "output": "10 5 1" }, { "input": "4", "output": "4 2 1" }, { "input": "3", "output": "3 1" }, { "input": "2", "output": "2 1" }, { "input": "5", "output": "5 1" }, { "input": "6", "output": "6 3 1" }, { "input": "7", "output": "7 1" }, { "input": "1", "output": "1" }, { "input": "8", "output": "8 4 2 1" }, { "input": "12", "output": "12 6 3 1" }, { "input": "100", "output": "100 50 25 5 1" }, { "input": "1000", "output": "1000 500 250 125 25 5 1" }, { "input": "10000", "output": "10000 5000 2500 1250 625 125 25 5 1" }, { "input": "100000", "output": "100000 50000 25000 12500 6250 3125 625 125 25 5 1" }, { "input": "1000000", "output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1" }, { "input": "509149", "output": "509149 1" }, { "input": "572877", "output": "572877 190959 63653 1201 1" }, { "input": "152956", "output": "152956 76478 38239 1" }, { "input": "733035", "output": "733035 244345 48869 1" }, { "input": "313114", "output": "313114 156557 3331 1" }, { "input": "893193", "output": "893193 297731 42533 1" }, { "input": "473273", "output": "473273 2243 1" }, { "input": "537000", "output": "537000 268500 134250 67125 22375 4475 895 179 1" }, { "input": "117079", "output": "117079 6887 97 1" }, { "input": "784653", "output": "784653 261551 9019 311 1" }, { "input": "627251", "output": "627251 1" }, { "input": "9", "output": "9 3 1" }, { "input": "999999", "output": "999999 333333 111111 37037 5291 481 37 1" }, { "input": "120", "output": "120 60 30 15 5 1" }, { "input": "720", "output": "720 360 180 90 45 15 5 1" }, { "input": "648", "output": "648 324 162 81 27 9 3 1" }, { "input": "2430", "output": "2430 1215 405 135 45 15 5 1" }, { "input": "119070", "output": "119070 59535 19845 6615 2205 735 245 49 7 1" }, { "input": "15", "output": "15 5 1" }, { "input": "21", "output": "21 7 1" }, { "input": "25", "output": "25 5 1" }, { "input": "100", "output": "100 50 25 5 1" }, { "input": "524287", "output": "524287 1" }, { "input": "1000000", "output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1" }, { "input": "600", "output": "600 300 150 75 25 5 1" }, { "input": "1000000", "output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1" }, { "input": "36", "output": "36 18 9 3 1" }, { "input": "1000000", "output": "1000000 500000 250000 125000 62500 31250 15625 3125 625 125 25 5 1" }, { "input": "20", "output": "20 10 5 1" }, { "input": "999983", "output": "999983 1" }, { "input": "9", "output": "9 3 1" }, { "input": "999983", "output": "999983 1" }, { "input": "20", "output": "20 10 5 1" }, { "input": "121", "output": "121 11 1" }, { "input": "1331", "output": "1331 121 11 1" } ]
530
0
3.8675
7,680
552
Vanya and Brackets
[ "brute force", "dp", "expression parsing", "greedy", "implementation", "strings" ]
null
null
Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
The first line contains expression *s* (1<=≀<=|*s*|<=≀<=5001, |*s*| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs <=+<= and <=*<=. The number of signs <=*<= doesn't exceed 15.
In the first line print the maximum possible value of an expression.
[ "3+5*7+8*4\n", "2+3*5\n", "3*4*5\n" ]
[ "303\n", "25\n", "60\n" ]
Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
[ { "input": "3+5*7+8*4", "output": "303" }, { "input": "2+3*5", "output": "25" }, { "input": "3*4*5", "output": "60" }, { "input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5", "output": "152587890625" }, { "input": "2*2+2*2", "output": "16" }, { "input": "1+1+1+1+1+1+1", "output": "7" }, { "input": "1+5*6+7*8", "output": "521" }, { "input": "9*8+7*6+5*4+3*2+1", "output": "1987" }, { "input": "3*3*9+4+6+8*4+5+1*4*6", "output": "12312" }, { "input": "4*9+4+5+8*4+6+9+8+2+5+2+5*7+6+8", "output": "2450" }, { "input": "9+9+9*9*9*9+9+9", "output": "19701" }, { "input": "9+9+9+9+9*9*9*9", "output": "32805" }, { "input": "1*1*1*1*1*1*1*1+1*1*1*1*1*1*1*1", "output": "2" }, { "input": "4+2*7+8+9*6+6*9+8+7*2+4", "output": "1380" }, { "input": "5", "output": "5" }, { "input": "4+6*7+4", "output": "74" }, { "input": "2+7+3+5+4+2+3+9+9+6+9+2+3+6+5*3+4+5+6+5+8", "output": "253" }, { "input": "3+2+2+3+7+1+9+1+6+8+3+2+2+6+7+2+8+8+1+4+9", "output": "94" }, { "input": "3+9+3+1+6+4+7+9+5+8+2+6+1+4+4+5+1+7+5+4+6+4+3+1*9+7+7+4+5+2+3+2+6+5+5+8+7+8+2+3*3+8+3+4+9+8*5+9+2+8+2+8+6+6+9+6+4+2+5+3+1+2+6+6+2+4+6+4+2+7+2+7+6+9+9+3+6+7+8+3+3+2+3+7+9+7+8+5+5+5*1+3+2+5+8+5*6+5+4*6+2+5+5+4+9+8+3+5+1+3+1+6+2+2+1+3+2+3+3+3+2+8+3+2+8+8+5+2+6+6+3+1+1+5+5*1+5+7+5+8+4+1*7+5+9+5+8+1*8+5+9+3+1+8+6+7+8+3+5+1+5+6+9*9+6+1+9+8+9+1+5+9+9+6+3+8+8+6*9*3+9+7+7+4+3+8+8+6+7+1+8+6+3+1+7+7+1+1+3+9+8+5+5+6+8+2+4+1+5+7+2+3+7+1+5+1+6+1+7+3*5+5+9+2+1+3+9+4+8+6+5+5+2+3+7+9+5+6+8+3*3+2+4+4+6+3+2+4+1+4+8", "output": "162353" }, { "input": "1*5*1+8*2*6*5*3*9+3+8+2+9*5+7+2+9+5+1*3+2*2*3*4*2*3", "output": "19699205" }, { "input": "4+4+6+2+5+9+9+5+5+9+4+1*5+3+6+9+6+2+4+3+2+8+9*6+5+4+3+8+7+3+2*3+1+6+8+3+8+1+8+2+1+1+1+6+9+6+4+6+7+8+3+1+5+4+8+8+6+5+8+7+7+1+7+6+3+3+9+6+3+5+4+4+1+4+1+8+6+2+9+8+7+2+3+1+4+3+9+9+2*1+3+8+2+4+1+8+9+3*7+3+7+5+3+7+5+5+3+2+9+8+4+7+5+3+7+7+3+8+9+4+9+6*6+3+8+8*7+7+9+1+3+5+1+1+1+9+8+2+1+1+5+5+5+1+6+7+3+6+1+4+1+7+1+7+1+1+9+9*4+1+3+9+3+5+5+5+5+2+9+6+7+3+5+9+3+5+3+9+3+9+9+2+7+2+1*4+6*2+5+7+6+1+1+2+8+9+5+8+3+9+9+1+1+4+9+7+5+8*9+5+2+6+5+6*2+4+2+5+2+3+9+6+9+5+5+5*6+8+2+3+1+2+8+3+1+6+5+9+7+4+2+8+9+1+5+8+5+3+2+7+1", "output": "82140" }, { "input": "6*9+9*5*5+1*2*9*9*1+4*8+8+9+5+6*5*6+4+2+2+1+5*5*7*8", "output": "11294919" }, { "input": "5+3+5+9+3+9+1+3+1*7+7+1+9+3+7+7+6+6+3+7+4+3+6+4+5+1+2*3+6*5+5+6+2+8+3+3+9+9+1+1+2+8+4+8+9+3*7+3+2*8+9+8+1*9+9+7+4+8+6+7+3+5+6+4+4+9+2+2+8+6+7+1+5+4+4+6+6+6+9+8+7+2+3+5+4+6+1+8+8+9+1+9+6+3+8+5*7+3+1+6+7+9+1+6+2+2+8+8+9+3+7+7+2+5+8+6+7+9+7+2+4+9+8+3+7+4+5+7+6+5*6+4+6+4+6+2+2*6+2+5+5+1+8+7+7+6+6+8+2+8+8+6+7+1+1+1+2+5+1+1+8+9+9+6+5+8+7+5+8+4+8+8+1+4+6+7+3+2*1+1+3+5+3+3+3+9+8+7*2+4+7+5+8+3+3+9+3+7+2+1+1+7+6+2+5+5+2+1+8+8+2+9+9+2+4+6+6+4+8+9+3+7+1+3*9+8+7+4+9+4+6+2+9+8+8+5+8+8+2+5+6+6+4+7+9+4+7+2+3+1+7", "output": "58437" }, { "input": "2+7+8*8*7+1+3+6*5*3*7*3*2+8+5*1+5*5+9*6+6*5+1*3+8+5", "output": "1473847" }, { "input": "1+2+4+8+6+5+3+8+2+9+9+5+8+7+7+7+6+1+7+2+8+3+2+5+1+6+1+3+8+2+5+4+3+5+7+8+5+7+7+3+8+1+7+1+1+1+5+9+5+9+1+6+7+6+8+9+2+7+9+2+9+9+7+3+2+8+4+4+5+9+6+2+6+8+1+3+5+3+9+4+7+4+3+9+8+2+6+3+5+1*3+1+6+8+5+3+9+2+9+9+3+4+8*6+3+9+7+1+1+4+6+4+5*6*1+1*9+6+5+4+3+7+3+8+6+2+3+7+4+1+5+8+6+1+6+9+1+2+7+2+2+1+7+9+4+3+1+4+3+3+1+1+2+1+8+9+8+6+9+9+6+3+7*1+1+3+7+9+3+6+5+2*9+8+1+9+8+7+5+3+6+9+3+5+3+5+5+7+5+2*9+9+2+4+2+3+7+1+7+1+3+8+6+4+5+9+3*2+8+6+8+2*6+8+1+4+2+7+7+6+8+3+2+5+8+1+8+5+6+1+6+4+6+8+6+6+4+3+5+2+1+5+9+9+4+4*9+7+8+4+4", "output": "178016" }, { "input": "8+3*6*9*6+5*1*8*2+1+9+2+1*3*2+9+5+4+3+1+3*9*6*8+4+1", "output": "9027949" }, { "input": "1*1*1*1*1*1*1*1*1*1*1*1", "output": "1" }, { "input": "5+5*5+5*5+5*5+5", "output": "885" }, { "input": "8+7+3+6+3*8+8+9+8+4+2", "output": "247" }, { "input": "7+8*4+9+5+3+2+3+3+2+9", "output": "327" }, { "input": "1+1+7+1+7+7*7+5+3*9+3", "output": "965" }, { "input": "9+6+9+7+8*2*9+8+6+7+5", "output": "728" }, { "input": "8+8*3*8+1+9*4+9+2+8+4", "output": "1759" }, { "input": "3+5+5+2+2+9*7+7+7*2*2", "output": "773" }, { "input": "6+8+5+9*2+7*9*3+2*2+8", "output": "3501" }, { "input": "2*3+9+6*5*8+2+9*6+3+9", "output": "3447" }, { "input": "7+7*6+7+6*1+8+8*1*2*4", "output": "1967" }, { "input": "3+2*5+9+5*2+5*5*7+9*2", "output": "2051" }, { "input": "3+4*5+6", "output": "47" } ]
77
0
0
7,688
939
Convenient For Everybody
[ "binary search", "two pointers" ]
null
null
In distant future on Earth day lasts for *n* hours and that's why there are *n* timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to *n* are used, i.e. there is no time "0 hours", instead of it "*n* hours" is used. When local time in the 1-st timezone is 1 hour, local time in the *i*-th timezone is *i* hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are *a**i* people from *i*-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than *s* hours 00 minutes local time and ends not later than *f* hours 00 minutes local time. Values *s* and *f* are equal for all time zones. If the contest starts at *f* hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum.
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=100<=000)Β β€” the number of hours in day. The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=10<=000), where *a**i* is the number of people in the *i*-th timezone who want to participate in the contest. The third line contains two space-separated integers *s* and *f* (1<=≀<=*s*<=&lt;<=*f*<=≀<=*n*).
Output a single integerΒ β€” the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
[ "3\n1 2 3\n1 3\n", "5\n1 2 3 4 1\n1 3\n" ]
[ "3\n", "4\n" ]
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
[ { "input": "3\n1 2 3\n1 3", "output": "3" }, { "input": "5\n1 2 3 4 1\n1 3", "output": "4" }, { "input": "2\n5072 8422\n1 2", "output": "2" }, { "input": "10\n7171 2280 6982 9126 9490 2598 569 6744 5754 1855\n7 9", "output": "4" }, { "input": "10\n5827 8450 8288 5592 6627 8234 3557 7568 4607 6949\n2 10", "output": "4" }, { "input": "50\n2847 339 1433 128 5933 4805 4277 5697 2574 9638 6992 5045 2254 7675 7503 3802 4012 1388 5307 3652 4764 214 9507 1832 118 7737 8279 9826 9941 250 8894 1871 616 147 9249 8867 1076 7551 5165 4709 1376 5758 4581 6670 8775 9351 4750 5294 9850 9793\n11 36", "output": "36" }, { "input": "100\n6072 8210 6405 1191 2533 8552 7594 8793 2207 8855 7415 6252 3433 2339 5532 3118 3054 5750 3690 9843 3881 1390 936 8611 7099 988 7730 3835 7065 5030 6932 6936 5531 5173 1331 8975 5454 1592 8516 328 1091 4368 8275 6462 8638 4002 5534 113 6295 5960 1688 3668 6604 9632 4214 8687 7950 3483 6149 4301 6607 1119 6466 6687 2042 6134 7008 1000 5627 7357 6998 6160 2003 4838 8478 5889 6486 470 7624 7581 524 9719 7029 6213 6963 8103 6892 7091 9451 520 2248 4482 633 3886 247 992 9861 2404 1677 4083\n75 95", "output": "6" }, { "input": "2\n5 1\n1 2", "output": "1" } ]
46
0
0
7,693
0
none
[ "none" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number *d* that meets some condition. Let *cnt*(*x*) be the number of occurrences of number *x* in number *d* as a substring. For example, if *d*<==<=747747, then *cnt*(4)<==<=2, *cnt*(7)<==<=4, *cnt*(47)<==<=2, *cnt*(74)<==<=2. Petya wants the following condition to fulfil simultaneously: *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.
The single line contains four integers *a*1, *a*2, *a*3 and *a*4 (1<=≀<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≀<=106).
On the single line print without leading zeroes the answer to the problem β€” the minimum lucky number *d* such, that *cnt*(4)<==<=*a*1, *cnt*(7)<==<=*a*2, *cnt*(47)<==<=*a*3, *cnt*(74)<==<=*a*4. If such number does not exist, print the single number "-1" (without the quotes).
[ "2 2 1 1\n", "4 7 3 1\n" ]
[ "4774\n", "-1\n" ]
none
[ { "input": "2 2 1 1", "output": "4774" }, { "input": "4 7 3 1", "output": "-1" }, { "input": "4 7 4 7", "output": "-1" }, { "input": "1 1 1 1", "output": "-1" }, { "input": "2 2 1 2", "output": "7474" }, { "input": "2 1 2 1", "output": "-1" }, { "input": "2 2 2 1", "output": "4747" }, { "input": "3 3 1 1", "output": "447774" }, { "input": "3 2 1 2", "output": "74474" }, { "input": "2 1 3 1", "output": "-1" }, { "input": "7 7 1 1", "output": "44444477777774" }, { "input": "4 7 2 1", "output": "44474777777" }, { "input": "3 3 2 2", "output": "474774" }, { "input": "4 3 2 1", "output": "4447477" }, { "input": "4 4 2 2", "output": "44747774" }, { "input": "1000000 1000000 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "10 10 3 5", "output": "-1" }, { "input": "10 10 3 7", "output": "-1" }, { "input": "1 7 1 1", "output": "74777777" }, { "input": "8 3 2 1", "output": "44444447477" }, { "input": "1000000 1000000 1000000 1000000", "output": "-1" }, { "input": "4584 45854 25 685", "output": "-1" }, { "input": "1 1 1 2", "output": "-1" }, { "input": "3 1000000 3 1", "output": "-1" }, { "input": "4 58458 2 1", "output": "4447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "845 8549 54 8", "output": "-1" }, { "input": "1000000 1000000 100000 100000", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 499 500", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 100000 100001", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "845488 44884 9945 9944", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "7 7 4 5", "output": "74447474747774" }, { "input": "7 8 5 4", "output": "444747474747777" }, { "input": "1000000 1000000 400000 400001", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "4585 4588 98 99", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 2 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "2 100000 1 2", "output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "86451 754 85 84", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "98654 4844 1001 1000", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "5 5 1 2", "output": "7444477774" }, { "input": "5 5 2 1", "output": "4444747777" }, { "input": "4 4 1 1", "output": "44477774" }, { "input": "4 4 2 2", "output": "44747774" }, { "input": "4 4 3 3", "output": "47474774" }, { "input": "10 9 4 5", "output": "7444444747474777774" }, { "input": "100 100 4 5", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774" }, { "input": "1000000 1000000 1 2", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 47 46", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 999999 1000000", "output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..." }, { "input": "54585 4584 458 954", "output": "-1" }, { "input": "6 6 1 3", "output": "-1" }, { "input": "6 6 2 3", "output": "744447477774" }, { "input": "6 10 2 1", "output": "4444474777777777" }, { "input": "7 3 1 1", "output": "4444447774" }, { "input": "47 74 8 9", "output": "7444444444444444444444444444444444444444747474747474747777777777777777777777777777777777777777777777777777777777777777774" }, { "input": "458445 445 6 7", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 10000 10001", "output": "7444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "1000000 1000000 978 977", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "7 1000 1 2", "output": "7444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "1 10 1 1", "output": "74777777777" }, { "input": "70 60 20 21", "output": "7444444444444444444444444444444444444444444444444447474747474747474747474747474747474747477777777777777777777777777777777777777774" }, { "input": "57 59 3 4", "output": "74444444444444444444444444444444444444444444444444444447474777777777777777777777777777777777777777777777777777777774" }, { "input": "10 10 5 5", "output": "44444747474747777774" }, { "input": "69 84 25 24", "output": "444444444444444444444444444444444444444444444747474747474747474747474747474747474747474747474777777777777777777777777777777777777777777777777777777777777" }, { "input": "25 94 11 12", "output": "74444444444444474747474747474747474777777777777777777777777777777777777777777777777777777777777777777777777777777777774" }, { "input": "1 1000000 4 5", "output": "-1" }, { "input": "7 1000000 2 3", "output": "7444447477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "1000000 1 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "45 65 31 32", "output": "74444444444444474747474747474747474747474747474747474747474747474747474747477777777777777777777777777777777774" }, { "input": "31 32 30 31", "output": "747474747474747474747474747474747474747474747474747474747474774" }, { "input": "1 1000000 1 1", "output": "7477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "2 1000000 1 1", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "50000 1000000 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "74544 1 1 1", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444..." }, { "input": "2 2 3 4", "output": "-1" }, { "input": "1 1000 2 1", "output": "-1" }, { "input": "1 10 1 2", "output": "-1" }, { "input": "1000000 1000000 1000000 999999", "output": "4747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474..." }, { "input": "1 2 1 1", "output": "747" }, { "input": "2 1 1 1", "output": "474" }, { "input": "2 2 2 1", "output": "4747" }, { "input": "2 2 2 2", "output": "-1" }, { "input": "1 3 1 1", "output": "7477" }, { "input": "1 4 1 1", "output": "74777" }, { "input": "2 3 2 2", "output": "74747" }, { "input": "2 5 2 2", "output": "7474777" }, { "input": "1 2 2 1", "output": "-1" }, { "input": "10 100 2 2", "output": "44444444747777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774" }, { "input": "3 4 3 3", "output": "7474747" }, { "input": "30 30 29 29", "output": "474747474747474747474747474747474747474747474747474747474774" }, { "input": "10 10 1 2", "output": "74444444447777777774" }, { "input": "999999 1000000 999999 999999", "output": "7474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747..." }, { "input": "10 11 1 1", "output": "444444444777777777774" }, { "input": "10 10 2 2", "output": "44444444747777777774" }, { "input": "100 200 5 5", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447474747477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777774" }, { "input": "10 11 10 10", "output": "747474747474747474747" }, { "input": "5 10 2 3", "output": "744474777777774" }, { "input": "6 8 1 1", "output": "44444777777774" }, { "input": "1 9 2 2", "output": "-1" } ]
154
7,987,200
3
7,701